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