import Setup which was used but not imported
[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 from enigma import quitMainloop
10
11 import xml.dom.minidom
12 from xml.dom import EMPTY_NAMESPACE
13 from skin import elementsWithTag
14
15 from Screens.Satconfig import NimSelection
16 from Screens.Setup import *
17
18 from Tools import XMLTools
19
20 # some screens
21 def doGlobal(screen):
22         screen["clock"] = Clock()
23
24
25 #               <item text="TV-Mode">self.setModeTV()</item>
26 #               <item text="Radio-Mode">self.setModeRadio()</item>
27 #               <item text="File-Mode">self.setModeFile()</item>
28 #               <item text="Scart">self.openDialog(ScartLoopThrough)</item>
29 #                       <item text="Sleep Timer"></item>
30
31
32 # read the menu
33 try:
34         # first we search in the current path
35         menufile = file('data/menu.xml', 'r')
36 except:
37         # if not found in the current path, we use the global datadir-path
38         menufile = file('/usr/share/enigma2/menu.xml', 'r')
39 mdom = xml.dom.minidom.parseString(menufile.read())
40 menufile.close()
41
42
43
44 def getValbyAttr(x, attr):
45         for p in range(x.attributes.length):
46                 a = x.attributes.item(p)
47                 attrib = str(a.name)
48                 value = str(a.value)
49                 if attrib == attr:
50                         return value
51                         
52         return ""
53
54 class boundFunction:
55         def __init__(self, fnc, *args):
56                 self.fnc = fnc
57                 self.args = args
58         def __call__(self):
59                 self.fnc(*self.args)
60
61 class Menu(Screen):
62         def okbuttonClick(self):
63                 print "okbuttonClick"
64                 selection = self["menu"].getCurrent()
65                 selection[1]()
66
67         def evalText(self, text):
68                 eval(text)
69                 
70         def nothing(self):                                                                                                                                      #dummy
71                 pass
72
73         def openDialog(self, dialog):                           # in every layer needed
74                 self.session.open(dialog)
75
76         def openSetup(self, dialog):
77                 self.session.open(Setup, dialog)
78
79         def addMenu(self, destList, node):
80                 MenuTitle = getValbyAttr(node, "text")
81                 if MenuTitle != "":                                                                                                                                     #check for title
82                         a = boundFunction(self.session.open, Menu, node, node.childNodes)
83                         #TODO add check if !empty(node.childNodes)
84                         destList.append((MenuTitle, a))
85                 
86         def addItem(self, destList, node):
87                 ItemText = getValbyAttr(node, "text")
88                 if ItemText != "":                                                                                                                                      #check for name
89                         b = XMLTools.mergeText(node.childNodes)
90                         if b != "":                                                                                                                                                             #check for function
91                                 destList.append((ItemText,boundFunction(self.evalText,b)))
92                         else:
93                                 destList.append((ItemText,self.nothing))                                #use dummy as function
94
95         def __init__(self, session, parent, childNode):
96                 Screen.__init__(self, session)
97                 
98                 list = []
99
100                 for x in childNode:                                                     #walk through the actual nodelist
101                         if x.nodeType != xml.dom.minidom.Element.nodeType:
102                             continue
103                         elif x.tagName == 'item':
104                                 self.addItem(list, x)
105                         elif x.tagName == 'menu':
106                                 self.addMenu(list, x)
107
108                 self["menu"] = MenuList(list)   
109                                                         
110                 self["actions"] = ActionMap(["OkCancelActions"], 
111                         {
112                                 "ok": self.okbuttonClick,
113                                 "cancel": self.close
114                         })
115                 
116                 a = getValbyAttr(parent, "title")
117                 if a == "":                                                                                                             #if empty use name
118                         a = getValbyAttr(parent, "text")
119                 self["title"] = Header(a)
120
121 class MainMenu(Menu):
122         #add file load functions for the xml-file
123         
124         def __init__(self, *x):
125                 Menu.__init__(self, *x)
126                 self.skinName = "Menu"
127
128         def openDialog(self, dialog):
129                 self.session.open(dialog)
130
131         def openSetup(self, dialog):
132                 self.session.open(Setup, dialog)
133
134         def setModeTV(self):
135                 print "set Mode to TV"
136                 pass
137
138         def setModeRadio(self):
139                 print "set Mode to Radio"
140                 pass
141
142         def setModeFile(self):
143                 print "set Mode to File"
144                 pass