version 0.3.0, added disable/enable comics
authorMarcus W <mece@LeChuck2.(none)>
Wed, 3 Feb 2010 01:40:04 +0000 (03:40 +0200)
committerMarcus W <mece@LeChuck2.(none)>
Wed, 3 Feb 2010 01:40:04 +0000 (03:40 +0200)
debs/comic-widget_0.2.5-3_all.deb [new file with mode: 0644]
extras-devel/comic-widget_0.2.5-3_all.deb [deleted file]
src/opt/comic-widget/images/icon2-64x64.png [new file with mode: 0644]
src/usr/lib/hildon-desktop/comicwidget.py

diff --git a/debs/comic-widget_0.2.5-3_all.deb b/debs/comic-widget_0.2.5-3_all.deb
new file mode 100644 (file)
index 0000000..6c17f84
Binary files /dev/null and b/debs/comic-widget_0.2.5-3_all.deb differ
diff --git a/extras-devel/comic-widget_0.2.5-3_all.deb b/extras-devel/comic-widget_0.2.5-3_all.deb
deleted file mode 100644 (file)
index 6c17f84..0000000
Binary files a/extras-devel/comic-widget_0.2.5-3_all.deb and /dev/null differ
diff --git a/src/opt/comic-widget/images/icon2-64x64.png b/src/opt/comic-widget/images/icon2-64x64.png
new file mode 100644 (file)
index 0000000..1ec464a
Binary files /dev/null and b/src/opt/comic-widget/images/icon2-64x64.png differ
index 984470e..4b6239d 100644 (file)
@@ -16,11 +16,12 @@ supports_alpha = False
 
 # constants. dbfile is the location of the csv
 # comiccache is the location of the images
-APP_VERSION = "0.2.5"
+APP_VERSION = "0.3.0"
 
 basedbdir = "/opt/comic-widget/db/"
 imagedir = "/opt/comic-widget/images/"
 dbdir = "/home/user/.comic-widget/"
+activecomics = dbdir + "activecomics.cfg"
 comiccache = "/home/user/MyDocs/.comics/"
 comics = {"xkcd":{"name":"xkcd","link":"http://xkcd.org/","start":666,"dbfile":dbdir + "comicdb.xkcd.csv"},
                "sinfest":{"name":"Sinfest","link":"http://sinfest.com/","start":3400,"dbfile":dbdir + "comicdb.sinfest.csv"},
@@ -311,13 +312,15 @@ class ComicHomePlugin(hildondesktop.HomePluginItem):
                hildondesktop.HomePluginItem.__init__(self)
                global supports_alpha
                self.set_settings(True)
+               self.active_comics = self.get_active_comics()
                self.connect("show-settings", self.show_options)
-               self.osso_c = osso.Context("comic-widget", "0.2.6", False)
+               self.osso_c = osso.Context("comic-widget", "0.3.0", False)
                self.osso_rpc = osso.Rpc(self.osso_c)
-               self.keys = comics.keys()
-               self.keypointer = 1
-               self.db = ComicDb(self.keys[self.keypointer])
-               self.comicname = comics[self.keys[self.keypointer]]['name']
+               self.keypointer = 0
+               if len(self.active_comics) < 1:
+                       self.active_comics = ['xkcd']
+               self.db = ComicDb(self.active_comics[self.keypointer])
+               self.comicname = comics[self.active_comics[self.keypointer]]['name']
                self.set_name = "comicwidget"
                screen = self.get_screen()
                colormap = screen.get_rgba_colormap()
@@ -540,12 +543,14 @@ class ComicHomePlugin(hildondesktop.HomePluginItem):
                                self.e_goweb.show_all()
 
                        elif func == 'switch':
-                               self.keypointer = (self.keypointer + 1) % len(comics)
+                               self.active_comics = self.get_active_comics()
+                               print "active comics: " + str(self.active_comics)
+                               self.keypointer = (self.keypointer + 1) % len(self.active_comics)
                                self.imgvpos = 0
                                self.db = []
-                               print "switching to " + self.keys[self.keypointer]
-                               self.comicname = comics[self.keys[self.keypointer]]['name']
-                               self.db = ComicDb(self.keys[self.keypointer])
+                               print "switching to " + self.active_comics[self.keypointer]
+                               self.comicname = comics[self.active_comics[self.keypointer]]['name']
+                               self.db = ComicDb(self.active_comics[self.keypointer])
                                self.e_open.remove(self.comic_image)
                                self.comic_image = self.get_resized_pixmap(self.db.get_comic(), self.imgvpos)
                                self.e_goweb.remove(self.label)
@@ -635,7 +640,52 @@ class ComicHomePlugin(hildondesktop.HomePluginItem):
 
                return False
 
-# ************************* OPTIONS ********************************
+
+       def get_active_comics(self):
+               print "get list"
+
+               if os.path.isfile(activecomics) == True:
+                       print "found " + activecomics
+                       dbf = open(activecomics, 'r')
+                       dbr = csv.reader(dbf)
+                       try:
+                               active = dbr.next()
+                       except:
+                               active = []
+                       dbf.close()
+                       return active
+               # if not, copy it.
+               else:
+                       print "file " + activecomics + " not found"
+                       if not os.path.exists(dbdir):
+                               print "path not found: " + dbdir
+                               try:
+                                       os.makedirs(dbdir)
+                               except:
+                                       print "settings dir creation failed. Exiting."
+                                       exit()
+                       try:
+#                              dbf = file(activecomics, 'w')
+#                              dbf.close()
+                               dbf = open(activecomics, 'w')
+                       except:
+                               print "error storing settings"
+                               exit()
+                       dbw = csv.writer(dbf)
+                       dbw.writerow(comics.keys())
+                       print comics.keys()
+                       dbf.close()
+                       ret = comics.keys()
+                       return ret
+
+               
+               
+               
+               #check if settings file exists
+
+               #if not, write defaults
+
+# ************************* OPTION DIALOGS ********************************
 
        def show_options(self, widget):
                dialog = gtk.Dialog("Comic Widget", None, gtk.DIALOG_DESTROY_WITH_PARENT)
@@ -645,7 +695,13 @@ class ComicHomePlugin(hildondesktop.HomePluginItem):
                about_button.set_alignment(0,0,0,0)
                about_button.connect("clicked", self.show_about)
 
+               comics_button = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL)
+               comics_button.set_text("Comics", "Choose which comics to view")
+               comics_button.set_alignment(0,0,0,0)
+               comics_button.connect("clicked", self.show_comics)
+
                dialog.vbox.pack_start(about_button, True, True, 0)
