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