import osso
import cairo
import pango
+import datetime
+
# constants. dbfile is the location of the csv
# comiccache is the location of the images
+APP_VERSION = "0.1"
imagedir = "/home/user/comic-widget/images/"
dbdir = "/home/user/comic-widget/db/"
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"}}
+ "sinfest":{"name":"Sinfest","link":"http://sinfest.com/","start":3400,"dbfile":dbdir + ".comicdb.sinfest.csv"},
+ "dilbert":{"name":"Dilbert","link":"http://dilbert.com.com/","start":"2009-01-01","dbfile":dbdir + ".comicdb.dilbert.csv"}}
# handling of the comics
class ComicDb():
for row in dbr:
self.db.insert(0,row)
dbf.close()
- self.currentcomic = 0
+ self.currentcomic = 0
def get_comic(self):
print str(self.currentcomic)
dbf.close()
def fetch_earlier(self, comic, earliest):
- number = int(earliest) - 1
- irow = self.get_irow(comic, number)
+ if len(earliest) == 10:
+ # date id.
+ dt = string.split(earliest, "-")
+ d = datetime.date(int(dt[0]),int(dt[1]),int(dt[2]))
+ earlier = d - datetime.timedelta( 1 )
+ comicid = earlier.isoformat()
+ else:
+ comicid = int(earliest) - 1
+
+ irow = self.get_irow(comic, comicid)
if irow:
print "got irow: "
print irow
print "\ninserting first...\n"
self.insert_row_first(irow)
else:
- print "No comic found at " + number
+ print "No comic found at " + comicid
+
+ def fetch_latest_std(self, comic, latest):
+ print "fetching new after " + str(comic) + " " + str(latest)
+ dateid = False
+ if len(latest) == 10:
+ # date id.
+ dateid = True
+ dt = string.split(latest, "-")
+ d = datetime.date(int(dt[0]),int(dt[1]),int(dt[2]))
+ newer = d + datetime.timedelta( 1 )
+ comicid = newer.isoformat()
+ else:
+ comicid = int(latest) + 1
+
+
+ while True:
+ irow = self.get_irow(comic, comicid)
+ if irow:
+ print "got irow: " + str(irow)
+ print "inserting..."
+ self.insert_row(irow)
+ if dateid:
+ dt = string.split(comicid, "-")
+ d = datetime.date(int(dt[0]),int(dt[1]),int(dt[2]))
+ newer = d + datetime.timedelta( 1 )
+ comicid = newer.isoformat()
+ else:
+ comicid += 1
+ else:
+ break
+
def get_irow(self, comic, number):
- if number < 0:
- return False
- print "number is now: " + str(number) + "\n"
+ dateid = False
+ if len(str(number)) == 10:
+ dateid = True
+ else:
+ if number < 0:
+ return False
+ print "number is now: " + str(number) + "\n"
if comic == 'xkcd':
link = "http://xkcd.org/" + str(number) + "/"
elif comic == 'sinfest':
link = "http://www.sinfest.net/archive_page.php?comicID=" + str(number)
+ elif comic == 'dilbert':
+ link = "http://dilbert.com/" + str(number) + "/"
else:
return False
- print "link: " + link + "\n"
+ print "link: " + link
try:
f = urllib2.urlopen(link)
hcode = f.code
return False
splt = string.split(splt[1], '" border="0" />', 1)
title = splt[0]
+
+ elif comic == 'dilbert':
+ s = f.read()
+ f.close()
+ splt = string.split(s, 'input type="hidden" name="PrintPath" value="', 1)
+ splt = string.split(splt[1], '" />', 1)
+ url = "http://dilbert.com" + splt[0]
+ if len(url) < 50:
+ print "Fake 404! Break break break!"
+ return False
+ title = ""
+
splt2 = string.rsplit(url, "/", 1)
filename = splt2[1]
irow = [comic,number,link,url,filename,title]
return irow
- print "got irow: "
- def fetch_latest_std(self, comic, latest):
- print "fetching new after " + str(comic) + " " + str(latest) + "\n"
- number = int(latest) + 1
- while True:
- irow = self.get_irow(comic, number)
- if irow:
- print "got irow: "
- print irow
- print "\ninserting...\n"
- self.insert_row(irow)
- number += 1
- else:
- break
-
-# ------------
+# ------------UI
class ComicHomePlugin(hildondesktop.HomePluginItem):
def __init__(self):
hildondesktop.HomePluginItem.__init__(self)
+ self.set_settings(True)
+ self.connect("show-settings", self.show_options)
self.osso_c = osso.Context("comic-widget", "0.0.1", False)
self.osso_rpc = osso.Rpc(self.osso_c)
self.keys = comics.keys()
self.label.set_alignment(xalign = 0, yalign = 0.5)
self.label.set_use_markup(True)
titl = str(self.db.db[self.db.currentcomic]['title'])
- if len(titl) > 18:
- titl = titl[:15] + "..."
+ if len(titl) > 22:
+ titl = titl[:19] + "..."
self.label.set_markup('<span size="12000" face="monospace"> <b>' + self.comicname + '</b> ' + str(self.db.db[self.db.currentcomic]['id']) + '\n ' + titl + '</span>')
self.e_goweb = gtk.EventBox()
self.e_goweb.set_name('goweb')
- self.e_goweb.set_size_request(178, 48)
+ self.e_goweb.set_size_request(220, 48)
# e_open is the eventbox for the image. Does nothing, but it's convenient to have it.
# it will change to be a cairo thing when I have the time.
self.e_open = gtk.EventBox()
self.vbox.pack_start(self.e_open,False,False,0)
self.vbox.pack_end(self.hbox,False,False,0)
- self.hbox.pack_start(self.e_switch,False,False,5)
- # self.hbox.add(self.label)
- self.hbox.pack_start(self.e_goweb,False,False,5)
- self.hbox.pack_end(self.e_next,False,False,5)
- self.hbox.pack_end(self.e_prev,False,False,5)
- self.hbox.pack_end(self.e_down,False,False,5)
- self.hbox.pack_end(self.e_up,False,False,5)
+ self.hbox.pack_start(self.e_switch,False,False,0)
+ self.hbox.pack_start(self.e_goweb,False,False,10)
+ self.hbox.pack_end(self.e_next,False,False,0)
+ self.hbox.pack_end(self.e_prev,False,False,0)
+ self.hbox.pack_end(self.e_down,False,False,0)
+ self.hbox.pack_end(self.e_up,False,False,0)
self.vbox.show_all()
self.add(self.vbox)
self.e_open.show_all()
self.e_goweb.remove(self.label)
titl = str(self.db.db[self.db.currentcomic]['title'])
- if len(titl) > 18:
- titl = titl[:15] + "..."
+ if len(titl) > 22:
+ titl = titl[:19] + "..."
self.label.set_markup('<span size="12000" face="monospace"> <b>' + self.comicname + '</b> ' + str(self.db.db[self.db.currentcomic]['id']) + '\n ' + titl + '</span>')
self.e_goweb.add(self.label)
self.e_goweb.show_all()
self.e_open.show_all()
self.e_goweb.remove(self.label)
titl = str(self.db.db[self.db.currentcomic]['title'])
- if len(titl) > 18:
- titl = titl[:15] + "..."
+ if len(titl) > 22:
+ titl = titl[:19] + "..."
self.label.set_markup('<span size="12000" face="monospace"> <b>' + self.comicname + '</b> ' + str(self.db.db[self.db.currentcomic]['id']) + '\n ' + titl + '</span>')
self.e_goweb.add(self.label)
self.e_goweb.show_all()
self.db = ComicDb(self.keys[self.keypointer])
self.e_goweb.remove(self.label)
titl = str(self.db.db[self.db.currentcomic]['title'])
- if len(titl) > 18:
- titl = titl[:15] + "..."
+ if len(titl) > 22:
+ titl = titl[:19] + "..."
self.label.set_markup('<span size="12000" face="monospace"> <b>' + self.comicname + '</b> ' + str(self.db.db[self.db.currentcomic]['id']) + '\n ' + titl + '</span>')
self.e_goweb.add(self.label)
self.e_goweb.show_all()
return retimg
+# ************************* OPTIONS ********************************
+
+ def show_options(self, widget):
+ dialog = gtk.Dialog("Comic Widget", None, gtk.DIALOG_DESTROY_WITH_PARENT)
+
+ about_button = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL)
+ about_button.set_text("About", "See Author, Copyright and License information")
+ about_button.set_alignment(0,0,0,0)
+ about_button.connect("clicked", self.show_about)
+
+ dialog.vbox.pack_start(about_button, True, True, 0)
+
+ dialog.show_all()
+ dialog.run()
+ dialog.destroy()
+
+ def show_about(self, widget):
+ dialog = gtk.AboutDialog()
+ dialog.set_title("About")
+ dialog.set_name("Comic widget")
+ dialog.set_version(APP_VERSION)
+ dialog.set_copyright("Copyright 2010 Marcus Wikstrom")
+ dialog.set_authors(["Marcus Wikstrom <mece@ovi.com>\n\nSpecial thanks to Benoit Hervier, Daniel Would and Brent Chiodo\nfor some nice code to sample."])
+ # 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_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()
+
hd_plugin_type = ComicHomePlugin