+               dialog.vbox.pack_start(comics_button, True, True, 0)
 
                dialog.show_all()
                dialog.run()
@@ -658,14 +714,73 @@ class ComicHomePlugin(hildondesktop.HomePluginItem):
                dialog.set_version(APP_VERSION)
                dialog.set_copyright("Copyright 2010 Marcus Wikstrom")
                dialog.set_authors(["Marcus Wikstrom <mece@ovi.com>\nLogo by Martin Wikstrom\n\nSpecial thanks to all the great python developers on t.m.o who share their code, and the helpful wizards on #maemo."])
-               # dialog.set_logo(gtk.gdk.pixbuf_new_from_file("/usr/share/touchsearch/icon.png"))
-               # dialog.set_comments("Thanks to Benoit Hervier, Daniel Would and Brent Chiodo for some nice code to sample.")
+               dialog.set_logo(gtk.gdk.pixbuf_new_from_file("/opt/comic-widget/images/icon2-64x64.png"))
+               dialog.set_comments("Silly rabbit, tricks are for kids.")
                dialog.set_license("""This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License. <http://www.gnu.org/licenses/>.""")
                dialog.set_wrap_license(True)
                dialog.show_all()
                dialog.run()
                dialog.destroy()
 
+       def show_comics(self, widget):
+               dialog = gtk.Dialog("Configure Search Engines", None, gtk.DIALOG_DESTROY_WITH_PARENT | gtk.DIALOG_NO_SEPARATOR)
+               comiclist = comics.keys()
+               comiclist.sort()
+               buttonlist = {}
+               for comicid in comiclist:
+                       buttonlist[comicid] = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL)
+                       print buttonlist[comicid].get_name()
+                       
+                       print buttonlist[comicid].set_alignment(0, 0.5, 0, 0.5) 
+                       active = False
+                       for acomic in self.active_comics:
+                               if acomic == comicid:
+                                       active = True
+                                       break
+                       if active:
+                               buttonlist[comicid].set_text(comics[comicid]['name'] + " *", comicid + ": click to remove")
+                               buttonlist[comicid].connect("clicked", self.remove_comic)
+                       else:
+                               buttonlist[comicid].set_text(comics[comicid]['name'], comicid + ": click to add")
+                               buttonlist[comicid].connect("clicked", self.add_comic)
+                       dialog.vbox.pack_start(buttonlist[comicid], True, True, 0)
+
+               
+               dialog.show_all()
+               dialog.run()
+               dialog.destroy()
+                               
+       def add_comic(self, widget):
+               print "add " + widget.get_title()
+               splt = string.split(widget.get_value(), ':', 1)
+               comicid = splt[0]
+               if os.path.isfile(activecomics) == True:
+                       print "added " + comicid + " to " + str(self.active_comics)
+                       try:
+                               found = self.active_comics.index(comicid)
+                       except:
+                               self.active_comics.append(comicid)
+                       dbf = open(activecomics, 'w')
+                       dbw = csv.writer(dbf)
+                       dbw.writerow(self.active_comics)
+                       dbf.close()
+               widget.set_text(comics[comicid]['name'] + " *", comicid + ": click to remove")
+
+       def remove_comic(self, widget):
+               print "remove " + widget.get_title()
+               if len(self.active_comics) == 1:
+                       return
+               splt = string.split(widget.get_value(), ':', 1)
+               comicid = splt[0]
+               if os.path.isfile(activecomics) == True:
+                       print "removing " + comicid + " from " + str(self.active_comics)
+                       del self.active_comics[self.active_comics.index(comicid)]
+                       dbf = open(activecomics, 'w')
+                       dbw = csv.writer(dbf)
+                       dbw.writerow(self.active_comics)
+                       dbf.close()
+               widget.set_text(comics[comicid]['name'], comicid + ": click to add")
+               
 hd_plugin_type = ComicHomePlugin