c3809318d2111f3215b578660b13dc0bcc494344
[enigma2.git] / lib / python / Screens / Menu.py
1 from Screen import *
2 from Components.MenuList import MenuList
3 from Components.ActionMap import ActionMap
4 from Components.Header import Header
5
6 # hack ... must be made dynamic
7 from ServiceScan import ServiceScan
8 from ScartLoopThrough import ScartLoopThrough
9 from Components.Button import Button
10 from Components.Label import Label
11 from Components.ProgressBar import ProgressBar
12 from ConfigMenu import *
13
14 from TimerEdit import *
15
16 from enigma import quitMainloop
17
18 import xml.dom.minidom
19 from xml.dom import EMPTY_NAMESPACE
20 from skin import elementsWithTag
21
22 # some screens
23 def doGlobal(screen):
24         screen["clock"] = Clock()
25
26
27 mdom = xml.dom.minidom.parseString(
28         """
29         <menu text="Mainmenu" title="the real Mainmenu">
30                 <item text="Standby debug">quitMainloop()</item>
31                 <item text="Automatic Scan">self.openDialog(ServiceScan)</item>
32
33                 <item text="TV-Mode">self.setModeTV()</item>
34                 <item text="Radio-Mode">self.setModeRadio()</item>
35                 <item text="File-Mode">self.setModeFile()</item>
36                 <item text="Scart">self.openDialog(ScartLoopThrough)</item>
37                 <item text="Timer">self.openDialog(TimerEditList)</item>
38                 <menu text="Setup">
39                         <menu text="Service Organising">
40                                 <item text="New Bouquets"></item>
41                                 <item text="Add to Bouquets"></item>
42                                 <item text="Edit Bouquets"></item>
43                         </menu>
44                         <menu text="Service Searching">
45                                 <item text="Satelliteconfig"></item>
46                                 <item text="Satfinder"></item>
47                                 <item text="Rotor Control"></item>
48                                 <item text="Edit Transponder"></item>
49                                 <item text="Automatic Scan">self.openDialog(ServiceScan)</item>
50                                 <item text="Automatic 'Multisat' Scan"></item>
51                                 <item text="Manual Scan"></item>
52                         </menu>
53                         <menu text="System">
54                                 <item text="Time Date"></item>
55                                 <item text="Video Audio"></item>
56                                 <item text="UHF Modulator"></item>
57                                 <item text="Harddisk"></item>
58                                 <item text="Keyboard"></item>
59                                 <item text="OSD">self.openDialog(configOSD)</item>
60                                 <item text="Language"></item>
61                                 <item text="LCD"></item>
62                         </menu>
63                         <item text="Common Interface"></item>
64                         <item text="Parental Control"></item>
65                         <item text="Expert"></item>
66                 </menu>
67                 <item text="Games"></item>
68                 <item text="Information"></item>
69                 <menu text="Standby">
70                         <item text="PowerOff"></item>
71                         <item text="Restart"></item>
72                         <item text="Standby"></item>
73                         <item text="Sleep Timer">self.goSetup()</item>
74                 </menu>
75         </menu>""")
76
77 def getText(nodelist):
78         rc = ""
79         for node in nodelist:
80                 if node.nodeType == node.TEXT_NODE:
81                         rc = rc + node.data
82         return rc
83
84 def getValbyAttr(x, attr):
85         for p in range(x.attributes.length):
86                 a = x.attributes.item(p)
87                 attrib = str(a.name)
88                 value = str(a.value)
89                 if attrib == attr:
90                         return value
91                         
92         return ""
93
94 class boundFunction:
95         def __init__(self, fnc, *args):
96                 self.fnc = fnc
97                 self.args = args
98         def __call__(self):
99                 self.fnc(*self.args)
100
101 class configOSD(Screen):
102         #this needs focus handling - so not useable
103
104         def okbuttonClick(self):
105                 self.close
106  
107         def __init__(self, session):
108                 Screen.__init__(self, session)
109
110                 self["actions"] = ActionMap(["OkCancelActions"], 
111                         {
112                                 "ok": self.okbuttonClick,
113                                 "cancel": self.close
114                         })
115
116                 self["okbutton"] = Button("Save")
117
118                 self["txt_alpha"] = Label("Alpha:")
119                 self["sld_alpha"] = ProgressBar()
120                 self["sld_alpha"].setValue(50)
121
122                 self["txt_brightness"] = Label("Brightness:")
123                 self["sld_brightness"] = ProgressBar()
124                 self["sld_brightness"].setValue(50)
125
126                 self["txt_gamma"] = Label("Contrast:")
127                 self["sld_gamma"] = ProgressBar()
128                 self["sld_gamma"].setValue(50)
129
130
131
132
133 class Menu(Screen):
134         #add file load functions for the xml-file
135         #remove old code (i.e. goScan / goClock...)
136
137         def openDialog(self, dialog):
138                 self.session.open(dialog)
139
140         def goSetup(self):
141                 self.session.open(configTest)
142         
143         def setModeTV(self):
144                 print "set Mode to TV"
145                 pass
146
147         def setModeRadio(self):
148                 print "set Mode to Radio"
149                 pass
150
151         def setModeFile(self):
152                 print "set Mode to File"
153                 pass
154
155         def goScan(self):
156                 self.session.open(ServiceScan)
157         
158         def goClock(self):
159                 self.session.open(clockDisplay, Clock())
160
161         def okbuttonClick(self):
162                 selection = self["menu"].getCurrent()
163                 selection[1]()
164
165         def evalText(self, text):
166                 eval(text)
167                 
168         def nothing(self):                                                                                                                                      #dummy
169                 pass
170
171         def addMenu(self, destList, node):
172                 MenuTitle = getValbyAttr(node, "text")
173                 if MenuTitle != "":                                                                                                                                     #check for title
174                         a = boundFunction(self.session.open, Menu, node, node.childNodes)
175                         #TODO add check if !empty(node.childNodes)
176                         destList.append((MenuTitle, a))
177                 
178         def addItem(self, destList, node):
179                 ItemText = getValbyAttr(node, "text")
180                 if ItemText != "":                                                                                                                                      #check for name
181                         b = getText(node.childNodes)
182                         if b != "":                                                                                                                                                             #check for function
183                                 destList.append((ItemText,boundFunction(self.evalText,b)))
184                         else:
185                                 destList.append((ItemText,self.nothing))                                #use dummy as function
186
187         def __init__(self, session, parent, childNode):
188                 Screen.__init__(self, session)
189                 
190                 list = []
191
192                 for x in childNode:                                                     #walk through the actual nodelist
193                         if x.nodeType != xml.dom.minidom.Element.nodeType:
194                             continue
195                         elif x.tagName == 'item':
196                                 self.addItem(list, x)
197                         elif x.tagName == 'menu':
198                                 self.addMenu(list, x)
199
200                 self["menu"] = MenuList(list)   
201                                                         
202                 self["actions"] = ActionMap(["OkCancelActions"], 
203                         {
204                                 "ok": self.okbuttonClick,
205                                 "cancel": self.close
206                         })
207                 
208                 a = getValbyAttr(parent, "title")
209                 if a == "":                                                                                                             #if empty use name
210                         a = getValbyAttr(parent, "text")
211                 self["title"] = Header(a)
212