1 ###############################################################################
2 # Copyright (c) 2008 Rico Schulte, 3c5x9. All rights reserved.
4 # Permission is hereby granted, free of charge, to any person obtaining a
5 # copy of this software and associated documentation files (the "Software"),
6 # to deal in the Software without restriction, including without limitation
7 # the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 # and/or sell copies of the Software, and to permit persons to whom the
9 # Software is furnished to do so, subject to the following conditions:
11 # The above copyright notice and this permission notice shall be included
12 # in all copies or substantial portions of the Software.
14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 # DEALINGS IN THE SOFTWARE.
21 ###############################################################################
23 from enigma import loadPic,ePixmap, getDesktop
24 from Components.Pixmap import Pixmap
25 from twisted.web.client import downloadPage
26 from urllib import quote_plus
27 from os import remove as os_remove, mkdir as os_mkdir
28 from os.path import isdir as os_path_isdir, isfile as os_isfile
30 from Components.AVSwitch import AVSwitch
33 val = AVSwitch().getAspectRatioSetting()
50 class WebPixmap(Pixmap):
51 def __init__(self,url=None,text=""):
53 self.default = "/usr/lib/enigma2/python/Plugins/Extensions/GoogleMaps/404.png"
54 self.cachedir = "/tmp/googlemaps/"
57 def load(self,url=None):
59 tmpfile = self.cachedir+quote_plus(url)+".jpg"
60 if os_path_isdir(self.cachedir) is False:
61 print "cachedir not existing, creating it"
62 os_mkdir(self.cachedir)
63 if os_isfile(tmpfile):
64 self.tmpfile = tmpfile
65 self.onLoadFinished(None)
67 self.tmpfile = tmpfile
69 "Accept":"image/png,image/*;q=0.8,*/*;q=0.5",
70 "Accept-Language":"de",
71 "Accept-Encoding":"gzip,deflate",
72 "Accept-Charset":"ISO-8859-1,utf-8;q=0.7,*;q=0.7",
74 "Referer":"http://maps.google.de/",
75 "Cookie:": "khcookie=fzwq1BaIQeBvxLjHsDGOezbBcCBU1T_t0oZKpA; PREF=ID=a9eb9d6fbca69f5f:TM=1219251671:LM=1219251671:S=daYFLkncM3cSOKsF; NID=15=ADVC1mqIWQWyJ0Wz655SirSOMG6pXP2ocdXwdfBZX56SgYaDXNNySnaOav-6_lE8G37iWaD7aBFza-gsX-kujQeH_8WTelqP9PpaEg0A_vZ9G7r50tzRBAZ-8GUwnEfl",
76 "Connection":"keep-alive"
78 agt = "Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.0.2) Gecko/2008091620 Firefox/3.0.2"
79 downloadPage(url,self.tmpfile,headers=head,agent=agt).addCallback(self.onLoadFinished).addErrback(self.onLoadFailed)
81 if self.default is not None:
82 self.setPixmapFromFile(self.default)
84 def onLoadFinished(self,result):
85 self.setPixmapFromFile(self.tmpfile)
86 if os_isfile(self.tmpfile):
87 os_remove(self.tmpfile)
89 def onLoadFailed(self,error):
90 print "WebPixmap:onLoadFAILED",error
91 if self.default is not None:
92 self.setPixmapFromFile(self.default)
93 if os_isfile(self.tmpfile):
94 os_remove(self.tmpfile)
96 def setPixmapFromFile(self,file):
97 if self.instance is not None:
98 h = self.instance.size().height()
99 w = self.instance.size().width()
104 self.pixmap = loadPic(file, w,h,aspect,resize, rotate,background)
105 if self.pixmap is not None:
106 self.instance.setPixmap(self.pixmap.__deref__())