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