46b982445a3f3e5b6580d013f8aadaae25096bae
[comic-widget] / src / usr / lib / hildon-desktop / comic-widget.py
1 import hildon
2 import hildondesktop
3 import gtk
4 import csv
5 import urllib2
6 import urllib
7 import string
8 import os
9 import osso
10 import cairo
11 import datetime
12
13 supports_alpha = False
14
15 # constants. dbfile is the location of the csv
16 # comiccache is the location of the images
17 APP_VERSION = "0.2.5"
18
19 imagedir = "/opt/comic-widget/images/"
20 dbdir = "/home/user/MyDocs/.comics/db/"
21 comiccache = "/home/user/MyDocs/.comics/"
22 comics = {"xkcd":{"name":"xkcd","link":"http://xkcd.org/","start":666,"dbfile":dbdir + "comicdb.xkcd.csv"},
23                 "sinfest":{"name":"Sinfest","link":"http://sinfest.com/","start":3400,"dbfile":dbdir + "comicdb.sinfest.csv"},
24                 "dilbert":{"name":"Dilbert","link":"http://dilbert.com.com/","start":"2009-01-01","dbfile":dbdir + "comicdb.dilbert.csv"}}
25
26 # handling of the comics
27 class ComicDb():
28         def __init__(self, comic):
29                 #if no db, start from this comic id.
30                 self.comic = comic
31                 self.start = comics[self.comic]["start"]
32                 self.dbfile = comics[self.comic]["dbfile"]
33
34                 #if db file exist, read it
35                 if os.path.isfile(self.dbfile) == True:
36                         dbf = open(self.dbfile, 'r')
37                 # if not, create it.
38                 else:
39                         dbf = open(self.dbfile, 'w')
40                         dbf.write('comic,id,link,url,filename,title\n')
41                         dbf.close()
42                         dbf = open(self.dbfile, 'r')
43                         self.fetch_latest_std(self.comic, self.start)
44
45                 if not os.path.exists(comiccache + self.comic + "/"):
46                         try:
47                                 os.makedirs(comiccache + self.comic + "/")
48                         except:
49                                 print "comic cache creation failed"
50                                 exit()
51                 dbr = csv.DictReader(dbf)
52                 self.db = []
53                 for row in dbr:
54                         self.db.insert(0,row)
55                 dbf.close()
56                 self.currentcomic = 0           
57
58         def get_comic(self):
59                 print str(self.currentcomic)
60                 if self.currentcomic < 0:
61                         self.refresh()
62                         self.currentcomic = 0
63                 if  len(self.db) < (self.currentcomic + 1):
64                         self.currentcomic -= 1
65                         self.refresh()
66                         self.currentcomic = len(self.db) - 1
67                         
68                 dbrow = self.db[self.currentcomic]
69                 filename = comiccache + self.comic + "/" + dbrow['filename']
70                 print filename + "\n"
71                 
72                 if os.path.isfile(filename):
73                         print "found, returning " + filename + "\n"
74                         return filename
75                 else:
76                         #fetch file
77                         print filename + " not found\nretrieving " + dbrow['url'] + "\n"
78                         urllib.urlretrieve(dbrow['url'], filename)
79                         print "success\n"
80                         return filename
81
82         def get_current_row(self):
83                 return self.db[self.currentcomic]               
84
85         def get_link(self):
86                 print str(self.currentcomic)
87                 if self.currentcomic < 0:
88                         self.refresh()
89                         self.currentcomic = 0
90                 if  len(self.db) < (self.currentcomic + 1):
91                         self.currentcomic -= 1
92                 return self.db[self.currentcomic]['link']
93
94
95
96         def insert_row(self, irow):
97                 dbf = open(self.dbfile, 'a')
98                 dbw = csv.writer(dbf)
99                 dbw.writerow(irow)
100                 dbf.close()
101
102         def insert_row_first(self, irow):
103                 dbf = open(self.dbfile, 'w')
104                 dbf.write('comic,id,link,url,filename,title\n')
105                 dbw = csv.writer(dbf)
106                 dbw.writerow(irow)
107                 dbf.close()
108                 dbf = open(self.dbfile, 'a')
109                 dbw = csv.DictWriter(dbf, ['comic','id','link','url','filename','title'])
110                 tmpdb = self.db
111                 tmpdb.reverse()
112                 for row in tmpdb:
113                         dbw.writerow(row)
114                 dbf.close()
115
116         def refresh(self):
117                 if len(self.db) < 1:
118                         self.fetch_latest_std(self.comic, self.start)
119                 elif self.currentcomic == 0 or self.currentcomic < 0:
120                         self.fetch_latest_std(self.comic, self.db[0]['id'])
121                 elif self.currentcomic == (len(self.db) - 1):
122                         self.fetch_earlier(self.comic, self.db[self.currentcomic]['id'])
123                 dbf = open(self.dbfile, 'r')
124                 dbr = csv.DictReader(dbf)
125                 self.db = []
126                 for row in dbr:
127                         self.db.insert(0,row)
128                 dbf.close()
129
130         def fetch_earlier(self, comic, earliest):
131                 if len(earliest) == 10:
132                         # date id.
133                         dt = string.split(earliest, "-")
134                         d = datetime.date(int(dt[0]),int(dt[1]),int(dt[2]))
135                         earlier = d - datetime.timedelta( 1 )
136                         comicid = earlier.isoformat()
137                 else:
138                         comicid = int(earliest) - 1
139
140                 irow = self.get_irow(comic, comicid)
141                 if irow:
142                         print "got irow: "
143                         print irow
144                         print "\ninserting first...\n"
145                         self.insert_row_first(irow)
146                 else:
147                         print "No comic found at " + comicid
148
149         def fetch_latest_std(self, comic, latest):
150                 print "fetching new after " + str(comic) + " " + str(latest)
151                 dateid = False
152                 if len(latest) == 10:
153                         # date id.
154                         dateid = True
155                         dt = string.split(latest, "-")
156                         d = datetime.date(int(dt[0]),int(dt[1]),int(dt[2]))
157                         newer = d + datetime.timedelta( 1 )
158                         comicid = newer.isoformat()
159                 else:
160                         comicid = int(latest) + 1
161
162
163                 while True:
164                         irow = self.get_irow(comic, comicid)
165                         if irow:
166                                 print "got irow: " + str(irow)
167                                 print "inserting..."
168                                 self.insert_row(irow)
169                                 if dateid:
170                                         dt = string.split(comicid, "-")
171                                         d = datetime.date(int(dt[0]),int(dt[1]),int(dt[2]))
172                                         newer = d + datetime.timedelta( 1 )
173                                         comicid = newer.isoformat()
174                                 else:
175                                         comicid += 1
176                         else:
177                                 break
178
179
180         def get_irow(self, comic, number):
181                 dateid = False
182                 if len(str(number)) == 10:
183                         dateid = True
184                 else:
185                         if number < 0:
186                                 return False
187                         print "number is now: " + str(number) + "\n"
188                 if comic == 'xkcd':
189                         link = "http://xkcd.org/" + str(number) + "/"
190                 elif comic == 'sinfest':
191                         link = "http://www.sinfest.net/archive_page.php?comicID=" + str(number)
192                 elif comic == 'dilbert':
193                         link = "http://dilbert.com/" + str(number) + "/"
194                 else:
195                         return False
196
197                 print "link: " + link
198                 try:
199                         f = urllib2.urlopen(link)
200                         hcode = f.code
201                 except:
202                         hcode = 404
203                 print "got hcode = " + str(hcode) + "\n"
204                 if (hcode != 200):
205                         return False
206                 else:
207                         # Build db entry.
208                         # they look like: comic,id,link,url,filename,title
209                         # We already have comic, number/id and link
210
211                         if comic == 'xkcd':
212                                 s = f.read()
213                                 f.close()
214                                 # This should be done with regex but...
215                                 splt = string.split(s, "<h3>Image URL (for hotlinking/embedding): ", 1)
216                                 splt2 = string.split(splt[1], "</h3>", 1)
217                                 url = splt2[0]
218                                 splt = string.split(splt[0], "<h1>", 1)
219                                 splt = string.split(splt[1], "</h1>", 1)
220
221                                 title = splt[0]
222
223                         elif comic == 'sinfest':
224                                 s = f.read()
225                                 f.close()
226                                 splt = string.split(s, 'height="107"', 1)
227                                 splt = string.split(splt[1], '<img src="', 1)
228                                 splt = string.split(splt[1], '" alt="', 1)
229                                 url = splt[0]
230                                 if len(url) < 49:
231                                         print "Fake 404! Break break break!"
232                                         return False
233                                 splt = string.split(splt[1], '" border="0" />', 1)
234                                 title = splt[0]
235
236                         elif comic == 'dilbert':
237                                 s = f.read()
238                                 f.close()
239                                 splt = string.split(s, 'input type="hidden" name="PrintPath" value="', 1)
240                                 splt = string.split(splt[1], '" />', 1)
241                                 url = "http://dilbert.com" + splt[0]
242                                 if len(url) < 50:
243                                         print "Fake 404! Break break break!"
244                                         return False
245                                 title = ""
246
247                         splt2 = string.rsplit(url, "/", 1)
248                         filename = splt2[1]
249                         irow = [comic,number,link,url,filename,title]
250                         return irow
251
252
253 # ------------UI
254
255 class ComicHomePlugin(hildondesktop.HomePluginItem):
256         def __init__(self):
257                 hildondesktop.HomePluginItem.__init__(self)
258                 global supports_alpha
259                 self.set_settings(True)
260                 self.connect("show-settings", self.show_options)
261                 self.osso_c = osso.Context("comic-widget", "0.0.1", False)
262                 self.osso_rpc = osso.Rpc(self.osso_c)
263                 self.keys = comics.keys()
264                 self.keypointer = 1
265                 self.db = ComicDb(self.keys[self.keypointer])
266                 self.comicname = comics[self.keys[self.keypointer]]['name']
267                 self.set_name = "comicwidget"
268                 screen = self.get_screen()
269                 colormap = screen.get_rgba_colormap()
270                 if colormap == None:
271                         colormap = screen.get_rgb_colormap()
272                         supports_alpha = False
273                 else:
274                         supports_alpha = True
275                 self.set_colormap(colormap)
276                 self.set_app_paintable(True)
277                 #setup internal area
278                 self.set_size_request(480, 230)
279                 self.imgvpos = 0;
280                 self.vbox = gtk.VBox()
281                 self.hbox = gtk.HBox()
282                 self.label = gtk.Label()
283                 self.label.set_alignment(xalign = 0, yalign = 0.5)
284                 self.label.set_use_markup(True)
285                 titl = str(self.db.db[self.db.currentcomic]['title'])
286                 if len(titl) > 22:
287                         titl = titl[:19] + "..."
288                 self.label.set_markup('<span size="12000" face="monospace"> <b>' + self.comicname + '</b> ' + str(self.db.db[self.db.currentcomic]['id']) + '\n ' + titl + '</span>')
289
290
291                 self.e_goweb = gtk.EventBox()
292                 self.e_goweb.set_name('goweb')
293                 self.e_goweb.set_size_request(220, 48)
294                 # e_open is the eventbox for the image. Does nothing, but it's convenient to have it.
295                 # it will change to be a cairo thing when I have the time.
296                 self.e_open = gtk.EventBox()
297                 self.e_open.set_name('open')
298                 self.e_switch = gtk.EventBox()
299                 self.e_switch.set_name('switch')
300                 self.e_switch.set_size_request(48, 48)
301                 self.e_next = gtk.EventBox()
302                 self.e_next.set_name('next')
303                 self.e_next.set_size_request(48, 48)
304                 self.e_prev = gtk.EventBox()
305                 self.e_prev.set_name('prev')
306                 self.e_prev.set_size_request(48, 48)
307                 self.e_up = gtk.EventBox()
308                 self.e_up.set_name('up')
309                 self.e_up.set_size_request(48, 48)
310                 self.e_down = gtk.EventBox()
311                 self.e_down.set_name('down')
312                 self.e_down.set_size_request(48, 48)
313                 self.comic_image = self.get_resized_pixmap(self.db.get_comic(), self.imgvpos)
314                 self.comic_image.show()
315                 
316
317                 # Preload images into a dictionary, so that we can access them by the names of the eventboxes:
318
319                 self.images = {'up0':cairo.ImageSurface.create_from_png(imagedir + "up0-48x48.png"),
320                                         'up1':cairo.ImageSurface.create_from_png(imagedir + "up1-48x48.png"),
321                                         'down0':cairo.ImageSurface.create_from_png(imagedir + "down0-48x48.png"),
322                                         'down1':cairo.ImageSurface.create_from_png(imagedir + "down1-48x48.png"),
323                                         'next0':cairo.ImageSurface.create_from_png(imagedir + "next0-48x48.png"),
324                                         'next1':cairo.ImageSurface.create_from_png(imagedir + "next1-48x48.png"),
325                                         'prev0':cairo.ImageSurface.create_from_png(imagedir + "prev0-48x48.png"),
326                                         'prev1':cairo.ImageSurface.create_from_png(imagedir + "prev1-48x48.png"),
327                                         'switch0':cairo.ImageSurface.create_from_png(imagedir + "switch0-48x48.png"),
328                                         'switch1':cairo.ImageSurface.create_from_png(imagedir + "switch1-48x48.png"),
329                                         }
330
331
332
333                 self.e_goweb.add(self.label)
334                 self.e_goweb.set_events(gtk.gdk.BUTTON_RELEASE_MASK)
335                 self.e_goweb.connect("button-release-event", self.view_comic)
336
337                 self.e_open.add(self.comic_image)
338
339                 # self.e_switch.add(self.switch)
340                 self.e_switch.set_events(gtk.gdk.BUTTON_PRESS_MASK|gtk.gdk.BUTTON_RELEASE_MASK|gtk.gdk.LEAVE_NOTIFY)
341                 self.e_switch.connect("button-press-event", self.button_press)
342                 self.e_switch.connect("button-release-event", self.button_release)
343                 self.e_switch.connect("leave-notify-event", self.button_release)
344
345
346                 # self.e_next.add(self.next)
347                 self.e_next.set_events(gtk.gdk.BUTTON_PRESS_MASK|gtk.gdk.BUTTON_RELEASE_MASK|gtk.gdk.LEAVE_NOTIFY)
348                 self.e_next.connect("button-press-event", self.button_press)
349                 self.e_next.connect("button-release-event", self.button_release)
350                 self.e_next.connect("leave-notify-event", self.button_release)
351
352                 #self.e_prev.add(self.prev)
353                 self.e_prev.set_events(gtk.gdk.BUTTON_PRESS_MASK|gtk.gdk.BUTTON_RELEASE_MASK|gtk.gdk.LEAVE_NOTIFY)
354                 self.e_prev.connect("button-press-event", self.button_press)
355                 self.e_prev.connect("button-release-event", self.button_release)
356                 self.e_prev.connect("leave-notify-event", self.button_release)
357
358                 #self.e_up.add(self.up)
359                 self.e_up.set_events(gtk.gdk.BUTTON_PRESS_MASK|gtk.gdk.BUTTON_RELEASE_MASK|gtk.gdk.LEAVE_NOTIFY)
360                 self.e_up.connect("button-press-event", self.button_press)
361                 self.e_up.connect("button-release-event", self.button_release)
362                 self.e_up.connect("leave-notify-event", self.button_release)
363                 
364
365                 #self.e_down.add(self.down)
366                 self.e_down.set_events(gtk.gdk.BUTTON_PRESS_MASK|gtk.gdk.BUTTON_RELEASE_MASK|gtk.gdk.LEAVE_NOTIFY)
367                 self.e_down.connect("button-press-event", self.button_press)
368                 self.e_down.connect("button-release-event", self.button_release)
369                 self.e_down.connect("leave-notify-event", self.button_release)
370
371                 self.vbox.pack_start(self.e_open,False,False,0)
372                 self.vbox.pack_end(self.hbox,False,False,0)
373
374                 self.hbox.pack_start(self.e_switch,False,False,0)
375                 self.hbox.pack_start(self.e_goweb,False,False,10)
376                 self.hbox.pack_end(self.e_next,False,False,0)
377                 self.hbox.pack_end(self.e_prev,False,False,0)
378                 self.hbox.pack_end(self.e_down,False,False,0)
379                 self.hbox.pack_end(self.e_up,False,False,0)
380                 self.vbox.show_all()
381                 self.add(self.vbox)
382
383         # **************** Cairo draw functions ***************
384
385         def realize(self, widget):
386                 global supports_alpha
387
388                 # To check if the display supports alpha channels, get the colormap
389                 screen = self.get_screen()
390                 colormap = screen.get_rgba_colormap()
391                 if colormap == None:
392                         print 'Your screen does not support alpha channels!'
393                         colormap = screen.get_rgb_colormap()
394                         supports_alpha = False
395                 else:
396                 #      print 'Your screen supports alpha channels!'
397                         supports_alpha = True
398
399                 # Now we have a colormap appropriate for the screen, use it
400                 self.set_colormap(colormap)
401
402                 return False
403
404         def do_expose_event(widget, event):
405                 cr = widget.window.cairo_create()
406                 widget.draw(widget.e_up, 0)
407                 widget.draw(widget.e_down, 0)
408                 widget.draw(widget.e_prev,0)
409                 widget.draw(widget.e_next, 0)
410                 widget.draw(widget.e_switch, 0)
411 #               widget.writeit(widget.e_goweb, "asdf")
412                 cr.set_operator(cairo.OPERATOR_OVER)
413                 region = gtk.gdk.region_rectangle(event.area)
414                 cr.region(region)
415                 bg_color=gtk.gdk.color_parse('#000000')
416                 if supports_alpha:
417                         cr.set_source_rgba (0.0, 0.0, 0.0, 0.5)
418                 else:
419                         cr.set_source_rgb (0.0, 0.0, 0.0)
420                         
421                 cr.fill_preserve()
422                 return False
423
424         # Function that draws a button preloaded in the images dictionary.
425         def draw(self, target, postfix):
426                 cr_e = target.window.cairo_create()
427                 cr_e.set_source_rgba(0.0, 0.0, 0.0, 0.5) # Transparent
428                 cr_e.set_operator(cairo.OPERATOR_SOURCE)
429                 cr_e.paint()
430                 cr_e.set_operator(cairo.OPERATOR_OVER)
431                 cr_e.set_source_surface(self.images[target.get_name() + str(postfix)], 0, 0)
432                 cr_e.paint()
433
434         # ********** Event handlers *************
435
436
437         # Most events happen on release, so I moved all of them into the same event handler.
438         def button_release(self, widget, event):
439                 if event.type == gtk.gdk.BUTTON_RELEASE:
440                         func = widget.get_name()
441                         print "pressed: " + func
442                         if func == 'up':
443                                 self.e_open.remove(self.comic_image)
444                                 self.imgvpos = self.imgvpos - 80
445                                 if self.imgvpos < 0:
446                                         self.imgvpos = 0
447                                 self.comic_image = self.get_resized_pixmap(self.db.get_comic(), self.imgvpos)
448                                 self.e_open.add(self.comic_image)
449                                 self.e_open.show_all()
450
451                         elif func == 'down':
452                                 self.e_open.remove(self.comic_image)
453                                 self.imgvpos = self.imgvpos + 80
454                                 self.comic_image = self.get_resized_pixmap(self.db.get_comic(), self.imgvpos)
455                                 self.e_open.add(self.comic_image)
456                                 self.e_open.show_all()
457                         
458                         elif func == 'next':
459                                 self.db.currentcomic -= 1
460                                 self.imgvpos = 0
461                                 self.e_open.remove(self.comic_image)
462                                 self.comic_image = self.get_resized_pixmap(self.db.get_comic(), self.imgvpos)
463                                 self.e_open.add(self.comic_image)
464                                 self.e_open.show_all()
465                                 self.e_goweb.remove(self.label)
466                                 titl = str(self.db.db[self.db.currentcomic]['title'])
467                                 if len(titl) > 22:
468                                         titl = titl[:19] + "..."
469                                 self.label.set_markup('<span size="12000" face="monospace"> <b>' + self.comicname + '</b> ' + str(self.db.db[self.db.currentcomic]['id']) + '\n ' + titl + '</span>')
470                                 self.e_goweb.add(self.label)
471                                 self.e_goweb.show_all()
472
473                         elif func == 'prev':
474                                 self.db.currentcomic += 1
475                                 self.imgvpos = 0
476                                 self.e_open.remove(self.comic_image)
477                                 self.comic_image = self.get_resized_pixmap(self.db.get_comic(), self.imgvpos)
478                                 self.e_open.add(self.comic_image)
479                                 self.e_open.show_all()
480                                 self.e_goweb.remove(self.label)
481                                 titl = str(self.db.db[self.db.currentcomic]['title'])
482                                 if len(titl) > 22:
483                                         titl = titl[:19] + "..."
484                                 self.label.set_markup('<span size="12000" face="monospace"> <b>' + self.comicname + '</b> ' + str(self.db.db[self.db.currentcomic]['id']) + '\n ' + titl + '</span>')
485                                 self.e_goweb.add(self.label)
486                                 self.e_goweb.show_all()
487
488                         elif func == 'switch':
489                                 self.keypointer = (self.keypointer + 1) % 3
490                                 self.imgvpos = 0
491                                 self.db = []
492                                 print "switching to " + self.keys[self.keypointer]
493                                 self.comicname = comics[self.keys[self.keypointer]]['name']
494                                 self.db = ComicDb(self.keys[self.keypointer])
495                                 self.e_goweb.remove(self.label)
496                                 titl = str(self.db.db[self.db.currentcomic]['title'])
497                                 if len(titl) > 22:
498                                         titl = titl[:19] + "..."
499                                 self.label.set_markup('<span size="12000" face="monospace"> <b>' + self.comicname + '</b> ' + str(self.db.db[self.db.currentcomic]['id']) + '\n ' + titl + '</span>')
500                                 self.e_goweb.add(self.label)
501                                 self.e_goweb.show_all()
502                                 self.e_open.remove(self.comic_image)
503                                 self.comic_image = self.get_resized_pixmap(self.db.get_comic(), self.imgvpos)
504                                 self.e_open.add(self.comic_image)
505                                 self.e_open.show_all()  
506
507                         else:
508                                 return False                    
509                 self.draw(widget, "0")
510
511         # this one only switches to pressed button image
512         def button_press(self, widget, event):
513                 if not event.type == gtk.gdk.BUTTON_PRESS:
514                         return False
515                 self.draw(widget, "1")
516
517         # this one cancels a button press when pointer is moved out from it after press.
518         def button_out(self, widget, event):
519                 if not event.type == gtk.gdk.BUTTON_PRESS:
520                         return False
521                 self.draw(widget, "0")
522
523         # no fancy cairo stuff here. simply launches url in browser.
524         def view_comic(self, widget, event):
525                 if not event.type == gtk.gdk.BUTTON_RELEASE:
526                         return False
527                 link = self.db.get_link()
528                 self.osso_rpc.rpc_run_with_defaults("osso_browser", "open_new_window", (link,))
529
530
531
532         # this function modifies the image to fit the widget and then returns it.
533
534         def get_resized_pixmap(self, filename, vpos):
535                 print "vpos: " + str(vpos)
536
537                 maxheight = 182
538
539                 pixbuf = gtk.gdk.pixbuf_new_from_file(filename)
540                 parent_buf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, pixbuf.get_has_alpha(), 8, 480, maxheight)
541                 parent_buf.fill(0xffffffff)
542                 retimg = gtk.Image()
543                 # get correct width/height
544                 new_height = 1
545                 new_width = 478
546                 new_height = int((478.0 / pixbuf.get_width()) * pixbuf.get_height())
547                 scaled_buf = pixbuf.scale_simple(new_width,new_height,gtk.gdk.INTERP_BILINEAR)
548                 print "scaled height: " + str(scaled_buf.get_height())
549                 if scaled_buf.get_height() > maxheight:
550                         if scaled_buf.get_height() - (vpos + maxheight) < 0:
551                                 vpos = scaled_buf.get_height() - maxheight
552                         scaled_buf.copy_area(0,vpos,478,maxheight,parent_buf,1,0)
553                         self.imgvpos = vpos
554                 else:
555                         tmpy = maxheight - scaled_buf.get_height()
556                         if tmpy > 0:
557                                 tmpy = tmpy / 2
558
559                         scaled_buf.copy_area(0,0,478,scaled_buf.get_height(),parent_buf,1,tmpy)
560                         self.imgvpos = 0
561                 retimg.set_from_pixbuf(parent_buf)
562                 print "vpos after fixing image: " + str(self.imgvpos)
563                 return retimg
564
565         def screen_changed(self, widget, old_screen=None):
566                 global supports_alpha
567
568                 # To check if the display supports alpha channels, get the colormap
569                 screen = self.get_screen()
570                 colormap = screen.get_rgba_colormap()
571                 if colormap == None:
572                         print 'Your screen does not support alpha channels!'
573                         colormap = screen.get_rgb_colormap()
574                         supports_alpha = False
575                 else:
576                 #      print 'Your screen supports alpha channels!'
577                         supports_alpha = True
578
579                 # Now we have a colormap appropriate for the screen, use it
580                 self.set_colormap(colormap)
581
582                 return False
583
584 # ************************* OPTIONS ********************************
585
586         def show_options(self, widget):
587                 dialog = gtk.Dialog("Comic Widget", None, gtk.DIALOG_DESTROY_WITH_PARENT)
588
589                 about_button = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL)
590                 about_button.set_text("About", "See Author, Copyright and License information")
591                 about_button.set_alignment(0,0,0,0)
592                 about_button.connect("clicked", self.show_about)
593
594                 dialog.vbox.pack_start(about_button, True, True, 0)
595
596                 dialog.show_all()
597                 dialog.run()
598                 dialog.destroy()
599
600         def show_about(self, widget):
601                 dialog = gtk.AboutDialog()
602                 dialog.set_title("About")
603                 dialog.set_name("Comic widget")
604                 dialog.set_version(APP_VERSION)
605                 dialog.set_copyright("Copyright 2010 Marcus Wikstrom")
606                 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."])
607                 # dialog.set_logo(gtk.gdk.pixbuf_new_from_file("/usr/share/touchsearch/icon.png"))
608                 # dialog.set_comments("Thanks to Benoit Hervier, Daniel Would and Brent Chiodo for some nice code to sample.")
609                 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/>.""")
610                 dialog.set_wrap_license(True)
611                 dialog.show_all()
612                 dialog.run()
613                 dialog.destroy()
614
615 hd_plugin_type = ComicHomePlugin
616
617
618 if __name__ == "__main__":
619         import gobject
620         gobject.type_register(hd_plugin_type)
621         obj = gobject.new(hd_plugin_type, plugin_id="plugin_id")
622         obj.show_all()
623         gtk.main()