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