- skins are now loaded first and applied later
[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 from Tools import XMLTools
23
24 # some screens
25 def doGlobal(screen):
26         screen["clock"] = Clock()
27
28
29 mdom = xml.dom.minidom.parseString(
30         """
31         <menu text="Mainmenu" title="the real Mainmenu">
32                 <item text="Standby debug">quitMainloop()</item>
33                 <item text="Automatic Scan">self.openDialog(ServiceScan)</item>
34
35                 <item text="TV-Mode">self.setModeTV()</item>
36                 <item text="Radio-Mode">self.setModeRadio()</item>
37                 <item text="File-Mode">self.setModeFile()</item>
38                 <item text="Scart">self.openDialog(ScartLoopThrough)</item>
39                 <item text="Timer">self.openDialog(TimerEditList)</item>
40                 <menu text="Setup">
41                         <menu text="Service Organising">
42                                 <item text="New Bouquets"></item>
43                                 <item text="Add to Bouquets"></item>
44                                 <item text="Edit Bouquets"></item>
45                         </menu>
46                         <menu text="Service Searching">
47                                 <item text="Satelliteconfig"></item>
48                                 <item text="Satfinder"></item>
49                                 <item text="Rotor Control"></item>
50                                 <item text="Edit Transponder"></item>
51                                 <item text="Automatic Scan">self.openDialog(ServiceScan)</item>
52                                 <item text="Automatic 'Multisat' Scan"></item>
53                                 <item text="Manual Scan"></item>
54                         </menu>
55                         <menu text="System">
56                                 <item text="Time Date"></item>
57                                 <item text="Video Audio"></item>
58                                 <item text="UHF Modulator"></item>
59                                 <item text="Harddisk"></item>
60                                 <item text="Keyboard"></item>
61                                 <item text="OSD">self.openDialog(configOSD)</item>
62                                 <item text="Language"></item>
63                                 <item text="LCD"></item>
64                         </menu>
65                         <item text="Common Interface"></item>
66                         <item text="Parental Control"></item>
67                         <item text="Expert"></item>
68                 </menu>
69                 <item text="Games"></item>
70                 <item text="Information"></item>
71                 <menu text="Standby">
72                         <item text="PowerOff"></item>
73                         <item text="Restart"></item>
74                         <item text="Standby"></item>
75                         <item text="Sleep Timer">self.goSetup()</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
126
127
128 class Menu(Screen):
129         #add file load functions for the xml-file
130         #remove old code (i.e. goScan / goClock...)
131
132         def openDialog(self, dialog):
133                 self.session.open(dialog)
134
135         def goSetup(self):
136                 self.session.open(configTest)
137         
138         def setModeTV(self):
139                 print "set Mode to TV"
140                 pass
141
142         def setModeRadio(self):
143                 print "set Mode to Radio"
144                 pass
145
146         def setModeFile(self):
147                 print "set Mode to File"
148                 pass
149
150         def goScan(self):
151                 self.session.open(ServiceScan)
152         
153         def goClock(self):
154                 self.session.open(clockDisplay, Clock())
155
156         def okbuttonClick(self):
157                 print "okbuttonClick"
158                 selection = self["menu"].getCurrent()
159                 selection[1]()
160
161         def evalText(self, text):
162                 eval(text)
163                 
164         def nothing(self):                                                                                                                                      #dummy
165                 pass
166
167         def addMenu(self, destList, node):
168                 MenuTitle = getValbyAttr(node, "text")
169                 if MenuTitle != "":                                                                                                                                     #check for title
170                         a = boundFunction(self.session.open, Menu, node, node.childNodes)
171                         #TODO add check if !empty(node.childNodes)
172                         destList.append((MenuTitle, a))
173                 
174         def addItem(self, destList, node):
175                 ItemText = getValbyAttr(node, "text")
176                 if ItemText != "":                                                                                                                                      #check for name
177                         b = XMLTools.mergeText(node.childNodes)
178                         if b != "":                                                                                                                                                             #check for function
179                                 destList.append((ItemText,boundFunction(self.evalText,b)))
180                         else:
181                                 destList.append((ItemText,self.nothing))                                #use dummy as function
182
183         def __init__(self, session, parent, childNode):
184                 Screen.__init__(self, session)
185                 
186                 list = []
187
188                 for x in childNode:                                                     #walk through the actual nodelist
189                         if x.nodeType != xml.dom.minidom.Element.nodeType:
190                             continue
191                         elif x.tagName == 'item':
192                                 self.addItem(list, x)
193                         elif x.tagName == 'menu':
194                                 self.addMenu(list, x)
195
196                 self["menu"] = MenuList(list)   
197                                                         
198                 self["actions"] = ActionMap(["OkCancelActions"], 
199                         {
200                                 "ok": self.okbuttonClick,
201                                 "cancel": self.close
202                         })
203                 
204                 a = getValbyAttr(parent, "title")
205                 if a == "":                                                                                                             #if empty use name
206                         a = getValbyAttr(parent, "text")
207                 self["title"] = Header(a)
208