17 socket.setdefaulttimeout(10)
19 supports_alpha = False
22 # sys.stdout = open('/home/user/.comic-widget/output_log.txt', 'a')
23 # sys.stderr = open('/home/user/.comic-widget/error_log.txt', 'a')
24 # print "Start logging!"
26 # constants. dbfile is the location of the csv
27 # comiccache is the location of the images
28 APP_VERSION = "0.4.0-1"
30 basedbdir = "/opt/comic-widget/db/"
31 imagedir = "/opt/comic-widget/images/"
32 dbdir = "/home/user/.comic-widget/"
33 activecomics = dbdir + "activecomics.cfg"
34 comiccache = "/home/user/MyDocs/.comics/"
35 defaultcomics = ['xkcd','wulff','sinfest']
37 "9_chickweed_lanecomicscom":{"name":"9 Chickweed Lane","link":"http://comics.com/9_chickweed_lane/","start":"2010-02-01","dbfile":dbdir + "comicdb.9chickweedlane.csv"},
38 "agnescomicscom":{"name":"Agnes","link":"http://comics.com/agnes/","start":"2010-02-01","dbfile":dbdir + "comicdb.agnes.csv"},
39 "andy_cappcomicscom":{"name":"Andy Capp","link":"http://comics.com/andy_capp/","start":"2010-02-01","dbfile":dbdir + "comicdb.andycapp.csv"},
40 "alley_oopcomicscom":{"name":"Alley Oop","link":"http://comics.com/alley_oop/","start":"2010-02-01","dbfile":dbdir + "comicdb.alleyoop.csv"},
41 "arlonjaniscomicscom":{"name":"Arlo and Janis","link":'http://comics.com/arlo&janis/',"start":"2010-02-01","dbfile":dbdir + "comicdb.arlonjanis.csv"},
42 "bccomicscom":{"name":"B.C.","link":"http://comics.com/bc/","start":"2010-02-01","dbfile":dbdir + "comicdb.bc.csv"},
43 "ballard_streetcomicscom":{"name":"Ballard Street","link":"http://comics.com/ballard_street/","start":"2010-02-01","dbfile":dbdir + "comicdb.ballardstreet.csv"},
44 "bencomicscom":{"name":"Ben","link":'http://comics.com/ben/',"start":"2010-02-01","dbfile":dbdir + "comicdb.ben.csv"},
45 "bettycomicscom":{"name":"Betty","link":"http://comics.com/betty/","start":"2010-02-01","dbfile":dbdir + "comicdb.betty.csv"},
46 "big_natecomicscom":{"name":"Big Nate","link":"http://comics.com/big_nate/","start":"2010-02-01","dbfile":dbdir + "comicdb.bignate.csv"},
47 "brevitycomicscom":{"name":"Brevity","link":"http://comics.com/brevity/","start":"2010-02-01","dbfile":dbdir + "comicdb.brevity.csv"},
48 "candorvillecomicscom":{"name":"Candorville","link":"http://comics.com/candorville/","start":"2010-02-01","dbfile":dbdir + "comicdb.candorville.csv"},
49 "cheap_thrillscomicscom":{"name":"Cheap Thrills","link":"http://comics.com/cheap_thrills/","start":"2010-02-01","dbfile":dbdir + "comicdb.cheapthrills.csv"},
50 "committedcomicscom":{"name":"Committed","link":"http://comics.com/committed/","start":"2010-02-01","dbfile":dbdir + "comicdb.committed.csv"},
51 "cownboycomicscom":{"name":"Cow and Boy","link":'http://comics.com/cow&boy/',"start":"2010-02-01","dbfile":dbdir + "comicdb.cownboy.csv"},
52 "cyanide":{"name":"Cyanide and Happiness","link":"http://explosm.com/","start":"1920","dbfile":dbdir + "comicdb.cyanide.csv"},
53 "daddyshomecomicscom":{"name":"Daddy's Home","link":"http://comics.com/daddys_home/","start":"2010-02-01","dbfile":dbdir + "comicdb.daddyshome.csv"},
54 "dilbert":{"name":"Dilbert","link":"http://dilbert.com/","start":"2010-01-01","dbfile":dbdir + "comicdb.dilbert.csv"},
55 "dog_eat_dougcomicscom":{"name":"Dog eat Doug","link":"http://comics.com/dog_eat_doug/","start":"2010-02-01","dbfile":dbdir + "comicdb.dogeatdoug.csv"},
56 "drabblecomicscom":{"name":"Drabble","link":"http://comics.com/drabble/","start":"2010-02-01","dbfile":dbdir + "comicdb.drabble.csv"},
57 "f_minuscomicscom":{"name":"F Minus","link":"http://comics.com/f_minus/","start":"2010-02-01","dbfile":dbdir + "comicdb.f_minus.csv"},
58 "family_treecomicscom":{"name":"Family Tree","link":"http://comics.com/family_tree/","start":"2010-02-01","dbfile":dbdir + "comicdb.familytree.csv"},
59 "farcuscomicscom":{"name":"Farcus","link":'http://comics.com/farcus/',"start":"2010-02-01","dbfile":dbdir + "comicdb.farcus.csv"},
60 "fat_catscomicscom":{"name":"Fat Cats","link":'http://comics.com/fat_cats_classics/',"start":"2010-02-01","dbfile":dbdir + "comicdb.fatcats.csv"},
61 "ferdnandcomicscom":{"name":"Ferd'nand","link":'http://comics.com/ferdnand/',"start":"2010-02-01","dbfile":dbdir + "comicdb.ferdnand.csv"},
62 "flight_deckcomicscom":{"name":"Flight_Deck","link":'http://comics.com/flight_deck/',"start":"2010-02-01","dbfile":dbdir + "comicdb.flightdeck.csv"},
63 "flonfriendscomicscom":{"name":"Flo and Friends","link":'http://comics.com/flo&friends/',"start":"2010-02-01","dbfile":dbdir + "comicdb.flonfriends.csv"},
64 "fort_knoxcomicscom":{"name":"Fort Knox","link":'http://comics.com/fort_knox/',"start":"2010-02-01","dbfile":dbdir + "comicdb.fortknox.csv"},
65 "franknernestcomicscom":{"name":"Frank and Ernest","link":'http://comics.com/frank&ernest/',"start":"2010-02-01","dbfile":dbdir + "comicdb.franknernest.csv"},
66 "frazzcomicscom":{"name":"Frazz","link":"http://comics.com/frazz/","start":"2010-02-01","dbfile":dbdir + "comicdb.frazz.csv"},
67 "free_rangecomicscom":{"name":"Free Range","link":'http://comics.com/free_range/',"start":"2010-02-01","dbfile":dbdir + "comicdb.freerange.csv"},
68 "geechcomicscom":{"name":"Geech","link":'http://comics.com/geech_classics/',"start":"2010-02-01","dbfile":dbdir + "comicdb.geech.csv"},
69 "getfuzzycomicscom":{"name":"Get Fuzzy","link":"http://comics.com/get_fuzzy/","start":"2010-02-01","dbfile":dbdir + "comicdb.getfuzzy.csv"},
70 "girlsnsportscomicscom":{"name":"Girls and Sports","link":'http://comics.com/girls&sports/',"start":"2010-02-01","dbfile":dbdir + "comicdb.gitlsnsports.csv"},
71 "graffiticomicscom":{"name":"Graffiti","link":'http://comics.com/graffiti/',"start":"2010-02-01","dbfile":dbdir + "comicdb.graffiti.csv"},
72 "grand_avenuecomicscom":{"name":"Grand Avenue","link":'http://comics.com/grand_avenue/',"start":"2010-02-01","dbfile":dbdir + "comicdb.grandavenue.csv"},
73 "heathcliffcomicscom":{"name":"Heathcliff","link":'http://comics.com/heathcliff/',"start":"2010-02-01","dbfile":dbdir + "comicdb.heathcliff.csv"},
74 "herb_and_jamaalcomicscom":{"name":"Herb and Jamaal","link":'http://comics.com/herb_and_jamaal/',"start":"2010-02-01","dbfile":dbdir + "comicdb.herbandjamaal.csv"},
75 "hermancomicscom":{"name":"Herman","link":'http://comics.com/herman/',"start":"2010-02-01","dbfile":dbdir + "comicdb.herman.csv"},
76 "home_and_awaycomicscom":{"name":"Home and Away","link":'http://comics.com/home_and_away/',"start":"2010-02-01","dbfile":dbdir + "comicdb.homeandaway.csv"},
77 "its_all_about_youcomicscom":{"name":"It's All About You","link":'http://comics.com/its_all_about_you/',"start":"2010-02-01","dbfile":dbdir + "comicdb.itsallaboutyou.csv"},
78 "janes_worldcomicscom":{"name":"Jane's World","link":'http://comics.com/janes_world/',"start":"2010-02-01","dbfile":dbdir + "comicdb.janesworld.csv"},
79 "jump_startcomicscom":{"name":"Jump Start","link":'http://comics.com/jump_start/',"start":"2010-02-01","dbfile":dbdir + "comicdb.jumpstart.csv"},
80 "kit_n_carlylecomicscom":{"name":"Kit 'n' Carlyle","link":'http://comics.com/kit_n_carlyle/',"start":"2010-02-01","dbfile":dbdir + "comicdb.kitncarlyle.csv"},
81 "lil_abnercomicscom":{"name":"Li'l Abner","link":'http://comics.com/lil_abner_classics/',"start":"2010-02-01","dbfile":dbdir + "comicdb.lilabner.csv"},
82 "liberty_meadowscomicscom":{"name":"Liberty Meadows","link":'http://comics.com/liberty_meadows/',"start":"2010-02-01","dbfile":dbdir + "comicdb.libertymeadows.csv"},
83 "little_dog_lostcomicscom":{"name":"Little Dog Lost","link":'http://comics.com/little_dog_lost/',"start":"2010-02-01","dbfile":dbdir + "comicdb.littledoglost.csv"},
84 "lolacomicscom":{"name":"Lola","link":'http://comics.com/lola/',"start":"2010-02-01","dbfile":dbdir + "comicdb.lola.csv"},
85 "luanncomicscom":{"name":"Luann","link":'http://comics.com/luann/',"start":"2010-02-01","dbfile":dbdir + "comicdb.luann.csv"},
86 "marmadukecomicscom":{"name":"Marmaduke","link":'http://comics.com/marmaduke/',"start":"2010-02-01","dbfile":dbdir + "comicdb.marmaduke.csv"},
87 "megcomicscom":{"name":"Meg","link":'http://comics.com/meg_classics/',"start":"2010-02-01","dbfile":dbdir + "comicdb.meg.csv"},
88 "minimum_securitycomicscom":{"name":"Minimum Security","link":'http://comics.com/minimum_security/',"start":"2010-02-01","dbfile":dbdir + "comicdb.minimumsecurity.csv"},
89 "moderately_confusedcomicscom":{"name":"Moderately Confused","link":'http://comics.com/moderately_confused/',"start":"2010-02-01","dbfile":dbdir + "comicdb.moderatelyconfused.csv"},
90 "mommacomicscom":{"name":"Momma","link":'http://comics.com/momma/',"start":"2010-02-01","dbfile":dbdir + "comicdb.momma.csv"},
91 "motleycomicscom":{"name":"Motley","link":'http://comics.com/motley_classics/',"start":"2010-02-01","dbfile":dbdir + "comicdb.motley.csv"},
92 "nancycomicscom":{"name":"Nancy","link":'http://comics.com/nancy/',"start":"2010-02-01","dbfile":dbdir + "comicdb.nancy.csv"},
93 "natural_selectioncomicscom":{"name":"Natural Selection","link":'http://comics.com/natural_selection/',"start":"2010-02-01","dbfile":dbdir + "comicdb.naturalselection.csv"},
94 "nest_headscomicscom":{"name":"Nest Heads","link":'http://comics.com/nest_heads/',"start":"2010-02-01","dbfile":dbdir + "comicdb.nestheads.csv"},
95 "off_the_markcomicscom":{"name":"Off the mark","link":"http://comics.com/off_the_mark/","start":"2010-02-01","dbfile":dbdir + "comicdb.offthemark.csv"},
96 "on_a_claire_daycomicscom":{"name":"On A Claire Day","link":'http://comics.com/on_a_claire_day/',"start":"2010-02-01","dbfile":dbdir + "comicdb.onaclaireday.csv"},
97 "one_big_happycomicscom":{"name":"One Big Happy","link":'http://comics.com/one_big_happy_classics/',"start":"2010-02-01","dbfile":dbdir + "comicdb.onebighappy.csv"},
98 "over_the_hedgecomicscom":{"name":"Over the Hedge","link":'http://comics.com/over_the_hedge/',"start":"2010-02-01","dbfile":dbdir + "comicdb.overthehedge.csv"},
99 "pc_and_pixelcomicscom":{"name":"PC and Pixel","link":'http://comics.com/pc_and_pixel/',"start":"2010-02-01","dbfile":dbdir + "comicdb.pcandpixel.csv"},
100 "peanutscomicscom":{"name":"Peanuts","link":"http://comics.com/peanuts/","start":"2010-02-01","dbfile":dbdir + "comicdb.peanuts.csv"},
101 "pearls_before_swinecomicscom":{"name":"Pearls Before Swine","link":'http://comics.com/pearls_before_swine/',"start":"2010-02-01","dbfile":dbdir + "comicdb.pearlsbeforeswine.csv"},
102 "phd":{"name":"PHD Comics","link":"http://www.phdcomics.com/","start":1240,"dbfile":dbdir + "comicdb.phd.csv"},
103 "picklescomicscom":{"name":"Pickles","link":'http://comics.com/pickles/',"start":"2010-02-01","dbfile":dbdir + "comicdb.pickles.csv"},
104 "prickly_citycomicscom":{"name":"Prickly City","link":'http://comics.com/prickly_city/',"start":"2010-02-01","dbfile":dbdir + "comicdb.pricklycity.csv"},
105 "raising_duncancomicscom":{"name":"Raising Duncan","link":'http://comics.com/raising_duncan_classics/',"start":"2010-02-01","dbfile":dbdir + "comicdb.raisingduncan.csv"},
106 "reality_checkcomicscom":{"name":"Reality Check","link":'http://comics.com/reality_check/',"start":"2010-02-01","dbfile":dbdir + "comicdb.realitycheck.csv"},
107 "rednrovercomicscom":{"name":"Red and Rover","link":'http://comics.com/red&rover/',"start":"2010-02-01","dbfile":dbdir + "comicdb.rednrover.csv"},
108 "rip_haywirecomicscom":{"name":"Rip Haywire","link":'http://comics.com/rip_haywire/',"start":"2010-02-01","dbfile":dbdir + "comicdb.riphaywire.csv"},
109 "ripleys_believe_it_or_notcomicscom":{"name":"Ripley's Believe it or not","link":'http://comics.com/ripleys_believe_it_or_not/',"start":"2010-02-01","dbfile":dbdir + "comicdb.ripleysbelieveitornot.csv"},
110 "rose_is_rosecomicscom":{"name":"Rose Is Rose","link":'http://comics.com/rose_is_rose/',"start":"2010-02-01","dbfile":dbdir + "comicdb.roseisrose.csv"},
111 "rubescomicscom":{"name":"Rubes","link":'http://comics.com/rubes/',"start":"2010-02-01","dbfile":dbdir + "comicdb.rubes.csv"},
112 "rudy_parkcomicscom":{"name":"Rudy Park","link":'http://comics.com/rudy_park/',"start":"2010-02-01","dbfile":dbdir + "comicdb.rudypark.csv"},
113 "scary_garycomicscom":{"name":"Scary Gary","link":'http://comics.com/scary_gary/',"start":"2010-02-01","dbfile":dbdir + "comicdb.scarygary.csv"},
114 "shirley_and_soncomicscom":{"name":"Shirley and Son","link":'http://comics.com/shirley_and_son_classics/',"start":"2010-02-01","dbfile":dbdir + "comicdb.shirleyandson.csv"},
115 "sinfest":{"name":"Sinfest","link":"http://sinfest.com/","start":3400,"dbfile":dbdir + "comicdb.sinfest.csv"},
116 "soup_to_nutzcomicscom":{"name":"Soup to Nutz","link":'http://comics.com/soup_to_nutz/',"start":"2010-02-01","dbfile":dbdir + "comicdb.souptonutz.csv"},
117 "speed_bumpcomicscom":{"name":"Speed Bump","link":'http://comics.com/speed_bump/',"start":"2010-02-01","dbfile":dbdir + "comicdb.speedbump.csv"},
118 "spot_the_frogcomicscom":{"name":"Spot the Frog","link":'http://comics.com/spot_the_frog/',"start":"2010-02-01","dbfile":dbdir + "comicdb.spotthefrog.csv"},
119 "state_of_the_unioncomicscom":{"name":"State of the Union","link":'http://comics.com/state_of_the_union/',"start":"2010-02-01","dbfile":dbdir + "comicdb.stateoftheunion.csv"},
120 "strange_brewcomicscom":{"name":"Strange Brew","link":'http://comics.com/strange_brew/',"start":"2010-02-01","dbfile":dbdir + "comicdb.strangebrew.csv"},
121 "tarzancomicscom":{"name":"Tarzan","link":'http://comics.com/tarzan_classics/',"start":"2010-02-01","dbfile":dbdir + "comicdb.tarzan.csv"},
122 "thats_lifecomicscom":{"name":"That's Life","link":'http://comics.com/thats_life/',"start":"2010-02-01","dbfile":dbdir + "comicdb.thatslife.csv"},
123 "the_barncomicscom":{"name":"The Barn","link":'http://comics.com/the_barn/',"start":"2010-02-01","dbfile":dbdir + "comicdb.the_barn.csv"},
124 "the_born_losercomicscom":{"name":"The Born Loser","link":'http://comics.com/the_born_loser/',"start":"2010-02-01","dbfile":dbdir + "comicdb.thebornloser.csv"},
125 "the_bucketscomicscom":{"name":"The Buckets","link":'http://comics.com/the_buckets/',"start":"2010-02-01","dbfile":dbdir + "comicdb.thebuckets.csv"},
126 "the_dinette_setcomicscom":{"name":"The Dinette Set","link":'http://comics.com/the_dinette_set/',"start":"2010-02-01","dbfile":dbdir + "comicdb.thedinetteset.csv"},
127 "the_grizzwellscomicscom":{"name":"The Grizzwells","link":'http://comics.com/the_grizzwells/',"start":"2010-02-01","dbfile":dbdir + "comicdb.thegrizzwells.csv"},
128 "the_humble_stumblecomicscom":{"name":"The Humble Stumble","link":'http://comics.com/the_humble_stumble/',"start":"2010-02-01","dbfile":dbdir + "comicdb.thehumblestumble.csv"},
129 "the_knight_lifecomicscom":{"name":"The Knight Life","link":'http://comics.com/the_knight_life/',"start":"2010-02-01","dbfile":dbdir + "comicdb.theknightlife.csv"},
130 "the_meaning_of_lilacomicscom":{"name":"The Meaning of Lila","link":'http://comics.com/the_meaning_of_lila/',"start":"2010-02-01","dbfile":dbdir + "comicdb.themeaningoflila.csv"},
131 "the_other_coastcomicscom":{"name":"The Other Coast","link":'http://comics.com/the_other_coast/',"start":"2010-02-01","dbfile":dbdir + "comicdb.theothercoast.csv"},
132 "the_sunshine_clubcomicscom":{"name":"the Sunshine Club","link":'http://comics.com/the_sunshine_club/',"start":"2010-02-01","dbfile":dbdir + "comicdb.thesunshineclub.csv"},
133 "unstrange_phenomenacomicscom":{"name":"Unstrange Phenomena","link":'http://comics.com/unstrange_phenomena/',"start":"2010-02-01","dbfile":dbdir + "comicdb.unstrangephenomena.csv"},
134 "watch_your_headcomicscom":{"name":"Watch Your Head","link":'http://comics.com/watch_your_head/',"start":"2010-02-01","dbfile":dbdir + "comicdb.watchyourhead.csv"},
135 "wizard_of_idcomicscom":{"name":"Wizard of Id","link":'http://comics.com/wizard_of_id/',"start":"2010-02-01","dbfile":dbdir + "comicdb.wizardofid.csv"},
136 "working_dazecomicscom":{"name":"Working Daze","link":'http://comics.com/working_daze/',"start":"2010-02-01","dbfile":dbdir + "comicdb.workingdaze.csv"},
137 "working_it_outcomicscom":{"name":"Working It Out","link":'http://comics.com/working_it_out/',"start":"2010-02-01","dbfile":dbdir + "comicdb.workingitout.csv"},
138 "wulff":{"name":"Wulffmorgenthaler","link":"http://wulffmorgenthaler.com/","start":"edd3411b-96ca-4d93-bd5f-0cf1deb67c8a","dbfile":dbdir + "comicdb.wulff.csv"},
139 "xkcd":{"name":"xkcd","link":"http://xkcd.org/","start":666,"dbfile":dbdir + "comicdb.xkcd.csv"},
140 "zack_hillcomicscom":{"name":"Zack Hill","link":'http://comics.com/zack_hill/',"start":"2010-02-01","dbfile":dbdir + "comicdb.zackhill.csv"},
145 defaults = {'width':480,'height':230}
146 #defaults = {'width':480,'height':240}
147 sizefile = "/home/user/.comic-widget/size.cfg"
152 # handling of the comics
154 def __init__(self, comic):
156 self.start = comics[self.comic]["start"]
157 self.dbfile = comics[self.comic]["dbfile"]
159 #if db file exist, read it
160 # if os.path.isfile(self.dbfile) == True:
161 # dbf = open(self.dbfile, 'r')
163 dbf = self.get_dbfile()
164 dbr = csv.DictReader(dbf)
167 self.db.insert(0,row)
169 if len(self.db) == 0:
171 self.currentcomic = 0
175 def get_dbfile(self):
176 #if db file exist, read it
177 print "fetching " + self.dbfile
178 if os.path.isfile(self.dbfile) == True:
179 print "found " + self.dbfile
180 dbf = open(self.dbfile, 'r')
184 print "file " + self.dbfile + " not found"
185 if not os.path.exists(dbdir):
186 print "path not found: " + dbdir
190 print "comic db creation failed on mkdir"
193 shutil.copyfile(basedbdir + "comicdb." + self.comic + ".csv", dbdir + "comicdb." + self.comic + ".csv")
195 print "comic db creation failed on copy"
196 print "creating new..."
197 dbf = open(self.dbfile, 'w')
198 dbf.write('comic,id,link,url,filename,title\n')
201 if os.path.isfile(self.dbfile) == True:
202 dbf = open(self.dbfile, 'r')
205 print "comic db creation failed after copy"
209 print str(self.currentcomic)
210 if self.currentcomic < 0:
211 self.currentcomic = 0
213 fetchid = self.db[self.currentcomic]['id']
215 fetchid = comics[self.comic]['start']
216 self.fetch_newer(self.comic, fetchid)
218 if len(self.db) < (self.currentcomic + 1):
220 self.currentcomic = len(self.db) - 1
222 fetchid = self.db[self.currentcomic]['id']
224 fetchid = comics[self.comic]['start']
225 self.fetch_earlier(self.comic, fetchid)
227 self.currentcomic = len(self.db) - 1
229 dbrow = self.db[self.currentcomic]
230 filename = comiccache + self.comic + "/" + dbrow['filename']
231 print filename + "\n"
233 if os.path.isfile(filename):
234 print "found, returning " + filename + "\n"
238 print filename + " not found\nretrieving " + dbrow['url'] + "\n"
239 if not os.path.exists(comiccache + self.comic + "/"):
240 print "create dir " + comiccache + self.comic + "/"
242 os.makedirs(comiccache + self.comic + "/")
245 print "comic db creation failed on mkdir"
248 urllib.urlretrieve(dbrow['url'], filename)
250 if os.path.isfile(filename):
255 def get_current_row(self):
256 return self.db[self.currentcomic]
259 print str(self.currentcomic)
260 if self.currentcomic < 0:
262 self.currentcomic = 0
263 if len(self.db) < (self.currentcomic + 1):
264 self.currentcomic -= 1
265 return self.db[self.currentcomic]['link']
269 def insert_row(self, irow):
270 dbf = open(self.dbfile, 'a')
271 dbw = csv.writer(dbf)
275 def insert_row_first(self, irow):
276 dbf = open(self.dbfile, 'w')
277 dbf.write('comic,id,link,url,filename,title\n')
278 dbw = csv.writer(dbf)
281 dbf = open(self.dbfile, 'a')
282 dbw = csv.DictWriter(dbf, ['comic','id','link','url','filename','title'])
290 # if len(self.db) < 1:
291 # self.currentcomic = -1
292 # self.fetch_latest_std(self.comic, self.start)
293 # elif self.currentcomic == 0 or self.currentcomic < 0:
294 # self.fetch_latest_std(self.comic, self.db[0]['id'])
295 # elif self.currentcomic == (len(self.db) - 1):
296 # self.fetch_earlier(self.comic, self.db[self.currentcomic]['id'])
297 dbf = open(self.dbfile, 'r')
298 dbr = csv.DictReader(dbf)
301 self.db.insert(0,row)
303 if len(self.db) == 0:
304 self.fetch_earlier(self.comic, self.start)
305 dbf = open(self.dbfile, 'r')
306 dbr = csv.DictReader(dbf)
309 self.db.insert(0,row)
314 def fetch_earlier(self, comic, earliest):
315 print "fetch before, " + comic + " earliest"
317 if comic == "cyanide" or comic == "wulff" or comic[-9:] == "comicscom":
318 print "getting get_prev_id..."
319 comicid = self.get_prev_id(comic,earliest)
321 print "already at first comic"
323 print "got " + comicid + " as the one before current..."
324 elif len(str(earliest)) == 10:
326 dt = string.split(earliest, "-")
327 d = datetime.date(int(dt[0]),int(dt[1]),int(dt[2]))
328 earlier = d - datetime.timedelta( 1 )
329 comicid = earlier.isoformat()
331 comicid = int(earliest) - 1
333 irow = self.get_irow(comic, comicid)
334 if irow and irow[0] == "skip":
335 print "problem with this one, fetching " + str(irow[2]) + " instead."
336 irow = self.get_irow(comic, irow[2])
338 if irow and len(irow) > 3:
341 print "\ninserting...\n"
342 self.insert_row_first([irow[0],irow[1],irow[2],irow[3],irow[4],irow[5]])
344 print "No comic found at " + comicid
350 def fetch_newer(self, comic, newest):
351 if comic == "cyanide" or comic == "wulff":
352 comicid = self.get_next_id(comic,newest)
354 print "already at last comic"
356 elif len(newest) == 10:
358 dt = string.split(newest, "-")
359 d = datetime.date(int(dt[0]),int(dt[1]),int(dt[2]))
360 newest = d + datetime.timedelta( 1 )
361 comicid = newest.isoformat()
363 comicid = int(newest) + 1
365 irow = self.get_irow(comic, comicid)
366 if irow and irow[0] == "skip":
367 print "problem with this one, fetching " + str(irow[1]) + " instead."
368 irow = self.get_irow(comic, irow[1])
370 if irow and len(irow) > 3:
373 print "\ninserting...\n"
374 self.insert_row([irow[0],irow[1],irow[2],irow[3],irow[4],irow[5]])
376 print "No comic found at " + str(comicid)
381 def fetch_latest_std(self, comic, latest):
382 print "fetching new after " + str(comic) + " " + str(latest)
385 if comic == 'cyanide':
386 next = self.get_next_id(comic, latest)
392 if len(str(latest)) == 10:
395 dt = string.split(latest, "-")
396 d = datetime.date(int(dt[0]),int(dt[1]),int(dt[2]))
397 newer = d + datetime.timedelta( 1 )
398 comicid = newer.isoformat()
400 comicid = int(latest) + 1
403 lasturl = self.db[0]['url']
407 irow = self.get_irow(comic, comicid)
409 print "got irow: " + str(irow)
410 if str(irow[0]) == 'skip':
411 print "skipping this one..."
414 if irow[3] == lasturl:
415 print "Looping the same, break break break!"
419 self.insert_row([irow[0],irow[1],irow[2],irow[3],irow[4],irow[5]])
425 dt = string.split(comicid, "-")
426 d = datetime.date(int(dt[0]),int(dt[1]),int(dt[2]))
427 newer = d + datetime.timedelta( 1 )
428 comicid = newer.isoformat()
439 def get_next_id(self, comic, number):
440 if comic == 'cyanide':
441 link = "http://www.explosm.net/comics/" + str(number) + "/"
442 print "link: " + link
444 f = urllib2.urlopen(link)
448 print "got hcode = " + str(hcode) + "\n"
452 # print "Cyanide & Happiness is unreliable, so we need to track next and prev"
456 splt = string.split(s, 'Previous</a> | <a href="/comics/', 1)
458 print "no 'next' found"
460 splt = string.split(splt[1], '/">Next >', 1)
462 print "no 'next' found"
465 print "got next: " + splt[0]
468 link = "http://wulffmorgenthaler.com/default.aspx?id=" + number
469 print "link: " + link
471 f = urllib2.urlopen(link)
475 print "got hcode = " + str(hcode) + "\n"
482 splt = string.split(s, '<a href="/default.aspx?id=', 1)
483 if not splt[1][36:69] == '" id="ctl00_content_Strip1_aPrev"':
484 print "no previous found"
485 if not splt[1][36:69] == '" id="ctl00_content_Strip1_aNext"':
486 print "no next found!"
489 splt = string.split(splt[1], '<a href="/default.aspx?id=', 1)
491 print "no next found! At newest comic!"
493 if not splt[1][36:69] == '" id="ctl00_content_Strip1_aNext"':
494 print "no next found!"
498 elif comic[-9:] == "comicscom":
499 link = comics[comic]['link'] + str(number) + "/"
500 print "link: " + link
502 f = urllib2.urlopen(link)
506 print "got hcode = " + str(hcode) + "\n"
512 return self.parse_comics_com(comic, s, 'next')
514 def get_prev_id(self, comic, number):
515 if comic == 'cyanide':
516 link = "http://www.explosm.net/comics/" + str(number) + "/"
517 print "link: " + link
519 f = urllib2.urlopen(link)
523 print "got hcode = " + str(hcode) + "\n"
527 print "Cyanide & Happiness is unreliable, so we need to track next and prev"
531 splt = string.split(s, 'First</a> | <a href="/comics/', 1)
533 print "no 'prev' found"
535 splt = string.split(splt[1], '/">< Previous', 1)
536 if len(splt) < 2 or len(splt[0]) > 5:
537 print "no 'next' found"
540 print "got previous: " + splt[0]
542 elif comic == 'wulff':
543 link = "http://wulffmorgenthaler.com/default.aspx?id=" + number
544 print "link: " + link
546 f = urllib2.urlopen(link)
550 print "got hcode = " + str(hcode) + "\n"
557 splt = string.split(s, '<a href="/default.aspx?id=', 1)
558 if not splt[1][36:69] == '" id="ctl00_content_Strip1_aPrev"':
561 print "no previous found"
565 elif comic[-9:] == "comicscom":
566 print "fetch prev, still in function..."
567 link = comics[comic]['link'] + str(number) + "/"
568 print "link: " + link
570 f = urllib2.urlopen(link)
574 print "got hcode = " + str(hcode) + "\n"
580 return self.parse_comics_com(comic, s, 'prev')
585 def get_irow(self, comic, number):
587 if len(str(number)) == 10:
592 print "number is now: " + str(number) + "\n"
594 link = "http://xkcd.org/" + str(number) + "/"
595 elif comic == 'sinfest':
596 link = "http://www.sinfest.net/archive_page.php?comicID=" + str(number)
597 elif comic == 'dilbert':
598 link = "http://dilbert.com/" + str(number) + "/"
600 link = "http://www.phdcomics.com/comics/archive.php?comicid=" + str(number)
601 elif comic == 'cyanide':
602 link = "http://www.explosm.net/comics/" + str(number) + "/"
603 elif comic == 'wulff':
604 link = "http://wulffmorgenthaler.com/default.aspx?id=" + str(number)
605 elif comic[-9:] == 'comicscom':
606 link = comics[comic]['link'] + str(number) + "/"
610 print "link: " + link
612 f = urllib2.urlopen(link)
616 print "got hcode = " + str(hcode) + "\n"
621 # they look like: comic,id,link,url,filename,title
622 # We already have comic, number/id and link
627 # This should be done with regex but...
628 splt = string.split(s, 'png" title="', 1)
629 splt = string.split(splt[1], '" alt="', 1)
631 splt = string.split(splt[1], "<h3>Image URL (for hotlinking/embedding): ", 1)
632 splt = string.split(splt[1], "</h3>", 1)
636 elif comic == 'sinfest':
639 splt = string.split(s, 'height="107"', 1)
640 splt = string.split(splt[1], '<img src="', 1)
641 splt = string.split(splt[1], '" alt="', 1)
644 print "Fake 404! Break break break!"
646 splt = string.split(splt[1], '" border="0" />', 1)
649 elif comic == 'dilbert':
652 splt = string.split(s, 'input type="hidden" name="PrintPath" value="', 1)
653 splt = string.split(splt[1], '" />', 1)
654 url = "http://dilbert.com" + splt[0]
656 print "Fake 404! Break break break!"
664 splt = string.split(s, '<title>PHD Comics: ', 1)
665 splt = string.split(splt[1], '</title>', 1)
667 splt = string.split(splt[1], '<td bgcolor=#FFFFFF align=center><img src=', 1)
668 splt = string.split(splt[1], ' align=top>', 1)
671 print "Fake 404! Break break break!"
674 elif comic == 'cyanide':
678 splt = string.split(s, ' First</a> | <a href="/comics/', 1)
683 splt = string.split(splt[1], '/">< ', 1)
685 print "got prev: " + prev
686 splt = string.split(s, 'Previous</a> | <a href="/comics/', 1)
691 splt = string.split(splt[1], '/">Next ></a>', 1)
692 if len(splt[0]) > 10:
696 print "got next: " + next
698 splt = string.split(s, '</tr><tr><td colspan=2>', 1)
702 splt = string.split(splt[1], ' <b>by <a href="', 1)
705 print "title wrong..."
707 splt = string.split(splt[1], 'a daily webcomic" src="http://www.explosm', 1)
709 print "a video? Try skipping"
710 return ['skip',next,prev]
712 splt = string.split(splt[1], '">', 1)
713 url = "http://www.explosm" + splt[0]
714 splt2 = string.rsplit(url, "/", 1)
716 irow = [comic,number,link,url,filename,title,next,prev]
718 elif comic == 'wulff':
722 # <img src="pics/dates/month/2.gif" alt="" />
723 # <img src="pics/dates/day/4.gif" alt="" />
724 # <img src="pics/dates/komma.gif" alt="" />
725 # <img src="pics/dates/year/2010.gif" alt="" />
726 splt = string.split(s, '<img src="pics/dates/month/', 1)
727 if not splt[1][1:2] == ".":
730 title = "0" + splt[1][:1]
731 splt = string.split(splt[1], '<img src="pics/dates/day/', 1)
732 if not splt[1][1:2] == ".":
733 title = title + "-" + splt[1][:2]
735 title = title + "-0" + splt[1][:1]
736 splt = string.split(splt[1], '<img src="pics/dates/year/', 1)
737 title = splt[1][:4] + "-" + title
739 splt = string.split(splt[1], 'id="ctl00_content_Strip1_imgStrip" class="strip" src="striphandler.ashx?stripid=', 1)
740 number = splt[1][:36]
741 url = "http://wulffmorgenthaler.com/striphandler.ashx?stripid=" + number
742 filename = number + ".gif"
743 irow = [comic,number,link,url,filename,title]
745 elif comic[-9:] == 'comicscom':
746 url = self.parse_comics_com(comic, f.read(), 'url')
750 splt2 = string.rsplit(url, "/", 1)
753 if filename == self.db[0]['filename']:
754 print "already exists! Break break break!"
758 irow = [comic,number,link,url,filename,title]
762 def parse_comics_com(self, comicname, source, get_what):
763 # rel="{StripID:309486, ComicID:36, Type:'Comic', DateStrip:'2010-02-06', URL_Comic: 'girls&sports', Link_Previous: '/girls&sports/2010-02-05/', Link_Next: '/girls&sports/2010-02-07/'}"
764 if get_what == "url":
765 splt = string.split(source, 'StripID:', 1)
766 splt = string.split(splt[1], ', ComicID:', 1)
767 url = "http://c0389161.cdn.cloudfiles.rackspacecloud.com/dyn/str_strip/" + splt[0] + ".full.gif"
769 elif get_what == "next":
770 splt = string.split(source, "Link_Next: '", 1)
771 splt = string.split(splt[1], "'", 1)
772 splt = string.split(splt[0], "/")
778 elif get_what == "prev":
779 print "getting comics com prev: " + comicname
780 splt = string.split(source, "Link_Previous: '", 1)
781 splt = string.split(splt[1], "'", 1)
782 splt = string.split(splt[0], "/")
786 if len(splt[2]) == 10:
795 class ComicHomePlugin(hildondesktop.HomePluginItem):
796 # __gtype_name__ = 'ComicHomePlugin'
798 hildondesktop.HomePluginItem.__init__(self)
799 global supports_alpha
800 self.set_settings(True)
801 self.active_comics = self.get_active_comics()
802 self.sizes = self.get_size_settings()
803 self.new_width = self.sizes['width']
804 self.new_height = self.sizes['height']
805 self.connect("show-settings", self.show_options)
806 self.osso_c = osso.Context("comic-widget", "0.3.0", False)
807 self.osso_rpc = osso.Rpc(self.osso_c)
809 if len(self.active_comics) < 1:
810 self.active_comics = ['xkcd']
812 self.db = ComicDb(self.active_comics[self.keypointer])
813 self.comicname = comics[self.active_comics[self.keypointer]]['name']
814 self.set_name = "comicwidget"
815 screen = self.get_screen()
816 colormap = screen.get_rgba_colormap()
818 colormap = screen.get_rgb_colormap()
819 supports_alpha = False
821 supports_alpha = True
822 self.set_colormap(colormap)
823 self.set_app_paintable(True)
825 self.set_size_request(self.sizes['width'], self.sizes['height'])
827 self.vbox = gtk.VBox()
828 self.hbox = gtk.HBox()
829 self.label = gtk.Label()
830 self.label.set_alignment(xalign = 0, yalign = 0.5)
831 self.label.set_use_markup(True)
832 self.label.set_markup(self.get_markup())
835 self.e_goweb = gtk.EventBox()
836 self.e_goweb.set_name('goweb')
837 self.e_goweb.set_size_request(self.sizes['width'] - 250, 48)
838 # e_open is the eventbox for the image. Does nothing, but it's convenient to have it.
839 # it will change to be a cairo thing when I have the time.
840 self.e_open = gtk.EventBox()
841 self.e_open.set_name('open')
842 self.e_switch = gtk.EventBox()
843 self.e_switch.set_name('switch')
844 self.e_switch.set_size_request(48, 48)
845 self.e_next = gtk.EventBox()
846 self.e_next.set_name('next')
847 self.e_next.set_size_request(48, 48)
848 self.e_prev = gtk.EventBox()
849 self.e_prev.set_name('prev')
850 self.e_prev.set_size_request(48, 48)
851 self.e_up = gtk.EventBox()
852 self.e_up.set_name('up')
853 self.e_up.set_size_request(48, 48)
854 self.e_down = gtk.EventBox()
855 self.e_down.set_name('down')
856 self.e_down.set_size_request(48, 48)
857 self.comic_image = self.get_resized_pixmap(self.db.get_comic(), self.imgvpos)
858 self.comic_image.show()
861 # Preload images into a dictionary, so that we can access them by the names of the eventboxes:
863 self.images = {'up0':cairo.ImageSurface.create_from_png(imagedir + "up0-48x48.png"),
864 'up1':cairo.ImageSurface.create_from_png(imagedir + "up1-48x48.png"),
865 'down0':cairo.ImageSurface.create_from_png(imagedir + "down0-48x48.png"),
866 'down1':cairo.ImageSurface.create_from_png(imagedir + "down1-48x48.png"),
867 'next0':cairo.ImageSurface.create_from_png(imagedir + "next0-48x48.png"),
868 'next1':cairo.ImageSurface.create_from_png(imagedir + "next1-48x48.png"),
869 'prev0':cairo.ImageSurface.create_from_png(imagedir + "prev0-48x48.png"),
870 'prev1':cairo.ImageSurface.create_from_png(imagedir + "prev1-48x48.png"),
871 'switch0':cairo.ImageSurface.create_from_png(imagedir + "switch0-48x48.png"),
872 'switch1':cairo.ImageSurface.create_from_png(imagedir + "switch1-48x48.png"),
877 self.e_goweb.add(self.label)
878 self.e_goweb.set_events(gtk.gdk.BUTTON_RELEASE_MASK)
879 self.e_goweb.connect("button-release-event", self.view_comic)
881 self.e_open.add(self.comic_image)
883 # self.e_switch.add(self.switch)
884 self.e_switch.set_events(gtk.gdk.BUTTON_PRESS_MASK|gtk.gdk.BUTTON_RELEASE_MASK|gtk.gdk.LEAVE_NOTIFY)
885 self.e_switch.connect("button-press-event", self.button_press)
886 self.e_switch.connect("button-release-event", self.button_release)
887 self.e_switch.connect("leave-notify-event", self.button_release)
890 # self.e_next.add(self.next)
891 self.e_next.set_events(gtk.gdk.BUTTON_PRESS_MASK|gtk.gdk.BUTTON_RELEASE_MASK|gtk.gdk.LEAVE_NOTIFY)
892 self.e_next.connect("button-press-event", self.button_press)
893 self.e_next.connect("button-release-event", self.button_release)
894 self.e_next.connect("leave-notify-event", self.button_release)
896 #self.e_prev.add(self.prev)
897 self.e_prev.set_events(gtk.gdk.BUTTON_PRESS_MASK|gtk.gdk.BUTTON_RELEASE_MASK|gtk.gdk.LEAVE_NOTIFY)
898 self.e_prev.connect("button-press-event", self.button_press)
899 self.e_prev.connect("button-release-event", self.button_release)
900 self.e_prev.connect("leave-notify-event", self.button_release)
902 #self.e_up.add(self.up)
903 self.e_up.set_events(gtk.gdk.BUTTON_PRESS_MASK|gtk.gdk.BUTTON_RELEASE_MASK|gtk.gdk.LEAVE_NOTIFY)
904 self.e_up.connect("button-press-event", self.button_press)
905 self.e_up.connect("button-release-event", self.button_release)
906 self.e_up.connect("leave-notify-event", self.button_release)
909 #self.e_down.add(self.down)
910 self.e_down.set_events(gtk.gdk.BUTTON_PRESS_MASK|gtk.gdk.BUTTON_RELEASE_MASK|gtk.gdk.LEAVE_NOTIFY)
911 self.e_down.connect("button-press-event", self.button_press)
912 self.e_down.connect("button-release-event", self.button_release)
913 self.e_down.connect("leave-notify-event", self.button_release)
915 self.vbox.pack_start(self.e_open,False,False,0)
916 self.vbox.pack_end(self.hbox,False,False,0)
918 self.hbox.pack_start(self.e_switch,False,False,0)
919 self.hbox.pack_start(self.e_goweb,False,False,5)
920 self.hbox.pack_end(self.e_next,False,False,0)
921 self.hbox.pack_end(self.e_prev,False,False,0)
922 self.hbox.pack_end(self.e_down,False,False,0)
923 self.hbox.pack_end(self.e_up,False,False,0)
929 # **************** Cairo draw functions ***************
931 def realize(self, widget):
932 global supports_alpha
934 # To check if the display supports alpha channels, get the colormap
935 screen = self.get_screen()
936 colormap = screen.get_rgba_colormap()
938 print 'Your screen does not support alpha channels!'
939 colormap = screen.get_rgb_colormap()
940 supports_alpha = False
942 # print 'Your screen supports alpha channels!'
943 supports_alpha = True
945 # Now we have a colormap appropriate for the screen, use it
946 self.set_colormap(colormap)
950 def do_expose_event(widget, event):
951 cr = widget.window.cairo_create()
952 widget.draw(widget.e_up, 0)
953 widget.draw(widget.e_down, 0)
954 widget.draw(widget.e_prev,0)
955 widget.draw(widget.e_next, 0)
956 widget.draw(widget.e_switch, 0)
957 # widget.writeit(widget.e_goweb, "asdf")
958 cr.set_operator(cairo.OPERATOR_OVER)
959 region = gtk.gdk.region_rectangle(event.area)
961 bg_color=gtk.gdk.color_parse('#000000')
963 cr.set_source_rgba (0.0, 0.0, 0.0, 0.5)
965 cr.set_source_rgb (0.0, 0.0, 0.0)
970 # Function that draws a button preloaded in the images dictionary.
971 def draw(self, target, postfix):
972 cr_e = target.window.cairo_create()
973 cr_e.set_source_rgba(0.0, 0.0, 0.0, 0.5) # Transparent
974 cr_e.set_operator(cairo.OPERATOR_SOURCE)
976 cr_e.set_operator(cairo.OPERATOR_OVER)
977 cr_e.set_source_surface(self.images[target.get_name() + str(postfix)], 0, 0)
980 # ********** Event handlers *************
983 # Most events happen on release, so I moved all of them into the same event handler.
984 def button_release(self, widget, event):
985 if event.type == gtk.gdk.BUTTON_RELEASE:
986 func = widget.get_name()
987 print "pressed: " + func
989 self.e_open.remove(self.comic_image)
990 self.imgvpos = self.imgvpos - ((self.sizes['height'] - 48) / 2.1)
993 self.comic_image = self.get_resized_pixmap(self.db.get_comic(), self.imgvpos)
994 self.e_open.add(self.comic_image)
995 self.e_open.show_all()
998 self.e_open.remove(self.comic_image)
999 self.imgvpos = self.imgvpos + ((self.sizes['height'] - 48) / 2.1)
1000 self.comic_image = self.get_resized_pixmap(self.db.get_comic(), self.imgvpos)
1001 self.e_open.add(self.comic_image)
1002 self.e_open.show_all()
1004 elif func == 'next':
1005 self.db.currentcomic -= 1
1007 self.e_open.remove(self.comic_image)
1008 self.comic_image = self.get_resized_pixmap(self.db.get_comic(), self.imgvpos)
1009 self.e_open.add(self.comic_image)
1010 self.e_open.show_all()
1011 self.e_goweb.remove(self.label)
1012 titl = str(self.db.db[self.db.currentcomic]['title'])
1014 titl = titl[:19] + "..."
1015 self.label.set_markup(self.get_markup())
1016 self.e_goweb.add(self.label)
1017 self.e_goweb.show_all()
1019 elif func == 'prev':
1020 self.db.currentcomic += 1
1022 self.e_open.remove(self.comic_image)
1023 self.comic_image = self.get_resized_pixmap(self.db.get_comic(), self.imgvpos)
1024 self.e_open.add(self.comic_image)
1025 self.e_open.show_all()
1026 self.e_goweb.remove(self.label)
1027 titl = str(self.db.db[self.db.currentcomic]['title'])
1029 titl = titl[:19] + "..."
1030 self.label.set_markup(self.get_markup())
1031 self.e_goweb.add(self.label)
1032 self.e_goweb.show_all()
1034 elif func == 'switch':
1035 self.active_comics = self.get_active_comics()
1038 #sys.stdout = sys.__stdout__
1040 #sys.stderr = sys.__stderr__
1041 print "active comics: " + str(self.active_comics)
1042 self.keypointer = (self.keypointer + 1) % len(self.active_comics)
1045 print "switching to " + self.active_comics[self.keypointer]
1046 self.comicname = comics[self.active_comics[self.keypointer]]['name']
1047 self.db = ComicDb(self.active_comics[self.keypointer])
1048 self.e_open.remove(self.comic_image)
1049 self.comic_image = self.get_resized_pixmap(self.db.get_comic(), self.imgvpos)
1050 self.e_goweb.remove(self.label)
1051 titl = str(self.db.db[self.db.currentcomic]['title'])
1053 titl = titl[:19] + "..."
1054 self.label.set_markup(self.get_markup())
1055 self.e_goweb.add(self.label)
1056 self.e_goweb.show_all()
1057 self.e_open.add(self.comic_image)
1058 self.e_open.show_all()
1062 self.draw(widget, "0")
1064 # this one only switches to pressed button image
1065 def button_press(self, widget, event):
1066 if not event.type == gtk.gdk.BUTTON_PRESS:
1068 self.draw(widget, "1")
1070 # this one cancels a button press when pointer is moved out from it after press.
1071 def button_out(self, widget, event):
1072 if not event.type == gtk.gdk.BUTTON_PRESS:
1074 self.draw(widget, "0")
1076 # no fancy cairo stuff here. simply launches url in browser.
1077 def view_comic(self, widget, event):
1078 if not event.type == gtk.gdk.BUTTON_RELEASE:
1080 link = self.db.get_link()
1081 self.osso_rpc.rpc_run_with_defaults("osso_browser", "open_new_window", (link,))
1085 # this function modifies the image to fit the widget and then returns it.
1087 def get_resized_pixmap(self, filename, vpos):
1088 print "vpos: " + str(vpos)
1090 width = int(self.sizes['width'])
1091 height = int(self.sizes['height'])
1092 picwidth = width - 2
1093 maxheight = height - 48
1095 pixbuf = gtk.gdk.pixbuf_new_from_file(filename)
1096 parent_buf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, pixbuf.get_has_alpha(), 8, width, maxheight)
1097 parent_buf.fill(0xffffffff)
1098 retimg = gtk.Image()
1099 # get correct width/height
1101 new_width = picwidth
1102 new_height = int((float(picwidth) / pixbuf.get_width()) * pixbuf.get_height())
1103 scaled_buf = pixbuf.scale_simple(new_width,new_height,gtk.gdk.INTERP_BILINEAR)
1104 print "scaled height: " + str(scaled_buf.get_height())
1105 if scaled_buf.get_height() > maxheight:
1106 if scaled_buf.get_height() - (vpos + maxheight) < 0:
1107 vpos = scaled_buf.get_height() - maxheight
1108 scaled_buf.copy_area(0,vpos,picwidth,maxheight,parent_buf,1,0)
1109 # parent_buf.composite(scaled_buf, 0, 0, 478, maxheight, 0, 0, 478, maxheight, gtk.gdk.INTERP_BILINEAR, 0)
1112 tmpy = maxheight - scaled_buf.get_height()
1116 scaled_buf.copy_area(0,0,picwidth,scaled_buf.get_height(),parent_buf,1,tmpy)
1118 # test = parent_buf.render_pixmap_and_mask(0)
1119 # parent_buf.add_alpha(True,chr(255),chr(255),chr(255))
1120 retimg.set_from_pixbuf(parent_buf)
1121 print retimg.get_pixel_size()
1122 print "vpos after fixing image: " + str(self.imgvpos)
1125 def screen_changed(self, widget, old_screen=None):
1126 global supports_alpha
1128 # To check if the display supports alpha channels, get the colormap
1129 screen = self.get_screen()
1130 colormap = screen.get_rgba_colormap()
1131 if colormap == None:
1132 print 'Your screen does not support alpha channels!'
1133 colormap = screen.get_rgb_colormap()
1134 supports_alpha = False
1136 # print 'Your screen supports alpha channels!'
1137 supports_alpha = True
1139 # Now we have a colormap appropriate for the screen, use it
1140 self.set_colormap(colormap)
1145 def get_active_comics(self):
1148 if os.path.isfile(activecomics) == True:
1149 print "found " + activecomics
1150 dbf = open(activecomics, 'r')
1151 dbr = csv.reader(dbf)
1160 print "file " + activecomics + " not found"
1161 if not os.path.exists(dbdir):
1162 print "path not found: " + dbdir
1166 print "settings dir creation failed. Exiting."
1169 # dbf = file(activecomics, 'w')
1171 dbf = open(activecomics, 'w')
1173 print "error storing settings"
1175 dbw = csv.writer(dbf)
1176 dbw.writerow(defaultcomics)
1182 def get_markup(self):
1183 if len(self.comicname + " " + str(self.db.db[self.db.currentcomic]['id'])) < 20:
1184 return '<span size="12000" face="arial"> <b>' + self.comicname + '</b> ' + str(self.db.db[self.db.currentcomic]['id']) + '\n ' + str(self.db.db[self.db.currentcomic]['title']) + '</span>'
1186 return '<span size="12000" face="arial"> <b>' + self.comicname + '</b>' + '\n ' + str(self.db.db[self.db.currentcomic]['title']) + '</span>'
1189 #check if settings file exists
1191 #if not, write defaults
1193 # ************************* OPTION DIALOGS ********************************
1195 def show_options(self, widget):
1196 print "loading options dialog"
1197 dialog = gtk.Dialog("Comic Widget", None, gtk.DIALOG_DESTROY_WITH_PARENT)
1199 about_button = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL)
1200 about_button.set_text("About", "See Author, Copyright and License information")
1201 about_button.set_alignment(0,0,0,0)
1202 about_button.connect("clicked", self.show_about)
1204 comics_button = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL)
1205 comics_button.set_text("Comics", "Choose which comics to view")
1206 comics_button.set_alignment(0,0,0,0)
1207 comics_button.connect("clicked", self.show_comics)
1209 # size_button = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL)
1210 # size_button.set_text("Change size", "Change the size of the widget")
1211 # size_button.set_alignment(0,0,0,0)
1212 # size_button.connect("clicked", self.show_size)
1214 print "adding buttons to dialog, starting with comics"
1215 dialog.vbox.pack_start(comics_button, True, True, 0)
1216 print "adding about button"
1217 dialog.vbox.pack_start(about_button, True, True, 0)
1218 # dialog.vbox.pack_start(size_button, True, True, 0)
1224 def show_about(self, widget):
1225 print "in about dialog"
1226 dialog = gtk.AboutDialog()
1227 dialog.set_title("About")
1228 dialog.set_name("Comic widget")
1229 dialog.set_version(APP_VERSION)
1230 dialog.set_copyright("Copyright 2010 Marcus Wikstrom")
1231 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."])
1232 dialog.set_logo(gtk.gdk.pixbuf_new_from_file("/opt/comic-widget/images/icon2-64x64.png"))
1233 dialog.set_comments("Silly rabbit, tricks are for kids.")
1234 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/>.""")
1235 dialog.set_wrap_license(True)
1240 def show_comics(self, widget, data = None):
1241 print "in comics dialog! yay!"
1242 dialog = gtk.Dialog("Choose comics", None, gtk.DIALOG_DESTROY_WITH_PARENT | gtk.DIALOG_NO_SEPARATOR)
1243 comiclist = comics.keys()
1247 self.liststore = gtk.ListStore(str,str,bool)
1248 for comicid in comiclist:
1250 for acomic in self.active_comics:
1251 if acomic == comicid:
1255 self.liststore.append(["* " + comics[comicid]['name'],comicid, active])
1257 self.liststore.append([" " + comics[comicid]['name'],comicid, active])
1258 self.treeview = hildon.GtkTreeView(gtk.HILDON_UI_MODE_EDIT)
1259 self.treeview.set_model(self.liststore)
1260 self.treeview.set_reorderable(True)
1261 tvcolumn = gtk.TreeViewColumn('Column 0')
1262 self.treeview.append_column(tvcolumn)
1263 cell = gtk.CellRendererText()
1264 tvcolumn.pack_start(cell, True)
1265 tvcolumn.add_attribute(cell, 'text', 0)
1267 ts = hildon.PannableArea()
1269 ts.set_size_request(-1, 280)
1270 ts.add(self.treeview)
1271 selection = self.treeview.get_selection()
1273 dialog.vbox.pack_start(ts,True,True,0)
1275 selection.connect("changed", self.pick_comic, comiclist)
1279 def pick_comic(self, widget, data):
1280 selected = widget.get_selected()
1281 if selected == None:
1284 print selected[0].get_value(selected[1],0) + ", " + selected[0].get_value(selected[1],1) + ", " + str(selected[0].get_value(selected[1],2))
1285 if selected[0].get_value(selected[1],2):
1286 self.remove_comic(selected[0].get_value(selected[1],1))
1287 splt = selected[0].get_value(selected[1],0)[1:]
1288 selected[0].set_value(selected[1],0," " + splt)
1289 selected[0].set_value(selected[1],2,False)
1291 self.add_comic(selected[0].get_value(selected[1],1))
1292 splt = selected[0].get_value(selected[1],0)[1:]
1293 selected[0].set_value(selected[1],0,"*" + splt)
1294 selected[0].set_value(selected[1],2,True)
1297 def add_comic(self, comicid):
1298 if os.path.isfile(activecomics) == True:
1299 print "added " + comicid + " to " + str(self.active_comics)
1301 found = self.active_comics.index(comicid)
1303 self.active_comics.append(comicid)
1304 dbf = open(activecomics, 'w')
1305 dbw = csv.writer(dbf)
1306 dbw.writerow(self.active_comics)
1309 def remove_comic(self, comicid):
1310 if os.path.isfile(activecomics) == True:
1311 print "removing " + comicid + " from " + str(self.active_comics)
1313 del self.active_comics[self.active_comics.index(comicid)]
1316 dbf = open(activecomics, 'w')
1317 dbw = csv.writer(dbf)
1318 dbw.writerow(self.active_comics)
1322 def get_size_settings(self):
1323 # defaults = {'width':480,'height':230}
1324 # options: w 798 700 600 500 480 400
1325 # options: h 420 360 310 270 240 200
1326 print "checking to see if config file is available"
1327 if os.path.isfile(sizefile) == True:
1328 print "found " + sizefile
1329 dbf = open(sizefile, 'r')
1330 dbr = csv.reader(dbf)
1335 print "empty config file"
1339 sizes = {'width':int(cfg[0]),'height':int(cfg[1])}
1340 if sizes['width'] > 798:
1341 sizes['width'] = 798
1342 if sizes['width'] < 400:
1343 sizes['width'] = 400
1344 if sizes['height'] > 420:
1345 sizes['height'] = 420
1346 if sizes['height'] < 200:
1347 sizes['height'] = 200
1354 print "no config file"
1357 hd_plugin_type = ComicHomePlugin
1360 if __name__ == "__main__":
1362 gobject.type_register(hd_plugin_type)
1363 obj = gobject.new(hd_plugin_type, plugin_id="plugin_id")