15 supports_alpha = False
17 # constants. dbfile is the location of the csv
18 # comiccache is the location of the images
21 basedbdir = "/opt/comic-widget/db/"
22 imagedir = "/opt/comic-widget/images/"
23 dbdir = "/home/user/.comic-widget/"
24 activecomics = dbdir + "activecomics.cfg"
25 comiccache = "/home/user/MyDocs/.comics/"
26 comics = {"xkcd":{"name":"xkcd","link":"http://xkcd.org/","start":666,"dbfile":dbdir + "comicdb.xkcd.csv"},
27 "sinfest":{"name":"Sinfest","link":"http://sinfest.com/","start":3400,"dbfile":dbdir + "comicdb.sinfest.csv"},
28 "phd":{"name":"PHD Comics","link":"http://www.phdcomics.com/","start":1240,"dbfile":dbdir + "comicdb.phd.csv"},
29 "dilbert":{"name":"Dilbert","link":"http://dilbert.com.com/","start":"2009-01-01","dbfile":dbdir + "comicdb.dilbert.csv"}}
31 # handling of the comics
33 def __init__(self, comic):
35 self.start = comics[self.comic]["start"]
36 self.dbfile = comics[self.comic]["dbfile"]
38 #if db file exist, read it
39 # if os.path.isfile(self.dbfile) == True:
40 # dbf = open(self.dbfile, 'r')
42 dbf = self.get_dbfile()
43 dbr = csv.DictReader(dbf)
53 #if db file exist, read it
54 print "fetching " + self.dbfile
55 if os.path.isfile(self.dbfile) == True:
56 print "found " + self.dbfile
57 dbf = open(self.dbfile, 'r')
61 print "file " + self.dbfile + " not found"
62 if not os.path.exists(dbdir):
63 print "path not found: " + dbdir
67 print "comic db creation failed on mkdir"
70 shutil.copyfile(basedbdir + "comicdb." + self.comic + ".csv", dbdir + "comicdb." + self.comic + ".csv")
72 print "comic db creation failed on copy"
73 print "creating new..."
74 dbf = open(self.dbfile, 'w')
75 dbf.write('comic,id,link,url,filename,title\n')
77 if os.path.isfile(self.dbfile) == True:
78 dbf = open(self.dbfile, 'r')
81 print "comic db creation failed after copy"
85 print str(self.currentcomic)
86 if self.currentcomic < 0:
89 if len(self.db) < (self.currentcomic + 1):
90 self.currentcomic -= 1
92 self.currentcomic = len(self.db) - 1
94 dbrow = self.db[self.currentcomic]
95 filename = comiccache + self.comic + "/" + dbrow['filename']
98 if os.path.isfile(filename):
99 print "found, returning " + filename + "\n"
103 print filename + " not found\nretrieving " + dbrow['url'] + "\n"
104 if not os.path.exists(comiccache + self.comic + "/"):
105 print "create dir " + comiccache + self.comic + "/"
107 os.makedirs(comiccache + self.comic + "/")
110 print "comic db creation failed on mkdir"
111 urllib.urlretrieve(dbrow['url'], filename)
115 def get_current_row(self):
116 return self.db[self.currentcomic]
119 print str(self.currentcomic)
120 if self.currentcomic < 0:
122 self.currentcomic = 0
123 if len(self.db) < (self.currentcomic + 1):
124 self.currentcomic -= 1
125 return self.db[self.currentcomic]['link']
129 def insert_row(self, irow):
130 dbf = open(self.dbfile, 'a')
131 dbw = csv.writer(dbf)
135 def insert_row_first(self, irow):
136 dbf = open(self.dbfile, 'w')
137 dbf.write('comic,id,link,url,filename,title\n')
138 dbw = csv.writer(dbf)
141 dbf = open(self.dbfile, 'a')
142 dbw = csv.DictWriter(dbf, ['comic','id','link','url','filename','title'])
151 self.fetch_latest_std(self.comic, self.start)
152 elif self.currentcomic == 0 or self.currentcomic < 0:
153 self.fetch_latest_std(self.comic, self.db[0]['id'])
154 elif self.currentcomic == (len(self.db) - 1):
155 self.fetch_earlier(self.comic, self.db[self.currentcomic]['id'])
156 dbf = open(self.dbfile, 'r')
157 dbr = csv.DictReader(dbf)
160 self.db.insert(0,row)
163 def fetch_earlier(self, comic, earliest):
164 if len(earliest) == 10:
166 dt = string.split(earliest, "-")
167 d = datetime.date(int(dt[0]),int(dt[1]),int(dt[2]))
168 earlier = d - datetime.timedelta( 1 )
169 comicid = earlier.isoformat()
171 comicid = int(earliest) - 1
173 irow = self.get_irow(comic, comicid)
177 print "\ninserting first...\n"
178 self.insert_row_first(irow)
180 print "No comic found at " + comicid
182 def fetch_latest_std(self, comic, latest):
183 print "fetching new after " + str(comic) + " " + str(latest)
185 if len(str(latest)) == 10:
188 dt = string.split(latest, "-")
189 d = datetime.date(int(dt[0]),int(dt[1]),int(dt[2]))
190 newer = d + datetime.timedelta( 1 )
191 comicid = newer.isoformat()
193 comicid = int(latest) + 1
195 lasturl = self.db[0]['url']
197 irow = self.get_irow(comic, comicid)
199 print "got irow: " + str(irow)
200 if irow[3] == lasturl:
201 print "Looping the same, break break break!"
205 self.insert_row(irow)
207 dt = string.split(comicid, "-")
208 d = datetime.date(int(dt[0]),int(dt[1]),int(dt[2]))
209 newer = d + datetime.timedelta( 1 )
210 comicid = newer.isoformat()
217 def get_irow(self, comic, number):
219 if len(str(number)) == 10:
224 print "number is now: " + str(number) + "\n"
226 link = "http://xkcd.org/" + str(number) + "/"
227 elif comic == 'sinfest':
228 link = "http://www.sinfest.net/archive_page.php?comicID=" + str(number)
229 elif comic == 'dilbert':
230 link = "http://dilbert.com/" + str(number) + "/"
232 link = "http://www.phdcomics.com/comics/archive.php?comicid=" + str(number)
236 print "link: " + link
238 f = urllib2.urlopen(link)
242 print "got hcode = " + str(hcode) + "\n"
247 # they look like: comic,id,link,url,filename,title
248 # We already have comic, number/id and link
253 # This should be done with regex but...
254 splt = string.split(s, "<h3>Image URL (for hotlinking/embedding): ", 1)
255 splt2 = string.split(splt[1], "</h3>", 1)
257 splt = string.split(splt[0], "<h1>", 1)
258 splt = string.split(splt[1], "</h1>", 1)
262 elif comic == 'sinfest':
265 splt = string.split(s, 'height="107"', 1)
266 splt = string.split(splt[1], '<img src="', 1)
267 splt = string.split(splt[1], '" alt="', 1)
270 print "Fake 404! Break break break!"
272 splt = string.split(splt[1], '" border="0" />', 1)
275 elif comic == 'dilbert':
278 splt = string.split(s, 'input type="hidden" name="PrintPath" value="', 1)
279 splt = string.split(splt[1], '" />', 1)
280 url = "http://dilbert.com" + splt[0]
282 print "Fake 404! Break break break!"
290 splt = string.split(s, '<title>PHD Comics: ', 1)
291 splt = string.split(splt[1], '</title>', 1)
293 splt = string.split(splt[1], '<td bgcolor=#FFFFFF align=center><img src=', 1)
294 splt = string.split(splt[1], ' align=top>', 1)
297 print "Fake 404! Break break break!"
301 splt2 = string.rsplit(url, "/", 1)
303 irow = [comic,number,link,url,filename,title]
309 class ComicHomePlugin(hildondesktop.HomePluginItem):
310 __gtype_name__ = 'ComicHomePlugin'
312 hildondesktop.HomePluginItem.__init__(self)
313 global supports_alpha
314 self.set_settings(True)
315 self.active_comics = self.get_active_comics()
316 self.connect("show-settings", self.show_options)
317 self.osso_c = osso.Context("comic-widget", "0.3.0", False)
318 self.osso_rpc = osso.Rpc(self.osso_c)
320 if len(self.active_comics) < 1:
321 self.active_comics = ['xkcd']
322 self.db = ComicDb(self.active_comics[self.keypointer])
323 self.comicname = comics[self.active_comics[self.keypointer]]['name']
324 self.set_name = "comicwidget"
325 screen = self.get_screen()
326 colormap = screen.get_rgba_colormap()
328 colormap = screen.get_rgb_colormap()
329 supports_alpha = False
331 supports_alpha = True
332 self.set_colormap(colormap)
333 self.set_app_paintable(True)
335 self.set_size_request(480, 230)
337 self.vbox = gtk.VBox()
338 self.hbox = gtk.HBox()
339 self.label = gtk.Label()
340 self.label.set_alignment(xalign = 0, yalign = 0.5)
341 self.label.set_use_markup(True)
342 titl = str(self.db.db[self.db.currentcomic]['title'])
344 titl = titl[:19] + "..."
345 self.label.set_markup('<span size="12000" face="monospace"> <b>' + self.comicname + '</b> ' + str(self.db.db[self.db.currentcomic]['id']) + '\n ' + titl + '</span>')
348 self.e_goweb = gtk.EventBox()
349 self.e_goweb.set_name('goweb')
350 self.e_goweb.set_size_request(220, 48)
351 # e_open is the eventbox for the image. Does nothing, but it's convenient to have it.
352 # it will change to be a cairo thing when I have the time.
353 self.e_open = gtk.EventBox()
354 self.e_open.set_name('open')
355 self.e_switch = gtk.EventBox()
356 self.e_switch.set_name('switch')
357 self.e_switch.set_size_request(48, 48)
358 self.e_next = gtk.EventBox()
359 self.e_next.set_name('next')
360 self.e_next.set_size_request(48, 48)
361 self.e_prev = gtk.EventBox()
362 self.e_prev.set_name('prev')
363 self.e_prev.set_size_request(48, 48)
364 self.e_up = gtk.EventBox()
365 self.e_up.set_name('up')
366 self.e_up.set_size_request(48, 48)
367 self.e_down = gtk.EventBox()
368 self.e_down.set_name('down')
369 self.e_down.set_size_request(48, 48)
370 self.comic_image = self.get_resized_pixmap(self.db.get_comic(), self.imgvpos)
371 self.comic_image.show()
374 # Preload images into a dictionary, so that we can access them by the names of the eventboxes:
376 self.images = {'up0':cairo.ImageSurface.create_from_png(imagedir + "up0-48x48.png"),
377 'up1':cairo.ImageSurface.create_from_png(imagedir + "up1-48x48.png"),
378 'down0':cairo.ImageSurface.create_from_png(imagedir + "down0-48x48.png"),
379 'down1':cairo.ImageSurface.create_from_png(imagedir + "down1-48x48.png"),
380 'next0':cairo.ImageSurface.create_from_png(imagedir + "next0-48x48.png"),
381 'next1':cairo.ImageSurface.create_from_png(imagedir + "next1-48x48.png"),
382 'prev0':cairo.ImageSurface.create_from_png(imagedir + "prev0-48x48.png"),
383 'prev1':cairo.ImageSurface.create_from_png(imagedir + "prev1-48x48.png"),
384 'switch0':cairo.ImageSurface.create_from_png(imagedir + "switch0-48x48.png"),
385 'switch1':cairo.ImageSurface.create_from_png(imagedir + "switch1-48x48.png"),
390 self.e_goweb.add(self.label)
391 self.e_goweb.set_events(gtk.gdk.BUTTON_RELEASE_MASK)
392 self.e_goweb.connect("button-release-event", self.view_comic)
394 self.e_open.add(self.comic_image)
396 # self.e_switch.add(self.switch)
397 self.e_switch.set_events(gtk.gdk.BUTTON_PRESS_MASK|gtk.gdk.BUTTON_RELEASE_MASK|gtk.gdk.LEAVE_NOTIFY)
398 self.e_switch.connect("button-press-event", self.button_press)
399 self.e_switch.connect("button-release-event", self.button_release)
400 self.e_switch.connect("leave-notify-event", self.button_release)
403 # self.e_next.add(self.next)
404 self.e_next.set_events(gtk.gdk.BUTTON_PRESS_MASK|gtk.gdk.BUTTON_RELEASE_MASK|gtk.gdk.LEAVE_NOTIFY)
405 self.e_next.connect("button-press-event", self.button_press)
406 self.e_next.connect("button-release-event", self.button_release)
407 self.e_next.connect("leave-notify-event", self.button_release)
409 #self.e_prev.add(self.prev)
410 self.e_prev.set_events(gtk.gdk.BUTTON_PRESS_MASK|gtk.gdk.BUTTON_RELEASE_MASK|gtk.gdk.LEAVE_NOTIFY)
411 self.e_prev.connect("button-press-event", self.button_press)
412 self.e_prev.connect("button-release-event", self.button_release)
413 self.e_prev.connect("leave-notify-event", self.button_release)
415 #self.e_up.add(self.up)
416 self.e_up.set_events(gtk.gdk.BUTTON_PRESS_MASK|gtk.gdk.BUTTON_RELEASE_MASK|gtk.gdk.LEAVE_NOTIFY)
417 self.e_up.connect("button-press-event", self.button_press)
418 self.e_up.connect("button-release-event", self.button_release)
419 self.e_up.connect("leave-notify-event", self.button_release)
422 #self.e_down.add(self.down)
423 self.e_down.set_events(gtk.gdk.BUTTON_PRESS_MASK|gtk.gdk.BUTTON_RELEASE_MASK|gtk.gdk.LEAVE_NOTIFY)
424 self.e_down.connect("button-press-event", self.button_press)
425 self.e_down.connect("button-release-event", self.button_release)
426 self.e_down.connect("leave-notify-event", self.button_release)
428 self.vbox.pack_start(self.e_open,False,False,0)
429 self.vbox.pack_end(self.hbox,False,False,0)
431 self.hbox.pack_start(self.e_switch,False,False,0)
432 self.hbox.pack_start(self.e_goweb,False,False,10)
433 self.hbox.pack_end(self.e_next,False,False,0)
434 self.hbox.pack_end(self.e_prev,False,False,0)
435 self.hbox.pack_end(self.e_down,False,False,0)
436 self.hbox.pack_end(self.e_up,False,False,0)
440 # **************** Cairo draw functions ***************
442 def realize(self, widget):
443 global supports_alpha
445 # To check if the display supports alpha channels, get the colormap
446 screen = self.get_screen()
447 colormap = screen.get_rgba_colormap()
449 print 'Your screen does not support alpha channels!'
450 colormap = screen.get_rgb_colormap()
451 supports_alpha = False
453 # print 'Your screen supports alpha channels!'
454 supports_alpha = True
456 # Now we have a colormap appropriate for the screen, use it
457 self.set_colormap(colormap)
461 def do_expose_event(widget, event):
462 cr = widget.window.cairo_create()
463 widget.draw(widget.e_up, 0)
464 widget.draw(widget.e_down, 0)
465 widget.draw(widget.e_prev,0)
466 widget.draw(widget.e_next, 0)
467 widget.draw(widget.e_switch, 0)
468 # widget.writeit(widget.e_goweb, "asdf")
469 cr.set_operator(cairo.OPERATOR_OVER)
470 region = gtk.gdk.region_rectangle(event.area)
472 bg_color=gtk.gdk.color_parse('#000000')
474 cr.set_source_rgba (0.0, 0.0, 0.0, 0.5)
476 cr.set_source_rgb (0.0, 0.0, 0.0)
481 # Function that draws a button preloaded in the images dictionary.
482 def draw(self, target, postfix):
483 cr_e = target.window.cairo_create()
484 cr_e.set_source_rgba(0.0, 0.0, 0.0, 0.5) # Transparent
485 cr_e.set_operator(cairo.OPERATOR_SOURCE)
487 cr_e.set_operator(cairo.OPERATOR_OVER)
488 cr_e.set_source_surface(self.images[target.get_name() + str(postfix)], 0, 0)
491 # ********** Event handlers *************
494 # Most events happen on release, so I moved all of them into the same event handler.
495 def button_release(self, widget, event):
496 if event.type == gtk.gdk.BUTTON_RELEASE:
497 func = widget.get_name()
498 print "pressed: " + func
500 self.e_open.remove(self.comic_image)
501 self.imgvpos = self.imgvpos - 80
504 self.comic_image = self.get_resized_pixmap(self.db.get_comic(), self.imgvpos)
505 self.e_open.add(self.comic_image)
506 self.e_open.show_all()
509 self.e_open.remove(self.comic_image)
510 self.imgvpos = self.imgvpos + 80
511 self.comic_image = self.get_resized_pixmap(self.db.get_comic(), self.imgvpos)
512 self.e_open.add(self.comic_image)
513 self.e_open.show_all()
516 self.db.currentcomic -= 1
518 self.e_open.remove(self.comic_image)
519 self.comic_image = self.get_resized_pixmap(self.db.get_comic(), self.imgvpos)
520 self.e_open.add(self.comic_image)
521 self.e_open.show_all()
522 self.e_goweb.remove(self.label)
523 titl = str(self.db.db[self.db.currentcomic]['title'])
525 titl = titl[:19] + "..."
526 self.label.set_markup('<span size="12000" face="monospace"> <b>' + self.comicname + '</b> ' + str(self.db.db[self.db.currentcomic]['id']) + '\n ' + titl + '</span>')
527 self.e_goweb.add(self.label)
528 self.e_goweb.show_all()
531 self.db.currentcomic += 1
533 self.e_open.remove(self.comic_image)
534 self.comic_image = self.get_resized_pixmap(self.db.get_comic(), self.imgvpos)
535 self.e_open.add(self.comic_image)
536 self.e_open.show_all()
537 self.e_goweb.remove(self.label)
538 titl = str(self.db.db[self.db.currentcomic]['title'])
540 titl = titl[:19] + "..."
541 self.label.set_markup('<span size="12000" face="monospace"> <b>' + self.comicname + '</b> ' + str(self.db.db[self.db.currentcomic]['id']) + '\n ' + titl + '</span>')
542 self.e_goweb.add(self.label)
543 self.e_goweb.show_all()
545 elif func == 'switch':
546 self.active_comics = self.get_active_comics()
547 print "active comics: " + str(self.active_comics)
548 self.keypointer = (self.keypointer + 1) % len(self.active_comics)
551 print "switching to " + self.active_comics[self.keypointer]
552 self.comicname = comics[self.active_comics[self.keypointer]]['name']
553 self.db = ComicDb(self.active_comics[self.keypointer])
554 self.e_open.remove(self.comic_image)
555 self.comic_image = self.get_resized_pixmap(self.db.get_comic(), self.imgvpos)
556 self.e_goweb.remove(self.label)
557 titl = str(self.db.db[self.db.currentcomic]['title'])
559 titl = titl[:19] + "..."
560 self.label.set_markup('<span size="12000" face="monospace"> <b>' + self.comicname + '</b> ' + str(self.db.db[self.db.currentcomic]['id']) + '\n ' + titl + '</span>')
561 self.e_goweb.add(self.label)
562 self.e_goweb.show_all()
563 self.e_open.add(self.comic_image)
564 self.e_open.show_all()
568 self.draw(widget, "0")
570 # this one only switches to pressed button image
571 def button_press(self, widget, event):
572 if not event.type == gtk.gdk.BUTTON_PRESS:
574 self.draw(widget, "1")
576 # this one cancels a button press when pointer is moved out from it after press.
577 def button_out(self, widget, event):
578 if not event.type == gtk.gdk.BUTTON_PRESS:
580 self.draw(widget, "0")
582 # no fancy cairo stuff here. simply launches url in browser.
583 def view_comic(self, widget, event):
584 if not event.type == gtk.gdk.BUTTON_RELEASE:
586 link = self.db.get_link()
587 self.osso_rpc.rpc_run_with_defaults("osso_browser", "open_new_window", (link,))
591 # this function modifies the image to fit the widget and then returns it.
593 def get_resized_pixmap(self, filename, vpos):
594 print "vpos: " + str(vpos)
598 pixbuf = gtk.gdk.pixbuf_new_from_file(filename)
599 parent_buf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, pixbuf.get_has_alpha(), 8, 480, maxheight)
600 parent_buf.fill(0xffffffff)
602 # get correct width/height
605 new_height = int((478.0 / pixbuf.get_width()) * pixbuf.get_height())
606 scaled_buf = pixbuf.scale_simple(new_width,new_height,gtk.gdk.INTERP_BILINEAR)
607 print "scaled height: " + str(scaled_buf.get_height())
608 if scaled_buf.get_height() > maxheight:
609 if scaled_buf.get_height() - (vpos + maxheight) < 0:
610 vpos = scaled_buf.get_height() - maxheight
611 scaled_buf.copy_area(0,vpos,478,maxheight,parent_buf,1,0)
614 tmpy = maxheight - scaled_buf.get_height()
618 scaled_buf.copy_area(0,0,478,scaled_buf.get_height(),parent_buf,1,tmpy)
620 retimg.set_from_pixbuf(parent_buf)
621 print "vpos after fixing image: " + str(self.imgvpos)
624 def screen_changed(self, widget, old_screen=None):
625 global supports_alpha
627 # To check if the display supports alpha channels, get the colormap
628 screen = self.get_screen()
629 colormap = screen.get_rgba_colormap()
631 print 'Your screen does not support alpha channels!'
632 colormap = screen.get_rgb_colormap()
633 supports_alpha = False
635 # print 'Your screen supports alpha channels!'
636 supports_alpha = True
638 # Now we have a colormap appropriate for the screen, use it
639 self.set_colormap(colormap)
644 def get_active_comics(self):
647 if os.path.isfile(activecomics) == True:
648 print "found " + activecomics
649 dbf = open(activecomics, 'r')
650 dbr = csv.reader(dbf)
659 print "file " + activecomics + " not found"
660 if not os.path.exists(dbdir):
661 print "path not found: " + dbdir
665 print "settings dir creation failed. Exiting."
668 # dbf = file(activecomics, 'w')
670 dbf = open(activecomics, 'w')
672 print "error storing settings"
674 dbw = csv.writer(dbf)
675 dbw.writerow(comics.keys())
684 #check if settings file exists
686 #if not, write defaults
688 # ************************* OPTION DIALOGS ********************************
690 def show_options(self, widget):
691 dialog = gtk.Dialog("Comic Widget", None, gtk.DIALOG_DESTROY_WITH_PARENT)
693 about_button = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL)
694 about_button.set_text("About", "See Author, Copyright and License information")
695 about_button.set_alignment(0,0,0,0)
696 about_button.connect("clicked", self.show_about)
698 comics_button = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL)
699 comics_button.set_text("Comics", "Choose which comics to view")
700 comics_button.set_alignment(0,0,0,0)
701 comics_button.connect("clicked", self.show_comics)
703 dialog.vbox.pack_start(about_button, True, True, 0)
704 dialog.vbox.pack_start(comics_button, True, True, 0)
710 def show_about(self, widget):
711 dialog = gtk.AboutDialog()
712 dialog.set_title("About")
713 dialog.set_name("Comic widget")
714 dialog.set_version(APP_VERSION)
715 dialog.set_copyright("Copyright 2010 Marcus Wikstrom")
716 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."])
717 dialog.set_logo(gtk.gdk.pixbuf_new_from_file("/opt/comic-widget/images/icon2-64x64.png"))
718 dialog.set_comments("Silly rabbit, tricks are for kids.")
719 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/>.""")
720 dialog.set_wrap_license(True)
725 def show_comics(self, widget):
726 dialog = gtk.Dialog("Configure Search Engines", None, gtk.DIALOG_DESTROY_WITH_PARENT | gtk.DIALOG_NO_SEPARATOR)
727 comiclist = comics.keys()
730 for comicid in comiclist:
731 buttonlist[comicid] = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL)
732 print buttonlist[comicid].get_name()
734 print buttonlist[comicid].set_alignment(0, 0.5, 0, 0.5)
736 for acomic in self.active_comics:
737 if acomic == comicid:
741 buttonlist[comicid].set_text(comics[comicid]['name'] + " *", comicid + ": click to remove")
742 buttonlist[comicid].connect("clicked", self.remove_comic)
744 buttonlist[comicid].set_text(comics[comicid]['name'], comicid + ": click to add")
745 buttonlist[comicid].connect("clicked", self.add_comic)
746 dialog.vbox.pack_start(buttonlist[comicid], True, True, 0)
753 def add_comic(self, widget):
754 print "add " + widget.get_title()
755 splt = string.split(widget.get_value(), ':', 1)
757 if os.path.isfile(activecomics) == True:
758 print "added " + comicid + " to " + str(self.active_comics)
760 found = self.active_comics.index(comicid)
762 self.active_comics.append(comicid)
763 dbf = open(activecomics, 'w')
764 dbw = csv.writer(dbf)
765 dbw.writerow(self.active_comics)
767 widget.set_text(comics[comicid]['name'] + " *", comicid + ": click to remove")
769 def remove_comic(self, widget):
770 print "remove " + widget.get_title()
771 if len(self.active_comics) == 1:
773 splt = string.split(widget.get_value(), ':', 1)
775 if os.path.isfile(activecomics) == True:
776 print "removing " + comicid + " from " + str(self.active_comics)
777 del self.active_comics[self.active_comics.index(comicid)]
778 dbf = open(activecomics, 'w')
779 dbw = csv.writer(dbf)
780 dbw.writerow(self.active_comics)
782 widget.set_text(comics[comicid]['name'], comicid + ": click to add")
784 hd_plugin_type = ComicHomePlugin
787 if __name__ == "__main__":
789 gobject.type_register(hd_plugin_type)
790 obj = gobject.new(hd_plugin_type, plugin_id="plugin_id")