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
8 import xml.etree.cElementTree
10 # FIXME: use resolveFile!
13 # first we search in the current path
14 setupfile = file('data/setup.xml', 'r')
16 # if not found in the current path, we use the global datadir-path
17 setupfile = file('/usr/share/enigma2/setup.xml', 'r')
18 setupdom = xml.etree.cElementTree.parse(setupfile)
21 class SetupError(Exception):
22 def __init__(self, message):
28 class SetupSummary(Screen):
30 def __init__(self, session, parent):
32 Screen.__init__(self, session, parent = parent)
33 self["SetupTitle"] = StaticText(_(parent.setup_title))
34 self["SetupEntry"] = StaticText("")
35 self["SetupValue"] = StaticText("")
36 self.onShow.append(self.addWatcher)
37 self.onHide.append(self.removeWatcher)
40 self.parent.onChangedEntry.append(self.selectionChanged)
41 self.parent["config"].onSelectionChanged.append(self.selectionChanged)
42 self.selectionChanged()
44 def removeWatcher(self):
45 self.parent.onChangedEntry.remove(self.selectionChanged)
46 self.parent["config"].onSelectionChanged.remove(self.selectionChanged)
48 def selectionChanged(self):
49 self["SetupEntry"].text = self.parent.getCurrentEntry()
50 self["SetupValue"].text = self.parent.getCurrentValue()
52 class Setup(ConfigListScreen, Screen):
56 def removeNotifier(self):
57 config.usage.setup_level.notifiers.remove(self.levelChanged)
59 def levelChanged(self, configElement):
62 self["config"].setList(list)
64 def refill(self, list):
65 xmldata = setupdom.getroot()
66 for x in xmldata.findall("setup"):
67 if x.get("key") != self.setup:
69 self.addItems(list, x);
70 self.setup_title = x.get("title", "").encode("UTF-8")
72 def __init__(self, session, setup):
73 Screen.__init__(self, session)
74 # for the skin: first try a setup_<setupID>, then Setup
75 self.skinName = ["setup_" + setup, "Setup" ]
77 self.onChangedEntry = [ ]
83 #check for list.entries > 0 else self.close
84 self["key_red"] = StaticText(_("Cancel"))
85 self["key_green"] = StaticText(_("OK"))
87 self["actions"] = NumberActionMap(["SetupActions"],
89 "cancel": self.keyCancel,
93 ConfigListScreen.__init__(self, list, session = session, on_change = self.changedEntry)
96 self.onLayoutFinish.append(self.layoutFinished)
98 def layoutFinished(self):
99 self.setTitle(_(self.setup_title))
102 def changedEntry(self):
103 for x in self.onChangedEntry:
106 def getCurrentEntry(self):
107 return self["config"].getCurrent()[0]
109 def getCurrentValue(self):
110 return str(self["config"].getCurrent()[1].getText())
112 def createSummary(self):
115 def addItems(self, list, parentNode):
118 item_level = int(x.get("level", 0))
120 if not self.levelChanged in config.usage.setup_level.notifiers:
121 config.usage.setup_level.notifiers.append(self.levelChanged)
122 self.onClose.append(self.removeNotifier)
124 if item_level > config.usage.setup_level.index:
127 requires = x.get("requires")
128 if requires and not SystemInfo.get(requires, False):
131 item_text = _(x.get("text", "??").encode("UTF-8"))
132 b = eval(x.text or "");
137 # the first b is the item itself, ignored by the configList.
138 # the second one is converted to string.
139 if not isinstance(item, ConfigNothing):
140 list.append( (item_text, item) )
142 def getSetupTitle(id):
143 xmldata = setupdom.getroot()
144 for x in xmldata.findall("setup"):
145 if x.get("key") == id:
146 return x.get("title", "").encode("UTF-8")
147 raise SetupError("unknown setup id '%s'!" % repr(id))