possible fix to the problem with the widget not appearing in the add widget list.
[comic-widget] / src / usr / lib / hildon-desktop / comic-widget.py
index 6c3ae6e..03b299f 100644 (file)
@@ -1,3 +1,4 @@
+import gobject
 import hildon
 import hildondesktop
 import gtk
@@ -28,14 +29,13 @@ comics = {"xkcd":{"name":"xkcd","link":"http://xkcd.org/","start":666,"dbfile":d
 # handling of the comics
 class ComicDb():
        def __init__(self, comic):
-               #if no db, start from this comic id.
                self.comic = comic
                self.start = comics[self.comic]["start"]
                self.dbfile = comics[self.comic]["dbfile"]
 
                #if db file exist, read it
-               if os.path.isfile(self.dbfile) == True:
-                       dbf = open(self.dbfile, 'r')
+               # if os.path.isfile(self.dbfile) == True:
+               #       dbf = open(self.dbfile, 'r')
                # if not, create it.
                dbf = self.get_dbfile()
                dbr = csv.DictReader(dbf)
@@ -49,17 +49,21 @@ class ComicDb():
 
        def get_dbfile(self):
                #if db file exist, read it
+               print "fetching " + self.dbfile
                if os.path.isfile(self.dbfile) == True:
+                       print "found " + self.dbfile
                        dbf = open(self.dbfile, 'r')
                        return dbf
                # if not, copy it.
                else:
-                       if not os.path.exists(dbdir):
+                       print "file " + self.dbfile + " not found"
+                       if not os.path.exists(dbdir + self.comic + "/"):
+                               print "path not found: " + dbdir + self.comic + "/"
                                try:
-                                       os.makedirs(dbdir)
+                                       os.makedirs(dbdir + self.comic + "/")
                                except:
                                        print "comic db creation failed on mkdir"
-                                       exit()  
+                                       exit()
                        try:
                                shutil.copyfile(basedbdir + "comicdb." + self.comic + ".csv", dbdir + "comicdb." + self.comic + ".csv")
                        except:
@@ -93,6 +97,13 @@ class ComicDb():
                else:
                        #fetch file
                        print filename + " not found\nretrieving " + dbrow['url'] + "\n"
+                       if not os.path.exists(comiccache + self.comic + "/"):
+                               print "create dir " + comiccache + self.comic + "/"
+                               try:
+                                       os.makedirs(comiccache + self.comic + "/")
+                                       print "created dir"
+                               except:
+                                       print "comic db creation failed on mkdir"
                        urllib.urlretrieve(dbrow['url'], filename)
                        print "success\n"
                        return filename
@@ -271,6 +282,7 @@ class ComicDb():
 # ------------UI
 
 class ComicHomePlugin(hildondesktop.HomePluginItem):
+       __gtype_name__ = 'ComicHomePlugin'
        def __init__(self):
                hildondesktop.HomePluginItem.__init__(self)
                global supports_alpha
@@ -630,12 +642,11 @@ class ComicHomePlugin(hildondesktop.HomePluginItem):
                dialog.run()
                dialog.destroy()
 
-hd_plugin_type = ComicHomePlugin
-
+def hd_plugin_get_object():
+    return gobject.new(ComicHomePlugin, plugin_id = hildon_plugin_id)
 
 if __name__ == "__main__":
-       import gobject
-       gobject.type_register(hd_plugin_type)
-       obj = gobject.new(hd_plugin_type, plugin_id="plugin_id")
+       obj = hd_plugin_get_object()
        obj.show_all()
+    print obj.get_text()
        gtk.main()