From 34ae027455851b25b4cc0b524b523cb67aa00ef0 Mon Sep 17 00:00:00 2001 From: Ed Bartosh Date: Sat, 10 Jan 2009 00:49:58 +0000 Subject: [PATCH 1/1] added sources --- TODO | 5 ++ debian/changelog | 12 ++++ debian/compat | 1 + debian/control | 12 ++++ debian/copyright | 26 +++++++++ debian/dirs | 4 ++ debian/rules | 51 +++++++++++++++++ debian/xkcdha.postinst | 10 ++++ icons/next.png | Bin 0 -> 937 bytes icons/prev.png | Bin 0 -> 982 bytes icons/random.png | Bin 0 -> 1205 bytes xkcdha.desktop | 4 ++ xkcdha.py | 143 ++++++++++++++++++++++++++++++++++++++++++++++++ 13 files changed, 268 insertions(+) create mode 100644 TODO create mode 100644 debian/changelog create mode 100644 debian/compat create mode 100644 debian/control create mode 100644 debian/copyright create mode 100644 debian/dirs create mode 100755 debian/rules create mode 100755 debian/xkcdha.postinst create mode 100644 icons/next.png create mode 100644 icons/prev.png create mode 100644 icons/random.png create mode 100644 test create mode 100644 xkcdha.desktop create mode 100755 xkcdha.py diff --git a/TODO b/TODO new file mode 100644 index 0000000..c7f249f --- /dev/null +++ b/TODO @@ -0,0 +1,5 @@ +1. stand-alone application +2. statusbar applet ? +3. gnome applet ? +4. slide show + diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 0000000..2d5cba3 --- /dev/null +++ b/debian/changelog @@ -0,0 +1,12 @@ +xkcdha (0.0.2) unstable; urgency=low + + * aligned controls properly + * fixed bug in next/prev navigation + + -- Ed Bartosh Tue, 06 Jan 2009 21:30:27 +0000 + +xkcdha (0.0.1) unstable; urgency=low + + * init + + -- Ed Bartosh Tue, 06 Jan 2009 13:14:06 +0000 diff --git a/debian/compat b/debian/compat new file mode 100644 index 0000000..7ed6ff8 --- /dev/null +++ b/debian/compat @@ -0,0 +1 @@ +5 diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..6a69f6c --- /dev/null +++ b/debian/control @@ -0,0 +1,12 @@ +Source: xkcdha +Section: user/desktop +Priority: extra +Maintainer: Ed Bartosh +Build-Depends: debhelper (>= 5) +Standards-Version: 3.7.2 + +Package: xkcdha +Architecture: all +Depends: hildon-desktop-python-loader, python2.5-hildondesktop +Description: HomeTools is a home hildon desktop applet which display comics from xkcd.com + diff --git a/debian/copyright b/debian/copyright new file mode 100644 index 0000000..30e6f34 --- /dev/null +++ b/debian/copyright @@ -0,0 +1,26 @@ +This is the Debian package of xkcdha, the Maemo Home Applet XKCD viewer + +The original packager and current maintainer is Ed Bartosh + +Copyright (c) 2008 Ed Bartosh + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + diff --git a/debian/dirs b/debian/dirs new file mode 100644 index 0000000..721230f --- /dev/null +++ b/debian/dirs @@ -0,0 +1,4 @@ +usr/share/applications/hildon-home +usr/lib/hildon-desktop +usr/share/xkcdha + diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..1127c27 --- /dev/null +++ b/debian/rules @@ -0,0 +1,51 @@ +#!/usr/bin/make -f + +# Uncomment this to turn on verbose mode. +#export DH_VERBOSE=1 + +PACKAGE := $(shell head -1 $(CURDIR)/debian/changelog | sed 's/^\([^ ]\+\) .*/\1/') +PREFIX := $(CURDIR)/debian/$(PACKAGE) +PYTHON := python2.5 + +build: build-stamp + +build-stamp: + dh_testdir + python setup.py build + touch $@ + +clean: + dh_testdir + dh_testroot + rm -f build-stamp + rm -f *.pyc + dh_clean + +install: build + dh_testdir + dh_testroot + dh_clean -k + dh_installdirs + cp $(CURDIR)/$(PACKAGE).py $(PREFIX)/usr/lib/hildon-desktop/ + cp $(CURDIR)/$(PACKAGE).desktop $(PREFIX)/usr/share/applications/hildon-home/ + cp -r $(CURDIR)/icons $(PREFIX)/usr/share/$(PACKAGE)/ + +binary-indep: build install + dh_testdir + dh_testroot + dh_installchangelogs + dh_installdocs + #dh_installmenu + #dh_python + dh_compress + dh_fixperms + dh_installdeb + #dh_shlibdeps + dh_gencontrol + dh_md5sums + dh_builddeb + +binary-arch: build install + +binary: binary-indep binary-arch +.PHONY: build clean binary-indep binary-arch binary install diff --git a/debian/xkcdha.postinst b/debian/xkcdha.postinst new file mode 100755 index 0000000..b5b19d9 --- /dev/null +++ b/debian/xkcdha.postinst @@ -0,0 +1,10 @@ +#!/bin/sh -e + +PKG="xkcdha" +USER="user" +GROUP="users" + +IMG_DIR="/home/$USER/MyDocs/.images/$PKG" + +[ "$1" = "configure" -a ! -d $IMG_DIR ] && (mkdir $IMG_DIR && chown -R $USER:$GROUP $IMG_DIR) +exit 0 diff --git a/icons/next.png b/icons/next.png new file mode 100644 index 0000000000000000000000000000000000000000..49c284fc6988d8d4a81cee6cbeb71b26f07ce5b4 GIT binary patch literal 937 zcmV;a16KTrP)Nkl0?U=D)n*ckdDM=f z@li0$uMh>43>4vX!E#Qq6x>?O|JA$a{NMAQ-`@Z8p1lAODhdD;U%3@wRAtvLB9Xdd z5er70@4>CB#esp*+;`_e)vWsXPtWD+_x|r4Ls^MjbZcZr@%X_E1fl$^Pn3!IG12rT zi(){2KZzie_>FNAAy?DZ{fER(tNc+lf*|M49QFD9H_I#g25kUvI5&O&-d)a7SLyAF z(v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?=5 z9ldQGz3HiJrBtAh@I%ArpVJ%7_n*E0`=%T!q=QxEd&}iVYW5D8ZNUZNSDPscG(D#3 z%Cd?waY}O18hQAq0zElxf7#mJaP7{G+fToAe?<_atXQ;xn$!BRYi>TsN{la46o%K> zq5ZokFtghRO>0 zz6yDJXWy@C3;-NX_n>8@fV(3Ex%q6_e70DJ`VsYcOz*xeXIHjrw!@v6#&;V_Zz8i7w*QXqJGw82zy=PNVX}u^DAk z8L(m*vp`u(2jzQZfZKFHTW$;Y9)FzerYnxXewd8#{(A3u&-h?;ql<)rhTGV%(_jy4o66M+idU@YM7jyTje#=zF}0Jy3rH2nBp)T8c6)MZo8` z+It>*Vu2ua-XXgU%9X}mjSY%heINj*+j$s`kSfuGdaQ?=`ber8dFzjR9WijIIl~$cb zDU(X5P zqkIv9r#9zH#KQkXZtryc(AfOpr{8pTdk6xatt#bkH~_F?YhkP`X3RJJ(P!T_oV)b- z$se0-T^tVQh3X1|AXxX=xj?o$O_7wq;c&`}@@D1&DR`G|82Aw)9_`=Da>Jb-UDJh>w#lgZ$5opS?=V5CY{3cH}?#`-7Cb zf25_oo1J5KXZ@d?_-=cpRi{ZWF36!m3-12WUt6z^j8CpVTh^Z~>%`XOf02IykgK}M T4R~l600000NkvXXu0mjfoVqd9 literal 0 HcmV?d00001 diff --git a/test b/test new file mode 100644 index 0000000..e69de29 diff --git a/xkcdha.desktop b/xkcdha.desktop new file mode 100644 index 0000000..9d90400 --- /dev/null +++ b/xkcdha.desktop @@ -0,0 +1,4 @@ +[Desktop Entry] +Name=XKCD H(ome)A(pplet) +Type=python +X-Path=xkcdha diff --git a/xkcdha.py b/xkcdha.py new file mode 100755 index 0000000..a6891f3 --- /dev/null +++ b/xkcdha.py @@ -0,0 +1,143 @@ +#!/usr/bin/python -tt + +import os +import sys +import re +import urllib + +import gtk +import hildondesktop + +MAX_HEIGHT = 370. +MAX_WIDTH = 700. + +class XKCDha(hildondesktop.HomeItem): + + image_dir = "/home/user/MyDocs/.images/xkcdha/" + icons_dir = "/usr/share/xkcdha/icons/" + + def __init__(self, max_height, max_width): + def controls(): + hbox = gtk.HBox() + hbox.pack_start(gtk.Alignment()) + for name in ("prev", "random", "next"): + box = gtk.EventBox() + image = gtk.Image() + image.set_from_file(self.icons_dir + "%s.png" % name) + box.add(image) + box.set_events(gtk.gdk.BUTTON_PRESS_MASK) + box.connect("button-press-event", getattr(self, "cb_%s" % name)) + hbox.pack_start(box, False, False) + hbox.pack_start(gtk.Alignment(), False, False, 5) + hbox.pack_start(gtk.Alignment()) + return hbox + + hildondesktop.HomeItem.__init__(self) + self.max_height, self.max_width = max_height, max_width + self.number = None + self.prev = None + self.next = None + self.image = gtk.Image() + + self.set_image() + + image_box = gtk.EventBox() + image_box.add(self.image) + image_box.set_events(gtk.gdk.BUTTON_PRESS_MASK) + image_box.connect("button-press-event", self.cb_random) + + vbox = gtk.VBox() + vbox.pack_start(controls()) + vbox.pack_start(image_box) + vbox.pack_start(controls()) + vbox.show_all() + + self.add(vbox) + + def set_image(self, number=""): + def get_image(number=""): + + if self.number and number != "random": + if not number: + number = self.number + elif number == "next" and self.next: + number = self.next + if number == "prev" and self.prev: + number = self.prev + + print 'number=', number, self.number + + url = "http://xkcd.com/" + if number == 'random': + url = "http://dynamic.xkcd.com/comic/random/" + elif number: + url = "http://xkcd.com/%s/" % number + + print 'url:', url + + content = urllib.urlopen(url).read() + img_url = re.search('(http://imgs.xkcd.com/comics/[^"]+)" title="[^"]+"', + content).group(1) + next = re.search('Next', content).group(1) + prev = re.search('< Prev', content).group(1) + self.number = re.search(\ + '

