entering numbers into networksetup is possible now
[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 from Components.Button import Button
6 from Components.Label import Label
7 from Components.ProgressBar import ProgressBar
8
9 # hack.... dynamically importing all screens
10 from __init__ import __all__
11 for i in __all__:
12         print "import " + i
13         if (i is not "Menu" ):
14                 exec "from " + i + " 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 #               <item text="TV-Mode">self.setModeTV()</item>
30 #               <item text="Radio-Mode">self.setModeRadio()</item>
31 #               <item text="File-Mode">self.setModeFile()</item>
32 #               <item text="Scart">self.openDialog(ScartLoopThrough)</item>
33 #                       <item text="Sleep Timer"></item>
34
35
36 # read the menu
37 try:
38         # first we search in the current path
39         menufile = file('data/menu.xml', 'r')
40 except:
41         # if not found in the current path, we use the global datadir-path
42         menufile = file('/usr/share/enigma2/menu.xml', 'r')
43 mdom = xml.dom.minidom.parseString(menufile.read())
44 menufile.close()
45
46
47
48 def getValbyAttr(x, attr):
49         for p in range(x.attributes.length):
50                 a = x.attributes.item(p)
51                 attrib = str(a.name)
52                 value = str(a.value)
53                 if attrib == attr:
54                         return value
55                         
56         return ""
57
58 class boundFunction:
59         def __init__(self, fnc, *args):
60                 self.fnc = fnc
61                 self.args = args
62         def __call__(self):
63                 self.fnc(*self.args)
64
65 class Menu(Screen):
66         def okbuttonClick(self):
67                 print "okbuttonClick"
68                 selection = self["menu"].getCurrent()
69                 selection[1]()
70
71         def evalText(self, text):
72                 eval(text)
73                 
74         def nothing(self):                                                                                                                                      #dummy
75                 pass
76
77         def openDialog(self, dialog):                           # in every layer needed
78                 self.session.open(dialog)
79
80         def openSetup(self, dialog):
81                 self.session.open(Setup, dialog)
82
83         def addMenu(self, destList, node):
84                 MenuTitle = getValbyAttr(node, "text")
85                 if MenuTitle != "":                                                                                                                                     #check for title
86                         a = boundFunction(self.session.open, Menu, node, node.childNodes)
87                         #TODO add check if !empty(node.childNodes)
88                         destList.append((MenuTitle, a))
89                 
90         def addItem(self, destList, node):
91                 ItemText = getValbyAttr(node, "text")
92                 if ItemText != "":                                                                                                                                      #check for name
93                         b = XMLTools.mergeText(node.childNodes)
94                         if b != "":                                                                                                                                                             #check for function
95                                 destList.append((ItemText,boundFunction(self.evalText,b)))
96                         else:
97                                 destList.append((ItemText,self.nothing))                                #use dummy as function
98
99         def __init__(self, session, parent, childNode):
100                 Screen.__init__(self, session)
101                 
102                 list = []
103
104                 for x in childNode:                                                     #walk through the actual nodelist
105                         if x.nodeType != xml.dom.minidom.Element.nodeType:
106                             continue
107                         elif x.tagName == 'item':
108                                 self.addItem(list, x)
109                         elif x.tagName == 'menu':
110                                 self.addMenu(list, x)
111
112                 self["menu"] = MenuList(list)   
113                                                         
114                 self["actions"] = ActionMap(["OkCancelActions"], 
115                         {
116                                 "ok": self.okbuttonClick,
117                                 "cancel": self.close
118                         })
119                 
120                 a = getValbyAttr(parent, "title")
121                 if a == "":                                                                                                             #if empty use name
122                         a = getValbyAttr(parent, "text")
123                 self["title"] = Header(a)
124
125 class FixedMenu(Screen):
126         def okbuttonClick(self):
127                 selection = self["menu"].getCurrent()
128                 selection[1]()
129
130         def __init__(self, session, title, list):
131                 Screen.__init__(self, session)
132                 
133                 self["menu"] = MenuList(list)   
134                                                         
135                 self["actions"] = ActionMap(["OkCancelActions"], 
136                         {
137                                 "ok": self.okbuttonClick,
138                                 "cancel": self.close
139                         })
140                 
141                 self["title"] = Header(title)
142
143
144 class MainMenu(Menu):
145         #add file load functions for the xml-file
146         
147         def __init__(self, *x):
148                 Menu.__init__(self, *x)
149                 self.skinName = "Menu"
150
151         def openDialog(self, dialog):
152                 self.session.open(dialog)
153
154         def openSetup(self, dialog):
155                 self.session.open(Setup, dialog)
156
157         def setModeTV(self):
158                 print "set Mode to TV"
159                 pass
160
161         def setModeRadio(self):
162                 print "set Mode to Radio"
163                 pass
164
165         def setModeFile(self):
166                 print "set Mode to File"
167                 pass