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.Label import Label
7 from Components.Pixmap import Pixmap
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('/usr/share/enigma2/setup.xml', 'r')
19 setupdom = xml.etree.cElementTree.parse(setupfile)
22 class SetupSummary(Screen):
24 <screen position="6,0" size="120,64">
25 <widget name="SetupTitle" position="6,0" size="120,16" font="Regular;12" />
26 <widget name="SetupEntry" position="6,16" size="120,32" font="Regular;12" />
27 <widget name="SetupValue" position="6,48" size="120,16" font="Regular;12" />
30 def __init__(self, session, parent):
31 Screen.__init__(self, session)
32 self["SetupTitle"] = Label(_(parent.setup_title))
33 self["SetupEntry"] = Label("")
34 self["SetupValue"] = Label("")
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)
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["title"] = Label(_(self.setup_title))
87 self["oktext"] = Label(_("OK"))
88 self["canceltext"] = Label(_("Cancel"))
90 self["cancel"] = Pixmap()
92 self["actions"] = NumberActionMap(["SetupActions"],
94 "cancel": self.keyCancel,
98 ConfigListScreen.__init__(self, list, session = session, on_change = self.changedEntry)
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 "unknown setup id '%s'!" % repr(id)