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
10 from Tools import XMLTools
12 # FIXME: use resolveFile!
15 # first we search in the current path
16 setupfile = file('data/setup.xml', 'r')
18 # if not found in the current path, we use the global datadir-path
19 setupfile = file('/usr/share/enigma2/setup.xml', 'r')
20 setupdom = xml.dom.minidom.parseString(setupfile.read())
23 class SetupSummary(Screen):
25 <screen position="6,0" size="120,64">
26 <widget name="SetupTitle" position="6,0" size="120,16" font="Regular;12" />
27 <widget name="SetupEntry" position="6,16" size="120,32" font="Regular;12" />
28 <widget name="SetupValue" position="6,48" size="120,16" font="Regular;12" />
31 def __init__(self, session, parent):
32 Screen.__init__(self, session)
33 self["SetupTitle"] = Label(_(parent.setup_title))
34 self["SetupEntry"] = Label("")
35 self["SetupValue"] = Label("")
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.childNodes[0]
67 entries = xmldata.childNodes
68 for x in entries: #walk through the actual nodelist
69 if x.nodeType != xml.dom.minidom.Element.nodeType:
71 elif x.tagName == 'setup':
72 if x.getAttribute("key") != self.setup:
74 self.addItems(list, x.childNodes);
75 self.setup_title = x.getAttribute("title").encode("UTF-8")
77 def __init__(self, session, setup):
78 Screen.__init__(self, session)
80 # for the skin: first try a setup_<setupID>, then Setup
81 self.skinName = ["setup_" + setup, "Setup" ]
83 self.onChangedEntry = [ ]
89 #check for list.entries > 0 else self.close
90 self["title"] = Label(_(self.setup_title))
92 self["oktext"] = Label(_("OK"))
93 self["canceltext"] = Label(_("Cancel"))
95 self["cancel"] = Pixmap()
97 self["actions"] = NumberActionMap(["SetupActions"],
99 "cancel": self.keyCancel,
100 "save": self.keySave,
103 ConfigListScreen.__init__(self, list, session = session, on_change = self.changedEntry)
108 def changedEntry(self):
109 for x in self.onChangedEntry:
112 def getCurrentEntry(self):
113 return self["config"].getCurrent()[0]
115 def getCurrentValue(self):
116 return str(self["config"].getCurrent()[1].getText())
118 def createSummary(self):
121 def addItems(self, list, childNode):
123 if x.nodeType != xml.dom.minidom.Element.nodeType:
125 elif x.tagName == 'item':
126 item_level = int(x.getAttribute("level") or "0")
128 if not self.levelChanged in config.usage.setup_level.notifiers:
129 config.usage.setup_level.notifiers.append(self.levelChanged)
130 self.onClose.append(self.removeNotifier)
132 if item_level > config.usage.setup_level.index:
135 requires = x.getAttribute("requires")
136 if requires and not SystemInfo.get(requires, False):
139 item_text = _(x.getAttribute("text").encode("UTF-8") or "??")
140 b = eval(XMLTools.mergeText(x.childNodes));
145 # the first b is the item itself, ignored by the configList.
146 # the second one is converted to string.
147 if not isinstance(item, ConfigNothing):
148 list.append( (item_text, item) )
150 def getSetupTitle(id):
151 xmldata = setupdom.childNodes[0].childNodes
152 for x in XMLTools.elementsWithTag(xmldata, "setup"):
153 if x.getAttribute("key") == id:
154 return x.getAttribute("title").encode("UTF-8")
155 raise "unknown setup id '%s'!" % repr(id)