added sources
authorEd Bartosh <bartosh@gmail.com>
Sat, 10 Jan 2009 00:49:58 +0000 (00:49 +0000)
committerEd Bartosh <bartosh@gmail.com>
Sat, 10 Jan 2009 00:49:58 +0000 (00:49 +0000)
14 files changed:
TODO [new file with mode: 0644]
debian/changelog [new file with mode: 0644]
debian/compat [new file with mode: 0644]
debian/control [new file with mode: 0644]
debian/copyright [new file with mode: 0644]
debian/dirs [new file with mode: 0644]
debian/rules [new file with mode: 0755]
debian/xkcdha.postinst [new file with mode: 0755]
icons/next.png [new file with mode: 0644]
icons/prev.png [new file with mode: 0644]
icons/random.png [new file with mode: 0644]
test [new file with mode: 0644]
xkcdha.desktop [new file with mode: 0644]
xkcdha.py [new file with mode: 0755]

diff --git a/TODO b/TODO
new file mode 100644 (file)
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 (file)
index 0000000..2d5cba3
--- /dev/null
@@ -0,0 +1,12 @@
+xkcdha (0.0.2) unstable; urgency=low
+
+  * aligned controls properly
+  * fixed bug in next/prev navigation
+
+ -- Ed Bartosh <bartosh@gmail.com>  Tue, 06 Jan 2009 21:30:27 +0000
+
+xkcdha (0.0.1) unstable; urgency=low
+
+  * init 
+
+ -- Ed Bartosh <bartosh@gmail.com>  Tue, 06 Jan 2009 13:14:06 +0000
diff --git a/debian/compat b/debian/compat
new file mode 100644 (file)
index 0000000..7ed6ff8
--- /dev/null
@@ -0,0 +1 @@
+5
diff --git a/debian/control b/debian/control
new file mode 100644 (file)
index 0000000..6a69f6c
--- /dev/null
@@ -0,0 +1,12 @@
+Source: xkcdha
+Section: user/desktop
+Priority: extra
+Maintainer: Ed Bartosh <bartosh@gmail.com>
+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 (file)
index 0000000..30e6f34
--- /dev/null
@@ -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 <bartosh@gmail.com>
+
+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 (file)
index 0000000..721230f
--- /dev/null
@@ -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 (executable)
index 0000000..1127c27
--- /dev/null
@@ -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 (executable)
index 0000000..b5b19d9
--- /dev/null
@@ -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 (file)
index 0000000..49c284f
Binary files /dev/null and b/icons/next.png differ
diff --git a/icons/prev.png b/icons/prev.png
new file mode 100644 (file)
index 0000000..b865151
Binary files /dev/null and b/icons/prev.png differ
diff --git a/icons/random.png b/icons/random.png
new file mode 100644 (file)
index 0000000..04a72ea
Binary files /dev/null and b/icons/random.png differ
diff --git a/test b/test
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/xkcdha.desktop b/xkcdha.desktop
new file mode 100644 (file)
index 0000000..9d90400
--- /dev/null
@@ -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 (executable)
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('<a href="([^"]+)" accesskey="n">Next', content).group(1)
+            prev = re.search('<a href="([^"]+)" accesskey="p">&lt; Prev', content).group(1)
+            self.number = re.search(\
+                    '<h3>Permanent link to this comic: http://xkcd.com/([^/]+)/</h3>', 
+                    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()
+