1 from enigma import loadPic,ePixmap, getDesktop
2 from Components.Pixmap import Pixmap
3 from twisted.web.client import downloadPage
4 from urllib import quote_plus
5 from os import remove as os_remove, mkdir as os_mkdir
6 from os.path import isdir as os_path_isdir, isfile as os_isfile
8 from Components.AVSwitch import AVSwitch
9 from Components.config import config
12 val = AVSwitch().getAspectRatioSetting()
29 class WebPixmap(Pixmap):
30 def __init__(self,default=None):
31 self.default = default
32 self.cachedir = "/tmp/googlemaps/"
35 def load(self,url=None):
37 tmpfile = self.cachedir+quote_plus(url)+".jpg"
38 if os_path_isdir(self.cachedir) is False:
39 print "cachedir not existing, creating it"
40 os_mkdir(self.cachedir)
41 if os_isfile(tmpfile):
42 self.tmpfile = tmpfile
43 self.onLoadFinished(None)
45 self.tmpfile = tmpfile
47 "Accept":"image/png,image/*;q=0.8,*/*;q=0.5",
48 "Accept-Language":"de",
49 "Accept-Encoding":"gzip,deflate",
50 "Accept-Charset":"ISO-8859-1,utf-8;q=0.7,*;q=0.7",
52 "Referer":"http://maps.google.de/",
53 "Cookie:": "khcookie=fzwq1BaIQeBvxLjHsDGOezbBcCBU1T_t0oZKpA; PREF=ID=a9eb9d6fbca69f5f:TM=1219251671:LM=1219251671:S=daYFLkncM3cSOKsF; NID=15=ADVC1mqIWQWyJ0Wz655SirSOMG6pXP2ocdXwdfBZX56SgYaDXNNySnaOav-6_lE8G37iWaD7aBFza-gsX-kujQeH_8WTelqP9PpaEg0A_vZ9G7r50tzRBAZ-8GUwnEfl",
54 "Connection":"keep-alive"
56 agt = "Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.0.2) Gecko/2008091620 Firefox/3.0.2"
57 downloadPage(url,self.tmpfile,headers=head,agent=agt).addCallback(self.onLoadFinished).addErrback(self.onLoadFailed)
59 if self.default is not None:
60 self.setPixmapFromFile(self.default)
62 def onLoadFinished(self,result):
63 self.setPixmapFromFile(self.tmpfile)
64 if os_isfile(self.tmpfile):
65 if config.plugins.GoogleMaps.cache_enabled.value is not True:
66 os_remove(self.tmpfile)
68 def onLoadFailed(self,error):
69 print "WebPixmap:onLoadFAILED",error
70 if self.default is not None:
71 print "showing 404",self.default
72 self.setPixmapFromFile(self.default)
73 if os_isfile(self.tmpfile):
74 os_remove(self.tmpfile)
76 def setPixmapFromFile(self,file):
77 if self.instance is not None:
78 h = self.instance.size().height()
79 w = self.instance.size().width()
84 self.pixmap = loadPic(file, w,h,aspect,resize, rotate,background)
85 if self.pixmap is not None:
86 self.instance.setPixmap(self.pixmap.__deref__())