1 from Screen import Screen
2 from Components.ActionMap import NumberActionMap
3 from Components.config import config
4 from Components.ConfigList import ConfigListScreen
5 from Components.Label import Label
6 from Components.Pixmap import Pixmap
9 from skin import elementsWithTag
11 from Tools import XMLTools
13 # FIXME: use resolveFile!
16 # first we search in the current path
17 setupfile = file('data/setup.xml', 'r')
19 # if not found in the current path, we use the global datadir-path
20 setupfile = file('/usr/share/enigma2/setup.xml', 'r')
21 setupdom = xml.dom.minidom.parseString(setupfile.read())
24 class SetupSummary(Screen):
26 <screen position="6,0" size="120,64">
27 <widget name="SetupTitle" position="6,0" size="120,16" font="Regular;12" />
28 <widget name="SetupEntry" position="6,16" size="120,32" font="Regular;12" />
29 <widget name="SetupValue" position="6,48" size="120,16" font="Regular;12" />
32 def __init__(self, session, parent):
33 Screen.__init__(self, session)
34 self["SetupTitle"] = Label(_(parent.setup_title))
35 self["SetupEntry"] = Label("")
36 self["SetupValue"] = Label("")
38 self.onShow.append(self.addWatcher)
39 self.onHide.append(self.removeWatcher)
42 self.parent.onChangedEntry.append(self.selectionChanged)
43 self.parent["config"].onSelectionChanged.append(self.selectionChanged)
44 self.selectionChanged()
46 def removeWatcher(self):
47 self.parent.onChangedEntry.remove(self.selectionChanged)
48 self.parent["config"].onSelectionChanged.remove(self.selectionChanged)
50 def selectionChanged(self):
51 self["SetupEntry"].text = self.parent.getCurrentEntry()
52 self["SetupValue"].text = self.parent.getCurrentValue()
54 class Setup(ConfigListScreen, Screen):
58 def removeNotifier(self):
59 config.usage.setup_level.notifiers.remove(self.levelChanged)
61 def levelChanged(self, configElement):
64 self["config"].setList(list)
66 def refill(self, list):
67 xmldata = setupdom.childNodes[0]
68 entries = xmldata.childNodes
69 for x in entries: #walk through the actual nodelist
70 if x.nodeType != xml.dom.minidom.Element.nodeType:
72 elif x.tagName == 'setup':
73 if x.getAttribute("key") != self.setup:
75 self.addItems(list, x.childNodes);
76 self.setup_title = x.getAttribute("title").encode("UTF-8")
78 def __init__(self, session, setup):
79 Screen.__init__(self, session)
81 self.onChangedEntry = [ ]
87 #check for list.entries > 0 else self.close
88 self["title"] = Label(_(self.setup_title))
90 self["oktext"] = Label(_("OK"))
91 self["canceltext"] = Label(_("Cancel"))
93 self["cancel"] = Pixmap()
95 self["actions"] = NumberActionMap(["SetupActions"],
97 "cancel": self.keyCancel,
101 ConfigListScreen.__init__(self, list, session = session, on_change = self.changedEntry)
106 def changedEntry(self):
107 for x in self.onChangedEntry:
110 def getCurrentEntry(self):
111 return self["config"].getCurrent()[0]
113 def getCurrentValue(self):
114 return str(self["config"].getCurrent()[1].getText())
116 def createSummary(self):
119 def addItems(self, list, childNode):
121 if x.nodeType != xml.dom.minidom.Element.nodeType:
123 elif x.tagName == 'item':
124 item_level = int(x.getAttribute("level") or "0")
126 if not self.levelChanged in config.usage.setup_level.notifiers:
127 config.usage.setup_level.notifiers.append(self.levelChanged)
128 self.onClose.append(self.removeNotifier)
130 if item_level > config.usage.setup_level.index:
133 item_text = _(x.getAttribute("text").encode("UTF-8") or "??")
134 b = eval(XMLTools.mergeText(x.childNodes));
139 # the first b is the item itself, ignored by the configList.
140 # the second one is converted to string.
141 list.append( (item_text, item) )
143 def getSetupTitle(id):
144 xmldata = setupdom.childNodes[0].childNodes
145 for x in elementsWithTag(xmldata, "setup"):
146 if x.getAttribute("key") == id:
147 return x.getAttribute("title").encode("UTF-8")
148 raise "unknown setup id '%s'!" % repr(id)