ec81c2d5ef99e8942b2dd6007f28b18fa7e296a1
[enigma2.git] / screens.py
1 from components import *
2 import sys
3 from enigma import quitMainloop
4
5 import xml.dom.minidom
6 from xml.dom import EMPTY_NAMESPACE
7 from skin import elementsWithTag
8
9
10 # some screens
11 def doGlobal(screen):
12         screen["clock"] = Clock()
13
14 class Screen(dict, HTMLSkin, GUISkin):
15         """ bla """
16
17         def __init__(self, session):
18                 self.skinName = self.__class__.__name__
19                 self.session = session
20                 GUISkin.__init__(self)
21                 
22         def execBegin(self):
23 #               assert self.session == None, "a screen can only exec one per time"
24 #               self.session = session
25                 for (name, val) in self.items():
26                         val.execBegin()
27         
28         def execEnd(self):
29                 for (name, val) in self.items():
30                         val.execEnd()
31 #               assert self.session != None, "execEnd on non-execing screen!"
32 #               self.session = None
33         
34         # never call this directly - it will be called from the session!
35         def doClose(self):
36                 GUISkin.close(self)
37                 
38                 del self.session
39                 for (name, val) in self.items():
40                         print "%s -> %d" % (name, sys.getrefcount(val))
41                         del self[name]
42         
43         def close(self, retval=None):
44                 self.session.close()
45
46
47 mdom = xml.dom.minidom.parseString(
48         """
49         <menu text="Mainmenu" title="the real Mainmenu">
50                 <item text="TV-Mode">self.setModeTV()</item>
51                 <item text="Radio-Mode">self.setModeRadio()</item>
52                 <item text="File-Mode">self.setModeFile()</item>
53                 <item text="Scart">self.openDialog(ScartLoopThrough)</item>
54                 <item text="Timer"></item>
55                 <menu text="Setup">
56                         <menu text="Service Organising">
57                                 <item text="New Bouquets"></item>
58                                 <item text="Add to Bouquets"></item>
59                                 <item text="Edit Bouquets"></item>
60                         </menu>
61                         <menu text="Service Searching">
62                                 <item text="Satelliteconfig"></item>
63                                 <item text="Satfinder"></item>
64                                 <item text="Rotor Control"></item>
65                                 <item text="Edit Transponder"></item>
66                                 <item text="Automatic Scan">self.openDialog(serviceScan)</item>
67                                 <item text="Automatic 'Multisat' Scan"></item>
68                                 <item text="Manual Scan"></item>
69                         </menu>
70                         <menu text="System">
71                                 <item text="Time Date"></item>
72                                 <item text="Video Audio"></item>
73                                 <item text="UHF Modulator"></item>
74                                 <item text="Harddisk"></item>
75                                 <item text="Keyboard"></item>
76                                 <item text="OSD">self.openDialog(configOSD)</item>
77                                 <item text="Language"></item>
78                                 <item text="LCD"></item>
79                         </menu>
80                         <item text="Common Interface"></item>
81                         <item text="Parental Control"></item>
82                         <item text="Expert"></item>
83                 </menu>
84                 <item text="Games"></item>
85                 <item text="Information"></item>
86                 <menu text="Standby">
87                         <item text="PowerOff"></item>
88                         <item text="Restart"></item>
89                         <item text="Standby"></item>
90                         <item text="Sleep Timer">self.goSetup()</item>
91                 </menu>
92                 <item text="Standby debug">quitMainloop()</item>
93         </menu>""")
94
95 def getText(nodelist):
96         rc = ""
97         for node in nodelist:
98                 if node.nodeType == node.TEXT_NODE:
99                         rc = rc + node.data
100         return rc
101
102 def getValbyAttr(x, attr):
103         for p in range(x.attributes.length):
104                 a = x.attributes.item(p)
105                 attrib = str(a.name)
106                 value = str(a.value)
107                 if attrib == attr:
108                         return value
109                         
110         return ""
111
112 class boundFunction:
113         def __init__(self, fnc, *args):
114                 self.fnc = fnc
115                 self.args = args
116         def __call__(self):
117                 self.fnc(*self.args)
118
119 class configOSD(Screen):
120         #this needs focus handling - so not useable
121
122         def okbuttonClick(self):
123                 self.close
124  
125         def __init__(self, session):
126                 Screen.__init__(self, session)
127
128                 self["actions"] = ActionMap(["OkCancelActions"], 
129                         {
130                                 "ok": self.okbuttonClick,
131                                 "cancel": self.close
132                         })
133
134                 self["okbutton"] = Button("Save")
135
136                 self["txt_alpha"] = Label("Alpha:")
137                 self["sld_alpha"] = ProgressBar()
138                 self["sld_alpha"].setValue(50)
139
140                 self["txt_brightness"] = Label("Brightness:")
141                 self["sld_brightness"] = ProgressBar()
142                 self["sld_brightness"].setValue(50)
143
144                 self["txt_gamma"] = Label("Contrast:")
145                 self["sld_gamma"] = ProgressBar()
146                 self["sld_gamma"].setValue(50)
147
148
149 class ScartLoopThrough(Screen):
150         def __init__(self, session):
151                 Screen.__init__(self, session)
152
153                 self["actions"] = ActionMap(["OkCancelActions"], 
154                         {
155                                 "cancel": self.close
156                         })
157
158 class ConfigMenu(Screen):
159         #create a generic class for view/edit settings
160         #all stuff come from xml file
161         #configtype / datasource / validate-call / ...
162
163         def __init__(self, session):
164                 Screen.__init__(self, session)
165
166                 self["actions"] = ActionMap(["OkCancelActions"], 
167                         {
168                                 #"ok": self.okbuttonClick,
169                                 "cancel": self.close
170                         })
171
172 class configTest(Screen):
173
174         def __init__(self, session):
175                 Screen.__init__(self, session)
176                 
177
178                 self["config"] = ConfigList(
179                         [
180                                 configEntry("HKEY_LOCAL_ENIGMA/IMPORTANT/USER_ANNOYING_STUFF/SDTV/FLASHES/GREEN"),
181                                 configEntry("HKEY_LOCAL_ENIGMA/IMPORTANT/USER_ANNOYING_STUFF/HDTV/FLASHES/GREEN"),
182                         ])
183
184                 self["actions"] = ActionMap(["OkCancelActions"], 
185                         {
186                                 "ok": self["config"].toggle,
187                                 "cancel": self.close
188                         })
189                 
190
191 class Menu(Screen):
192         #add file load functions for the xml-file
193         #remove old code (i.e. goScan / goClock...)
194
195         def openDialog(self, dialog):
196                 self.session.open(dialog)
197
198         def goSetup(self):
199                 self.session.open(configTest)
200         
201         def setModeTV(self):
202                 print "set Mode to TV"
203                 pass
204
205         def setModeRadio(self):
206                 print "set Mode to Radio"
207                 pass
208
209         def setModeFile(self):
210                 print "set Mode to File"
211                 pass
212
213         def goScan(self):
214                 self.session.open(serviceScan)
215         
216         def goClock(self):
217                 self.session.open(clockDisplay, Clock())
218
219         def okbuttonClick(self):
220                 selection = self["menu"].getCurrent()
221                 selection[1]()
222
223         def evalText(self, text):
224                 eval(text)
225                 
226         def nothing(self):                                                                                                                                      #dummy
227                 pass
228
229         def addMenu(self, destList, node):
230                 MenuTitle = getValbyAttr(node, "text")
231                 if MenuTitle != "":                                                                                                                                     #check for title
232                         a = boundFunction(self.session.open, Menu, node, node.childNodes)
233                         #TODO add check if !empty(node.childNodes)
234                         destList.append((MenuTitle, a))
235                 
236         def addItem(self, destList, node):
237                 ItemText = getValbyAttr(node, "text")
238                 if ItemText != "":                                                                                                                                      #check for name
239                         b = getText(node.childNodes)
240                         if b != "":                                                                                                                                                             #check for function
241                                 destList.append((ItemText,boundFunction(self.evalText,b)))
242                         else:
243                                 destList.append((ItemText,self.nothing))                                #use dummy as function
244
245         def __init__(self, session, parent, childNode):
246                 Screen.__init__(self, session)
247                 
248                 list = []
249
250                 for x in childNode:                                                     #walk through the actual nodelist
251                         if x.nodeType != xml.dom.minidom.Element.nodeType:
252                             continue
253                         elif x.tagName == 'item':
254                                 self.addItem(list, x)
255                         elif x.tagName == 'menu':
256                                 self.addMenu(list, x)
257
258                 self["menu"] = MenuList(list)   
259                                                         
260                 self["actions"] = ActionMap(["OkCancelActions"], 
261                         {
262                                 "ok": self.okbuttonClick,
263                                 "cancel": self.close
264                         })
265                 
266                 a = getValbyAttr(parent, "title")
267                 if a == "":                                                                                                             #if empty use name
268                         a = getValbyAttr(parent, "text")
269                 self["title"] = Header(a)
270
271 class channelSelection(Screen):
272         def __init__(self, session):
273                 Screen.__init__(self, session)
274
275                 self["key_red"] = Button("red")
276                 self["key_green"] = Button("green")
277                 self["key_yellow"] = Button("yellow")
278                 self["key_blue"] = Button("blue")
279                 
280                 self["list"] = ServiceList()
281                 self["list"].setRoot(eServiceReference("""1:0:1:0:0:0:0:0:0:0:(provider=="ARD") && (type == 1)"""))
282                 
283                 #self["okbutton"] = Button("ok", [self.channelSelected])
284                 
285                 class ChannelActionMap(ActionMap):
286                         def action(self, contexts, action):
287                                 if action[:7] == "bouquet":
288                                         print "setting root to " + action[8:]
289                                         self.csel["list"].setRoot(eServiceReference("1:0:1:0:0:0:0:0:0:0:" + action[8:]))
290                                 else:
291                                         ActionMap.action(self, contexts, action)
292
293                 self["actions"] = ChannelActionMap(["ChannelSelectActions", "OkCancelActions"], 
294                         {
295                                 "cancel": self.close,
296                                 "ok": self.channelSelected,
297                                 "mark": self.doMark
298                         })
299                 self["actions"].csel = self
300
301         def doMark(self):
302                 ref = self["list"].getCurrent()
303                 if self["list"].isMarked(ref):
304                         self["list"].removeMarked(ref)
305                 else:
306                         self["list"].addMarked(ref)
307                 
308         def channelSelected(self):
309                 self.session.nav.playService(self["list"].getCurrent())
310                 self.close()
311
312         #called from infoBar
313         def zapUp(self):
314                 self["list"].moveUp()
315                 self.session.nav.playService(self["list"].getCurrent())
316
317         def zapDown(self):
318                 self["list"].moveDown()
319                 self.session.nav.playService(self["list"].getCurrent())
320
321 class infoBar(Screen):
322         def __init__(self, session):
323                 Screen.__init__(self, session)
324
325                 #instantiate forever
326                 self["ServiceList"] = self.session.instantiateDialog(channelSelection)
327                 
328                 self["actions"] = ActionMap( [ "InfobarActions" ], 
329                         {
330                                 "switchChannel": self.switchChannel,
331                                 "mainMenu": self.mainMenu,
332                                 "zapUp": self.zapUp,
333                                 "zapDown": self.zapDown
334                         })
335                 self["okbutton"] = Button("mainMenu", [self.mainMenu])
336                 
337                 self["CurrentTime"] = Clock()
338                 
339                 self["ServiceName"] = ServiceName(self.session.nav)
340                 
341                 self["Event_Now"] = EventInfo(self.session.nav, EventInfo.Now)
342                 self["Event_Next"] = EventInfo(self.session.nav, EventInfo.Next)
343
344                 self["Event_Now_Duration"] = EventInfo(self.session.nav, EventInfo.Now_Duration)
345                 self["Event_Next_Duration"] = EventInfo(self.session.nav, EventInfo.Next_Duration)
346         
347         def mainMenu(self):
348                 print "loading mainmenu XML..."
349                 menu = mdom.childNodes[0]
350                 assert menu.tagName == "menu", "root element in menu must be 'menu'!"
351                 self.session.open(Menu, menu, menu.childNodes)
352
353         def switchChannel(self):        
354                 self.session.execDialog(self["ServiceList"])
355
356         def     zapUp(self):
357                 self["ServiceList"].zapUp()
358
359         def     zapDown(self):
360                 self["ServiceList"].zapDown()
361
362 # a clock display dialog
363 class clockDisplay(Screen):
364         def okbutton(self):
365                 self.session.close()
366         
367         def __init__(self, session, clock):
368                 Screen.__init__(self, session)
369                 self["theClock"] = clock
370                 b = Button("bye")
371                 b.onClick = [ self.okbutton ]
372                 self["okbutton"] = b
373                 self["title"] = Header("clock dialog: here you see the current uhrzeit!")
374
375 class serviceScan(Screen):
376         def ok(self):
377                 print "ok"
378                 if self["scan"].isDone():
379                         self.close()
380         
381         def cancel(self):
382                 print "cancel not yet implemented ;)"
383         
384         def __init__(self, session):
385                 Screen.__init__(self, session)
386                 
387                 self["scan_progress"] = ProgressBar()
388                 self["scan_state"] = Label("scan state")
389                 self["scan"] = ServiceScan(self["scan_progress"], self["scan_state"])
390
391                 self["actions"] = ActionMap(["OkCancelActions"], 
392                         {
393                                 "ok": self.ok,
394                                 "cancel": self.cancel
395                         })
396