adding volume control
[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 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 addMenu(self, destList, node):
138                 MenuTitle = getValbyAttr(node, "text")
139                 if MenuTitle != "":                                                                                                                                     #check for title
140                         a = boundFunction(self.session.open, Menu, node, node.childNodes)
141                         #TODO add check if !empty(node.childNodes)
142                         destList.append((MenuTitle, a))
143                 
144         def addItem(self, destList, node):
145                 ItemText = getValbyAttr(node, "text")
146                 if ItemText != "":                                                                                                                                      #check for name
147                         b = XMLTools.mergeText(node.childNodes)
148                         if b != "":                                                                                                                                                             #check for function
149                                 destList.append((ItemText,boundFunction(self.evalText,b)))
150                         else:
151                                 destList.append((ItemText,self.nothing))                                #use dummy as function
152
153         def __init__(self, session, parent, childNode):
154                 Screen.__init__(self, session)
155                 
156                 list = []
157
158                 for x in childNode:                                                     #walk through the actual nodelist
159                         if x.nodeType != xml.dom.minidom.Element.nodeType:
160                             continue
161                         elif x.tagName == 'item':
162                                 self.addItem(list, x)
163                         elif x.tagName == 'menu':
164                                 self.addMenu(list, x)
165
166                 self["menu"] = MenuList(list)   
167                                                         
168                 self["actions"] = ActionMap(["OkCancelActions"], 
169                         {
170                                 "ok": self.okbuttonClick,
171                                 "cancel": self.close
172                         })
173                 
174                 a = getValbyAttr(parent, "title")
175                 if a == "":                                                                                                             #if empty use name
176                         a = getValbyAttr(parent, "text")
177                 self["title"] = Header(a)
178
179 class FixedMenu(Screen):
180         def okbuttonClick(self):
181                 selection = self["menu"].getCurrent()
182                 selection[1]()
183
184         def __init__(self, session, title, list):
185                 Screen.__init__(self, session)
186                 
187                 self["menu"] = MenuList(list)   
188                                                         
189                 self["actions"] = ActionMap(["OkCancelActions"], 
190                         {
191                                 "ok": self.okbuttonClick,
192                                 "cancel": self.close
193                         })
194                 
195                 self["title"] = Header(title)
196
197
198 class MainMenu(Menu):
199         #add file load functions for the xml-file
200         #remove old code (i.e. goScan / goClock...)
201         
202         def __init__(self, *x):
203                 Menu.__init__(self, *x)
204                 self.skinName = "Menu"
205
206         def openDialog(self, dialog):
207                 self.session.open(dialog)
208
209         def goSetup(self):
210                 self.session.open(configTest)
211         
212         def setModeTV(self):
213                 print "set Mode to TV"
214                 pass
215
216         def setModeRadio(self):
217                 print "set Mode to Radio"
218                 pass
219
220         def setModeFile(self):
221                 print "set Mode to File"
222                 pass
223
224         def goScan(self):
225                 self.session.open(ServiceScan)
226         
227         def goClock(self):
228                 self.session.open(clockDisplay, Clock())