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