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 getDesktop,eSize
24 from Plugins.Plugin import PluginDescriptor
25 from Screens.Screen import Screen
26 from Components.ActionMap import ActionMap
27 from Components.Label import Label
28 from Components.MenuList import MenuList
29 from Components.config import config, ConfigSubList, ConfigSubsection, ConfigInteger, ConfigYesNo, ConfigText
31 from Plugins.Extensions.GoogleMaps.KMLlib import RootFolder,KmlFolder,KmlPlace
32 from Plugins.Extensions.GoogleMaps.WebPixmap import WebPixmap
34 config.plugins.GoogleMaps = ConfigSubsection()
35 config.plugins.GoogleMaps.position = ConfigSubsection()
36 config.plugins.GoogleMaps.position.x = ConfigInteger(33)
37 config.plugins.GoogleMaps.position.y = ConfigInteger(21)
38 config.plugins.GoogleMaps.position.z = ConfigInteger(6)
41 def applySkinVars(skin,dict):
42 for key in dict.keys():
44 skin = skin.replace('{'+key+'}',dict[key])
49 class GoogleMapsMainScreen(Screen):
51 <screen position="0,0" size="{screen.size}" title="GoogleMaps" flags="wfNoBorder">
52 <widget name="bg" position="0,0" size="{screen.size}" backgroundColor="white" zPosition="0"/>
53 <widget name="pic1" position="{pixmap1.pos}" size="{pixmap.size}" zPosition="1" />
54 <widget name="pic2" position="{pixmap2.pos}" size="{pixmap.size}" zPosition="1"/>
55 <widget name="pic3" position="{pixmap3.pos}" size="{pixmap.size}" zPosition="1"/>
56 <widget name="pic4" position="{pixmap4.pos}" size="{pixmap.size}" zPosition="1"/>
57 <widget name="pic5" position="{pixmap5.pos}" size="{pixmap.size}" zPosition="1"/>
58 <widget name="pic6" position="{pixmap6.pos}" size="{pixmap.size}" zPosition="1"/>
59 <widget name="pic7" position="{pixmap7.pos}" size="{pixmap.size}" zPosition="1"/>
60 <widget name="pic8" position="{pixmap8.pos}" size="{pixmap.size}" zPosition="1"/>
61 <widget name="pic9" position="{pixmap9.pos}" size="{pixmap.size}" zPosition="1"/>
63 <widget name="infopanel" position="{infopanel.pos}" size="{infopanel.size}" zPosition="0" backgroundColor="blue"/>
64 <widget name="posx" position="{posx.pos}" size="{posx.size}" font="{font}" zPosition="1" />
65 <widget name="posy" position="{posy.pos}" size="{posy.size}" font="{font}" zPosition="1" />
66 <widget name="posz" position="{posz.pos}" size="{posz.size}" font="{font}" zPosition="1" />
67 <widget name="placeslist" position="{placeslist.pos}" size="{placeslist.size}" zPosition="1"/>
71 def __init__(self, session):
72 self.session = session
73 size_w = getDesktop(0).size().width()
74 size_h = getDesktop(0).size().height()
75 print "DESKTOPsize is",size_w,size_h
78 infopanel_width = size_w - (p_h*3)
79 infopanel_height = size_h
86 'screen.size': "%i,%i"%(size_w,size_h),
87 'pixmap.size': '%i,%i'%(p_h,p_h),
90 'pixmap2.pos': '%i,0'%(p_h),
91 'pixmap3.pos': '%i,0'%(p_h*2),
93 'pixmap4.pos': '0,%i'%(p_h),
94 'pixmap5.pos': '%i,%i'%(p_h,p_h),
95 'pixmap6.pos': '%i,%i'%(p_h*2,p_h),
97 'pixmap7.pos': '0,%i'%(p_h*2),
98 'pixmap8.pos': '%i,%i'%(p_h,p_h*2),
99 'pixmap9.pos': '%i,%i'%(p_h*2,p_h*2),
101 'infopanel.pos': '%i,0'%(p_h*3),
102 'infopanel.size': '%i,%i'%(infopanel_width,infopanel_height),
104 'posx.pos': '%i,0'%(p_h*3),
105 'posx.size': '%i,%i'%(infopanel_width,label_height),
107 'posy.pos': '%i,%i'%(p_h*3,label_height),
108 'posy.size': '%i,%i'%(infopanel_width,label_height),
110 'posz.pos': '%i,%i'%(p_h*3,label_height*2),
111 'posz.size': '%i,%i'%(infopanel_width,label_height),
113 'placeslist.pos': '%i,%i'%(p_h*3,label_height*3),
114 'placeslist.size': '%i,%i'%(infopanel_width,infopanel_height-(label_height*3)),
119 self.skin = applySkinVars(GoogleMapsMainScreen.raw_skin,self.dict)
120 Screen.__init__(self, session)
121 self["infopanel"] = Label()
122 self["posx"] = Label("")
123 self["posy"] = Label("")
124 self["posz"] = Label("")
125 self["placeslist"] = MenuList([])
128 self["pic1"] = WebPixmap()
129 self["pic2"] = WebPixmap()
130 self["pic3"] = WebPixmap()
131 self["pic4"] = WebPixmap()
132 self["pic5"] = WebPixmap()
133 self["pic6"] = WebPixmap()
134 self["pic7"] = WebPixmap()
135 self["pic8"] = WebPixmap()
136 self["pic9"] = WebPixmap()
137 self["setupActions"] = ActionMap(["OkCancelActions", "NumberActions","DirectionActions"],
139 "cancel": self.close,
152 self.onLayoutFinish.append(self.onLayoutFinished)
154 def buildMenuRoot(self):
157 for i in root.getFiles("/usr/lib/enigma2/python/Plugins/Extensions/GoogleMaps/"):
158 l = lambda name,filepath: self.openFolderRoot(name,filepath)
159 list.append((i[0],i[1],l))
160 self["placeslist"].setList(list)
162 def openFolderRoot(self,name,filepath):
163 print "openFolderRoot",name,filepath
165 folderx = root.getFolderFromFile(filepath)
167 l = lambda name,filepath: self.buildMenuRoot()
168 list.append(("..",filepath,l))
169 for folderx in folderx.getFolders():
170 l = lambda name,folder: self.openFolder(name,folder)
171 list.append(("+ "+folderx.name,folderx,l))
173 for placex in folderx.getPlacemarks():
174 l = lambda name,place: self.showPlace(name,place)
175 list.append((""+placex.name,placex,l))
177 self["placeslist"].setList(list)
179 def openFolder(self,name,foldery):
180 print "open Folder",name,foldery
182 if foldery.parent is None:
183 l = lambda name,folder: self.buildMenuRoot()
184 list.append(("..",None,l))
186 l = lambda name,folder: self.openFolder(name,folder)
187 list.append(("..",foldery.parent,l))
189 for folderx in foldery.getFolders():
190 l = lambda name,folder: self.openFolder(name,folder)
191 list.append(("+ "+folderx.name,folderx,l))
193 for placex in foldery.getPlacemarks():
194 l = lambda name,place: self.showPlace(name,place)
195 list.append((""+placex.name,placex,l))
197 self["placeslist"].setList(list)
199 def showPlace(self,name,place):
200 #print "show Place",name,place
201 x,y,z = place.getTile(self.z)
202 self.setNewXYZ(x,y,z)
204 def onLayoutFinished(self):
206 self.setNewXYZ(config.plugins.GoogleMaps.position.x.value,
207 config.plugins.GoogleMaps.position.y.value,
208 config.plugins.GoogleMaps.position.z.value)
212 listentry = self["placeslist"].getCurrent()
213 if listentry is not None:
214 if listentry[1] is not None:
215 listentry[2](listentry[0],listentry[1])
219 self.setNewXYZ(self.x-1,self.y-1,self.z)
223 self.setNewXYZ(self.x+1,self.y-1,self.z)
227 self.setNewXYZ(self.x-1,self.y+1,self.z)
231 self.setNewXYZ(self.x+1,self.y+1,self.z)
236 self.setNewXYZ(self.x,self.y-1,self.z)
240 self.setNewXYZ(self.x,self.y+1,self.z)
244 self.setNewXYZ(self.x-1,self.y,self.z)
248 self.setNewXYZ(self.x+1,self.y,self.z)
253 self.setNewXYZ(self.x*2,self.y*2+1,self.z+1)
257 self.setNewXYZ(self.x/2,self.y/2,self.z-1)
260 def setNewXYZ(self,x,y,z):
267 config.plugins.GoogleMaps.position.x.value = x
268 config.plugins.GoogleMaps.position.y.value = y
269 config.plugins.GoogleMaps.position.z.value = z
271 self["posx"].setText(_('Pos.')+" X: "+str(x))
272 self["posy"].setText(_('Pos.')+" Y: "+str(y))
273 self["posz"].setText(_('Zoom')+" : "+str(z))
275 self["pic1"].load(self.getURL(x-1,y-1,z))
276 self["pic2"].load(self.getURL(x,y-1,z))
277 self["pic3"].load(self.getURL(x+1,y-1,z))
278 self["pic4"].load(self.getURL(x-1,y,z))
279 self["pic5"].load(self.getURL(x,y,z))
280 self["pic6"].load(self.getURL(x+1,y,z))
281 self["pic7"].load(self.getURL(x-1,y+1,z))
282 self["pic8"].load(self.getURL(x,y+1,z))
283 self["pic9"].load(self.getURL(x+1,y+1,z))
285 def getURL(self,x,y,z):
286 url = "http://khm1.google.com/kh?v=32&hl=de&x=%i&y=%i&z=%i"%(x,y,z)
289 def getMapURL(self,x,y,z):
290 url = "http://mt1.google.com/mt?v=w2t.99&hl=de&x=%i&y=%i&z=%i&s=G"%(x,y,z)
293 def menu(menuid, **kwargs):
294 #starting from main menu
295 if menuid == "mainmenu":
296 return [(_("Google Maps"), main, "googlemaps", 46)]
299 def main(session,**kwargs):
300 session.openWithCallback(mainCB,GoogleMapsMainScreen)
304 config.plugins.GoogleMaps.position.x.save()
305 config.plugins.GoogleMaps.position.y.save()
306 config.plugins.GoogleMaps.position.z.save()
308 def Plugins(path,**kwargs):
309 return [PluginDescriptor(
311 description="browse google maps",
312 where = PluginDescriptor.WHERE_MENU,