1 from Screens.Screen import Screen
2 from Screens.InfoBarGenerics import InfoBarPlugins
3 from Screens.InfoBar import InfoBar
4 from Plugins.Plugin import PluginDescriptor
5 from Components.ActionMap import ActionMap
6 from Components.config import config, ConfigSubsection, ConfigSubDict, ConfigText, ConfigBoolean
7 from Components.Element import cached
8 from enigma import eTimer
9 from Components.Label import Label
10 from Components.MenuList import MenuList
11 from enigma import getDesktop, eSize,ePoint
12 from skin import applyAllAttributes, dom_skins
15 from Widget import Widget
16 from widgets import importWidgets, importSingleWidget
21 SIBbase__init__ = None
22 SIB_StartOnlyOneTime = False
23 SIB_TOGGLE_SHOW = InfoBar.toggleShow
24 SIB_SWOFF = InfoBar.hide
27 config.plugins.Widgets = ConfigSubsection()
28 config.plugins.Widgets.show_empty_positions = ConfigBoolean(default = True,descriptions = {False: _("hide"), True: _("show")})
29 config.plugins.Widgets.active_widgets = ConfigSubDict()
32 config.plugins.Widgets.active_widgets["w%i_%i"%(x,y)] = ConfigText("")
35 def Plugins(**kwargs):
36 return [PluginDescriptor(where = PluginDescriptor.WHERE_SESSIONSTART, fnc = SIBautostart)]
40 class ReplaceInfoBar():
46 boolean = property(Replace)
50 def SIBautostart(reason, **kwargs):
51 global SIBbase__init__
52 if "session" in kwargs:
53 if SIBbase__init__ is None:
54 SIBbase__init__ = InfoBarPlugins.__init__
55 InfoBarPlugins.__init__ = InfoBarPlugins__init__
56 InfoBarPlugins.switch = switch
57 InfoBarPlugins.swOff = swOff
61 def InfoBarPlugins__init__(self):
62 global SIB_StartOnlyOneTime
63 if not SIB_StartOnlyOneTime:
64 SIB_StartOnlyOneTime = True
65 self["SIBActions"] = ActionMap(["WidgetStartActions"],{"ok_but": self.switch,"exit_but": self.swOff}, -1)
66 self.SIBtimer = eTimer()
67 self.SIBtimer.callback.append(self.swOff)
68 self.SIBtimer.start(4000, True)
70 InfoBarPlugins.__init__ = InfoBarPlugins.__init__
71 InfoBarPlugins.switch = None
72 InfoBarPlugins.swOff = None
78 if InfoBar and InfoBar.instance and ReplaceInfoBar.Replace:
82 idx = config.usage.infobar_timeout.index
84 self.SIBtimer.start(idx*1000, True)
85 SIB_TOGGLE_SHOW(InfoBar.instance)
86 elif (SIB_STATE == 1):
89 SIB_SWOFF(InfoBar.instance)
90 self.session.open(WidgetDesktop)
94 SIB_SWOFF(InfoBar.instance)
99 if InfoBar and InfoBar.instance and ReplaceInfoBar.Replace:
103 SIB_SWOFF(InfoBar.instance)
105 def lookupScreenSkin(screenname):
106 for skin in dom_skins:
107 for scr in skin[1].findall("screen"):
108 if scr.get("name") == screenname:
112 def lookupWidgetConfig():
113 for skin in dom_skins:
114 for scr in skin[1].findall("widgetconfig"):
115 if scr.findall("num_widgets"):
119 def getWidgetForPosition(session,positionname):
120 #print "positionname value",config.plugins.Widgets.active_widgets[positionname].value
121 wpath = config.plugins.Widgets.active_widgets[positionname].value
125 return importSingleWidget(session,wpath)
127 class WidgetDesktop(Screen):
132 def __init__(self, session):
133 self.num_widgets_x = 3
134 self.num_widgets_y = 3
135 self.imported_widgets = []
136 self.widgets_on_position = {}
137 self.session = session
138 Screen.__init__(self, session)
140 loadSkinReal("/usr/lib/enigma2/python/Plugins/Extensions/Widgets/skin.xml")
143 cfg = lookupWidgetConfig()
145 for config in cfg.getchildren():
146 if config.tag == "num_widgets":
147 self.num_widgets_x = int(config.get("x"))
148 self.num_widgets_y = int(config.get("y"))
149 print "init screen with",self.num_widgets_x,"x",self.num_widgets_y
150 self.initBackgrounds()
153 for x in range(1,self.num_widgets_x+1):
154 for y in range(1,self.num_widgets_y+1):
155 self.positions.append("w%i_%i"%(x,y))
159 scr = lookupScreenSkin("WidgetDesktop")
161 self.original_screen = scr
162 self.original_screen_newchilds = []
163 for wname in self.positions:
164 twidget = getWidgetForPosition(session,wname)
165 if twidget is not False:
166 print "found widget for position",wname,twidget
167 twidget[1].setPositionname(wname)
168 self.importWidgetElements(twidget, wname)
169 self.importWidgetSkin(scr, twidget, wname)
170 self.imported_widgets.append(twidget)
171 self.widgets_on_position[wname] = twidget
173 print "position is empty",wname
175 self["actions"] = ActionMap(["WidgetDesktopActions"],{
177 "cancel": self.close,
179 "down": self.key_down,
180 "left": self.key_left,
181 "right": self.key_right,
182 "menu": self.key_menu,
183 "info": self.key_info,
185 self.onLayoutFinish.append(self.restoreSkin)
186 self.onLayoutFinish.append(self._onLoadFinished)
187 self.onClose.append(self._onClose )
189 def importWidgetElements(self,widget,wname):
190 for elementname in widget[1].elements.keys():
191 self[wname+"_e_"+elementname] = widget[1].elements[elementname]
193 def importWidgetSkin(self,scr,widget,wname):
194 x,y = self.getPositionOfBackgroundElement(scr,wname)
195 for screenelement in widget[2].find("desktopwidget").getchildren():
196 element = self.patchWidgetElementSkinPosition(screenelement,x,y,wname)
197 self.original_screen_newchilds.append(element)
200 def getPositionOfBackgroundElement(self,screen,elementname):
201 for w in screen.getchildren():
202 if w.get("name") == elementname:
203 xy = w.get("position").split(",")
204 return int(xy[0]),int(xy[1])
207 def restoreSkin(self):
208 for old in self.original_screen_newchilds:
209 self.original_screen.remove(old)
212 def initBackgrounds(self):
213 for x in range(1,self.num_widgets_x+1):
214 for y in range(1,self.num_widgets_y+1):
215 wname = "w%i_%i"%(x,y)
216 self[wname] = Label()
217 if not config.plugins.Widgets.show_empty_positions.value:
219 self[wname+"_h"] = Label(_("press menu to edit"))
220 self[wname+"_h"].hide()
222 def patchWidgetElementSkinPosition(self,element,x1,y1,wname):
223 pos1= element.get("position").split(",")
226 pos2 = "%i,%i"%(x2,y2)
227 element.set("position",pos2)
228 if element.get("name") is not None:
229 element.set("name",wname+"_e_"+element.get("name"))
232 def _onLoadFinished(self):
233 for w in self.imported_widgets:
235 w[1].onLoadFinished(self)
237 print "Exception in onLoadFinished of widget",w[0],e
240 for w in self.imported_widgets:
242 # notify the widget that it will be closed
245 #deleting the instance of the widget
248 print "Exception in onClose of widget",w[0],e
252 self.selection_x -= 1
253 if self.selection_x <= 0:
254 self.selection_x = self.num_widgets_x
259 self.selection_x += 1
260 if self.selection_x>self.num_widgets_x:
266 self.selection_y -= 1
267 if self.selection_y <= 0:
268 self.selection_y = self.num_widgets_y
273 self.selection_y += 1
274 if self.selection_y>self.num_widgets_y:
278 def selectionShow(self):
279 if self.selection_x==0:
281 if self.selection_y==0:
283 if self.selection_x in range(1,self.num_widgets_x+1) and self.selection_y in range(1,self.num_widgets_y+1):
284 self["w%i_%i_h"%(self.selection_x,self.selection_y)].show()
286 def selectionHide(self):
287 if self.selection_x in range(1,self.num_widgets_x+1) and self.selection_y in range(1,self.num_widgets_y+1):
288 self["w%i_%i_h"%(self.selection_x,self.selection_y)].hide()
291 if self.selection_x != 0 and self.selection_y != 0:
292 print "menukey on position",self.selection_x,self.selection_y
293 w = self.getWidgetOnPosition(self.selection_x,self.selection_y)
295 self.session.open(WidgetPositionConfigScreen,self.selection_x,self.selection_y,widget=w)
297 self.session.open(WidgetPositionConfigScreen,self.selection_x,self.selection_y)
300 if self.selection_x != 0 and self.selection_y != 0:
301 w = self.getWidgetOnPosition(self.selection_x,self.selection_y)
303 print "infokey on widget",w[0]
306 def getWidgetOnPosition(self,x,y):
308 return self.widgets_on_position["w%i_%i"%(self.selection_x,self.selection_y)]
313 class WidgetPositionConfigScreen(Screen):
314 def __init__(self, session,x,y,widget=False):
315 self.session = session
319 Screen.__init__(self, session)
322 if widget is not False:
323 list.append((_("clear position"),"remove"))
325 for widget in importWidgets(session):
326 list.append((widget[1].name,widget))
328 self["list"] = MenuList(list)
329 self["preview"] = Label("")
330 self["description"] = Label("")
331 self["version"] = Label("")
332 self["author"] = Label("")
333 self["homepage"] = Label("")
334 self["key_green"] = Label(_("ok"))
335 self["key_red"] = Label(_("cancel"))
338 self["actions"] = ActionMap(["WidgetPositionConfigScreenActions"],{
340 "cancel": self.close,
348 if self["list"].getCurrent() is not None:
349 self.setValue(self["list"].getCurrent()[1][3])
360 self["list"].pageUp()
364 self["list"].pageDown()
368 if self["list"].getCurrent() is not None:
369 value = self["list"].getCurrent()[1]
371 if value == "remove":
372 self["description"].setText("remove current widget")
373 self["version"].setText("")
374 self["author"].setText("")
375 self["homepage"].setText("")
377 self["description"].setText(value[1].description)
378 self["version"].setText(value[1].version)
379 self["author"].setText(value[1].author)
380 self["homepage"].setText(value[1].homepage)
384 def setValue(self,value):
385 config.plugins.Widgets.active_widgets["w%i_%i"%(self.position_x,self.position_y)].value = value
386 config.plugins.Widgets.active_widgets["w%i_%i"%(self.position_x,self.position_y)].save()
389 ############################################################################
390 # Copyright (C) 2008 by Volker Christian #
391 # Volker.Christian@fh-hagenberg.at #
392 from skin import loadSkin
396 def loadSkinReal(skinPath):
397 if os.path.exists(skinPath):
398 print "[Widgets] Loading skin ", skinPath
399 for skin in dom_skins:
402 if skin[0] == skinPath.replace("skin.xml",""):
403 dom_skins.remove(skin)
407 def loadPluginSkin(pluginPath):
408 pass #loadSkinReal(pluginPath + "/skin.xml")
410 ############################################################################