bug
[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
40 # read the skin
41 try:
42         # first we search in the current path
43         menufile = file('data/menu.xml', 'r')
44 except:
45         # if not found in the current path, we use the global datadir-path
46         menufile = file('/usr/share/enigma2/menu.xml', 'r')
47 mdom = xml.dom.minidom.parseString(menufile.read())
48 menufile.close()
49
50
51
52 def getValbyAttr(x, attr):
53         for p in range(x.attributes.length):
54                 a = x.attributes.item(p)
55                 attrib = str(a.name)
56                 value = str(a.value)
57                 if attrib == attr:
58                         return value
59                         
60         return ""
61
62 class boundFunction:
63         def __init__(self, fnc, *args):
64                 self.fnc = fnc
65                 self.args = args
66         def __call__(self):
67                 self.fnc(*self.args)
68
69 class configOSD(Screen):
70         #this needs focus handling - so not useable
71
72         def okbuttonClick(self):
73                 self.close
74  
75         def __init__(self, session):
76                 Screen.__init__(self, session)
77
78                 self["actions"] = ActionMap(["OkCancelActions"], 
79                         {
80                                 "ok": self.okbuttonClick,
81                                 "cancel": self.close
82                         })
83
84                 self["okbutton"] = Button("Save")
85
86                 self["txt_alpha"] = Label("Alpha:")
87                 self["sld_alpha"] = ProgressBar()
88                 self["sld_alpha"].setValue(50)
89
90                 self["txt_brightness"] = Label("Brightness:")
91                 self["sld_brightness"] = ProgressBar()
92                 self["sld_brightness"].setValue(50)
93
94                 self["txt_gamma"] = Label("Contrast:")
95                 self["sld_gamma"] = ProgressBar()
96                 self["sld_gamma"].setValue(50)
97
98 class Menu(Screen):
99         def okbuttonClick(self):
100                 print "okbuttonClick"
101                 selection = self["menu"].getCurrent()
102                 selection[1]()
103
104         def evalText(self, text):
105                 eval(text)
106                 
107         def nothing(self):                                                                                                                                      #dummy
108                 pass
109
110         def openDialog(self, dialog):                           # in every layer needed
111                 self.session.open(dialog)
112
113         def openSetup(self, dialog):
114                 self.session.open(Setup, dialog)
115
116         def addMenu(self, destList, node):
117                 MenuTitle = getValbyAttr(node, "text")
118                 if MenuTitle != "":                                                                                                                                     #check for title
119                         a = boundFunction(self.session.open, Menu, node, node.childNodes)
120                         #TODO add check if !empty(node.childNodes)
121                         destList.append((MenuTitle, a))
122                 
123         def addItem(self, destList, node):
124                 ItemText = getValbyAttr(node, "text")
125                 if ItemText != "":                                                                                                                                      #check for name
126                         b = XMLTools.mergeText(node.childNodes)
127                         if b != "":                                                                                                                                                             #check for function
128                                 destList.append((ItemText,boundFunction(self.evalText,b)))
129                         else:
130                                 destList.append((ItemText,self.nothing))                                #use dummy as function
131
132         def __init__(self, session, parent, childNode):
133                 Screen.__init__(self, session)
134                 
135                 list = []
136
137                 for x in childNode:                                                     #walk through the actual nodelist
138                         if x.nodeType != xml.dom.minidom.Element.nodeType:
139                             continue
140                         elif x.tagName == 'item':
141                                 self.addItem(list, x)
142                         elif x.tagName == 'menu':
143                                 self.addMenu(list, x)
144
145                 self["menu"] = MenuList(list)   
146                                                         
147                 self["actions"] = ActionMap(["OkCancelActions"], 
148                         {
149                                 "ok": self.okbuttonClick,
150                                 "cancel": self.close
151                         })
152                 
153                 a = getValbyAttr(parent, "title")
154                 if a == "":                                                                                                             #if empty use name
155                         a = getValbyAttr(parent, "text")
156                 self["title"] = Header(a)
157
158 class FixedMenu(Screen):
159         def okbuttonClick(self):
160                 selection = self["menu"].getCurrent()
161                 selection[1]()
162
163         def __init__(self, session, title, list):
164                 Screen.__init__(self, session)
165                 
166                 self["menu"] = MenuList(list)   
167                                                         
168                 self["actions"] = ActionMap(["OkCancelActions"], 
169                         {
170                                 "ok": self.okbuttonClick,
171                                 "cancel": self.close
172                         })
173                 
174                 self["title"] = Header(title)
175
176
177 class MainMenu(Menu):
178         #add file load functions for the xml-file
179         #remove old code (i.e. goScan / goClock...)
180         
181         def __init__(self, *x):
182                 Menu.__init__(self, *x)
183                 self.skinName = "Menu"
184
185         def openDialog(self, dialog):
186                 self.session.open(dialog)
187
188         def openSetup(self, dialog):
189                 self.session.open(Setup, dialog)
190
191         def goSetup(self):
192                 self.session.open(configTest)
193         
194         def setModeTV(self):
195                 print "set Mode to TV"
196                 pass
197
198         def setModeRadio(self):
199                 print "set Mode to Radio"
200                 pass
201
202         def setModeFile(self):
203                 print "set Mode to File"
204                 pass
205
206         def goScan(self):
207                 self.session.open(ServiceScan)
208         
209         def goClock(self):
210                 self.session.open(clockDisplay, Clock())