[RecordTimer] fix repeat timer issue.
[vuplus_dvbapp] / lib / python / Screens / Setup.py
1 from Screen import Screen
2 from Components.ActionMap import NumberActionMap
3 from Components.config import config, ConfigNothing
4 from Components.SystemInfo import SystemInfo
5 from Components.ConfigList import ConfigListScreen
6 from Components.Sources.StaticText import StaticText
7 from enigma import eEnv
8
9 import xml.etree.cElementTree
10
11 # FIXME: use resolveFile!
12 # read the setupmenu
13 try:
14         # first we search in the current path
15         setupfile = file('data/setup.xml', 'r')
16 except:
17         # if not found in the current path, we use the global datadir-path
18         setupfile = file(eEnv.resolve('${datadir}/enigma2/setup.xml'), 'r')
19 setupdom = xml.etree.cElementTree.parse(setupfile)
20 setupfile.close()
21
22 def getConfigMenuItem(configElement):
23         for item in setupdom.getroot().findall('./setup/item/.'):
24                 if item.text == configElement:
25                         return _(item.attrib["text"]), eval(configElement)
26         return "", None
27
28 class SetupError(Exception):
29     def __init__(self, message):
30         self.msg = message
31
32     def __str__(self):
33         return self.msg
34
35 class SetupSummary(Screen):
36
37         def __init__(self, session, parent):
38
39                 Screen.__init__(self, session, parent = parent)
40                 self["SetupTitle"] = StaticText(_(parent.setup_title))
41                 self["SetupEntry"] = StaticText("")
42                 self["SetupValue"] = StaticText("")
43                 self.onShow.append(self.addWatcher)
44                 self.onHide.append(self.removeWatcher)
45
46         def addWatcher(self):
47                 self.parent.onChangedEntry.append(self.selectionChanged)
48                 self.parent["config"].onSelectionChanged.append(self.selectionChanged)
49                 self.selectionChanged()
50
51         def removeWatcher(self):
52                 self.parent.onChangedEntry.remove(self.selectionChanged)
53                 self.parent["config"].onSelectionChanged.remove(self.selectionChanged)
54
55         def selectionChanged(self):
56                 self["SetupEntry"].text = self.parent.getCurrentEntry()
57                 self["SetupValue"].text = self.parent.getCurrentValue()
58
59 class Setup(ConfigListScreen, Screen):
60
61         ALLOW_SUSPEND = True
62
63         def removeNotifier(self):
64                 config.usage.setup_level.notifiers.remove(self.levelChanged)
65
66         def levelChanged(self, configElement):
67                 list = []
68                 self.refill(list)
69                 self["config"].setList(list)
70
71         def removeEntryNotifier(self):
72                 if self.needEntryChange:
73                         for item in self.needEntryChange:
74                                 if self.entryChanged in item.notifiers:
75                                         item.notifiers.remove(self.entryChanged)
76
77         def entryChanged(self, configElement):
78                 list = []
79                 self.refill(list)
80                 self["config"].setList(list)
81
82         def refill(self, list):
83                 xmldata = setupdom.getroot()
84                 for x in xmldata.findall("setup"):
85                         if x.get("key") != self.setup:
86                                 continue
87                         self.addItems(list, x);
88                         self.setup_title = x.get("title", "").encode("UTF-8")
89
90         def __init__(self, session, setup):
91                 Screen.__init__(self, session)
92                 # for the skin: first try a setup_<setupID>, then Setup
93                 self.skinName = ["setup_" + setup, "Setup" ]
94
95                 self.onChangedEntry = [ ]
96
97                 self.needEntryChange = [ ]
98
99                 self.setup = setup
100                 list = []
101                 self.refill(list)
102
103                 #check for list.entries > 0 else self.close
104                 self["key_red"] = StaticText(_("Cancel"))
105                 self["key_green"] = StaticText(_("OK"))
106
107                 self["actions"] = NumberActionMap(["SetupActions"], 
108                         {
109                                 "cancel": self.keyCancel,
110                                 "save": self.keySave,
111                         }, -2)
112
113                 ConfigListScreen.__init__(self, list, session = session, on_change = self.changedEntry)
114
115                 self.changedEntry()
116                 self.onLayoutFinish.append(self.layoutFinished)
117
118         def layoutFinished(self):
119                 self.setTitle(_(self.setup_title))
120
121         # for summary:
122         def changedEntry(self):
123                 for x in self.onChangedEntry:
124                         x()
125
126         def getCurrentEntry(self):
127                 return self["config"].getCurrent()[0]
128
129         def getCurrentValue(self):
130                 return str(self["config"].getCurrent()[1].getText())
131
132         def createSummary(self):
133                 return SetupSummary
134
135         def addItems(self, list, parentNode):
136                 self.needEntryChange = [ ]
137                 for x in parentNode:
138                         if x.tag == 'item':
139                                 item_level = int(x.get("level", 0))
140
141                                 if not self.levelChanged in config.usage.setup_level.notifiers:
142                                         config.usage.setup_level.notifiers.append(self.levelChanged)
143                                         self.onClose.append(self.removeNotifier)
144
145                                 if item_level > config.usage.setup_level.index:
146                                         continue
147
148                                 requires = x.get("requires")
149                                 if requires and not SystemInfo.get(requires, False):
150                                         continue;
151
152                                 item_text = _(x.get("text", "??").encode("UTF-8"))
153                                 b = eval(x.text or "");
154                                 if b == "":
155                                         continue
156                                 #add to configlist
157                                 item = b
158                                 # the first b is the item itself, ignored by the configList.
159                                 # the second one is converted to string.
160                                 if not isinstance(item, ConfigNothing):
161                                         list.append( (item_text, item) )
162
163                                         needentrychange = x.get("entrychange")
164                                         if needentrychange == "yes":
165                                                 self.needEntryChange.append(item)
166                                                 if not self.entryChanged in item.notifiers:
167                                                         item.notifiers.append(self.entryChanged)
168                                                 if not self.removeEntryNotifier in self.onClose:
169                                                         self.onClose.append(self.removeEntryNotifier)
170
171 def getSetupTitle(id):
172         xmldata = setupdom.getroot()
173         for x in xmldata.findall("setup"):
174                 if x.get("key") == id:
175                         return x.get("title", "").encode("UTF-8")
176         raise SetupError("unknown setup id '%s'!" % repr(id))