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