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
9 import xml.etree.cElementTree
11 # FIXME: use resolveFile!
14 # first we search in the current path
15 setupfile = file('data/setup.xml', 'r')
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)
22 class SetupError(Exception):
23 def __init__(self, message):
29 class SetupSummary(Screen):
31 def __init__(self, session, parent):
33 Screen.__init__(self, session, parent = parent)
34 self["SetupTitle"] = StaticText(_(parent.setup_title))
35 self["SetupEntry"] = StaticText("")
36 self["SetupValue"] = StaticText("")
37 self.onShow.append(self.addWatcher)
38 self.onHide.append(self.removeWatcher)
41 self.parent.onChangedEntry.append(self.selectionChanged)
42 self.parent["config"].onSelectionChanged.append(self.selectionChanged)
43 self.selectionChanged()
45 def removeWatcher(self):
46 self.parent.onChangedEntry.remove(self.selectionChanged)
47 self.parent["config"].onSelectionChanged.remove(self.selectionChanged)
49 def selectionChanged(self):
50 self["SetupEntry"].text = self.parent.getCurrentEntry()
51 self["SetupValue"].text = self.parent.getCurrentValue()
53 class Setup(ConfigListScreen, Screen):
57 def removeNotifier(self):
58 config.usage.setup_level.notifiers.remove(self.levelChanged)
60 def levelChanged(self, configElement):
63 self["config"].setList(list)
65 def refill(self, list):
66 xmldata = setupdom.getroot()
67 for x in xmldata.findall("setup"):
68 if x.get("key") != self.setup:
70 self.addItems(list, x);
71 self.setup_title = x.get("title", "").encode("UTF-8")
73 def __init__(self, session, setup):
74 Screen.__init__(self, session)
75 # for the skin: first try a setup_<setupID>, then Setup
76 self.skinName = ["setup_" + setup, "Setup" ]
78 self.onChangedEntry = [ ]
84 #check for list.entries > 0 else self.close
85 self["key_red"] = StaticText(_("Cancel"))
86 self["key_green"] = StaticText(_("OK"))
88 self["actions"] = NumberActionMap(["SetupActions"],
90 "cancel": self.keyCancel,
94 ConfigListScreen.__init__(self, list, session = session, on_change = self.changedEntry)
97 self.onLayoutFinish.append(self.layoutFinished)
99 def layoutFinished(self):
100 self.setTitle(_(self.setup_title))
103 def changedEntry(self):
104 for x in self.onChangedEntry:
107 def getCurrentEntry(self):
108 return self["config"].getCurrent()[0]
110 def getCurrentValue(self):
111 return str(self["config"].getCurrent()[1].getText())
113 def createSummary(self):
116 def addItems(self, list, parentNode):
119 item_level = int(x.get("level", 0))
121 if not self.levelChanged in config.usage.setup_level.notifiers:
122 config.usage.setup_level.notifiers.append(self.levelChanged)
123 self.onClose.append(self.removeNotifier)
125 if item_level > config.usage.setup_level.index:
128 requires = x.get("requires")
129 if requires and not SystemInfo.get(requires, False):
132 item_text = _(x.get("text", "??").encode("UTF-8"))
133 b = eval(x.text or "");
138 # the first b is the item itself, ignored by the configList.
139 # the second one is converted to string.
140 if not isinstance(item, ConfigNothing):
141 list.append( (item_text, item) )
143 def getSetupTitle(id):
144 xmldata = setupdom.getroot()
145 for x in xmldata.findall("setup"):
146 if x.get("key") == id:
147 return x.get("title", "").encode("UTF-8")
148 raise SetupError("unknown setup id '%s'!" % repr(id))