Permanent link to this comic: http://xkcd.com/([^/]+)/

', + content).group(1) + self.next = self.number + if next != '#': + self.next = next[1:-1] + + self.prev = self.number + if prev != '#': + self.prev = prev[1:-1] + + filename = os.path.join(self.image_dir, self.number + '.png') + if not os.path.exists(filename): + print 'getting url', img_url, 'to', filename + urllib.urlretrieve(img_url, filename) + else: + print 'already exists', filename + + print 'filename:', filename, 'img_url:', img_url + print 'next:', next, self.next + print 'prev:', prev, self.prev + print 'number:', self.number + return filename + + pixbuf = gtk.gdk.pixbuf_new_from_file(get_image(number)) + scale_y = self.max_height / pixbuf.props.height + scale_x = self.max_width / pixbuf.props.width + if scale_x > scale_y: + newx = int(pixbuf.props.width * scale_y) + newy = int(self.max_height) + else: + newx = int(self.max_width) + newy = int(pixbuf.props.height * scale_x) + + self.image.set_from_pixbuf(pixbuf.scale_simple(newx, newy, gtk.gdk.INTERP_BILINEAR)) + self.image.show() + + def cb_random(self, widget, data = None): + self.set_image('random') + + def cb_next(self, widget, data = None): + self.set_image('next') + + def cb_prev(self, widget, data = None): + self.set_image('prev') + +def hd_plugin_get_objects(): + return [XKCDha(MAX_HEIGHT, MAX_WIDTH)] + +def run_in_window(): + main_window = gtk.Window(gtk.WINDOW_TOPLEVEL) + main_window.set_title("XKCD Home Applet") + main_window.connect("destroy", gtk.main_quit) + main_window.add(XKCDha(MAX_HEIGHT, MAX_WIDTH)) + main_window.show_all() + gtk.main() + +if __name__ == "__main__": + run_in_window() + sys.exit() + -- 1.7.9.5