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 skin import elementsWithTag
12 from Tools import XMLTools
14 # FIXME: use resolveFile!
17 # first we search in the current path
18 setupfile = file('data/setup.xml', 'r')
20 # if not found in the current path, we use the global datadir-path
21 setupfile = file('/usr/share/enigma2/setup.xml', 'r')
22 setupdom = xml.dom.minidom.parseString(setupfile.read())
25 class SetupSummary(Screen):
27 <screen position="6,0" size="120,64">
28 <widget name="SetupTitle" position="6,0" size="120,16" font="Regular;12" />
29 <widget name="SetupEntry" position="6,16" size="120,32" font="Regular;12" />
30 <widget name="SetupValue" position="6,48" size="120,16" font="Regular;12" />
33 def __init__(self, session, parent):
34 Screen.__init__(self, session)
35 self["SetupTitle"] = Label(_(parent.setup_title))
36 self["SetupEntry"] = Label("")
37 self["SetupValue"] = Label("")
39 self.onShow.append(self.addWatcher)
40 self.onHide.append(self.removeWatcher)
43 self.parent.onChangedEntry.append(self.selectionChanged)
44 self.parent["config"].onSelectionChanged.append(self.selectionChanged)
45 self.selectionChanged()
47 def removeWatcher(self):
48 self.parent.onChangedEntry.remove(self.selectionChanged)
49 self.parent["config"].onSelectionChanged.remove(self.selectionChanged)
51 def selectionChanged(self):
52 self["SetupEntry"].text = self.parent.getCurrentEntry()
53 self["SetupValue"].text = self.parent.getCurrentValue()
55 class Setup(ConfigListScreen, Screen):
59 def removeNotifier(self):
60 config.usage.setup_level.notifiers.remove(self.levelChanged)
62 def levelChanged(self, configElement):
65 self["config"].setList(list)
67 def refill(self, list):
68 xmldata = setupdom.childNodes[0]
69 entries = xmldata.childNodes
70 for x in entries: #walk through the actual nodelist
71 if x.nodeType != xml.dom.minidom.Element.nodeType:
73 elif x.tagName == 'setup':
74 if x.getAttribute("key") != self.setup:
76 self.addItems(list, x.childNodes);
77 self.setup_title = x.getAttribute("title").encode("UTF-8")
79 def __init__(self, session, setup):
80 Screen.__init__(self, session)
82 # for the skin: first try a setup_<setupID>, then Setup
83 self.skinName = ["setup_" + setup, "Setup" ]
85 self.onChangedEntry = [ ]
91 #check for list.entries > 0 else self.close
92 self["title"] = Label(_(self.setup_title))
94 self["oktext"] = Label(_("OK"))
95 self["canceltext"] = Label(_("Cancel"))
97 self["cancel"] = Pixmap()
99 self["actions"] = NumberActionMap(["SetupActions"],
101 "cancel": self.keyCancel,
102 "save": self.keySave,
105 ConfigListScreen.__init__(self, list, session = session, on_change = self.changedEntry)
110 def changedEntry(self):
111 for x in self.onChangedEntry:
114 def getCurrentEntry(self):
115 return self["config"].getCurrent()[0]
117 def getCurrentValue(self):
118 return str(self["config"].getCurrent()[1].getText())
120 def createSummary(self):
123 def addItems(self, list, childNode):
125 if x.nodeType != xml.dom.minidom.Element.nodeType:
127 elif x.tagName == 'item':
128 item_level = int(x.getAttribute("level") or "0")
130 if not self.levelChanged in config.usage.setup_level.notifiers:
131 config.usage.setup_level.notifiers.append(self.levelChanged)
132 self.onClose.append(self.removeNotifier)
134 if item_level > config.usage.setup_level.index:
137 requires = x.getAttribute("requires")
138 if requires and not SystemInfo.get(requires, False):
141 item_text = _(x.getAttribute("text").encode("UTF-8") or "??")
142 b = eval(XMLTools.mergeText(x.childNodes));
147 # the first b is the item itself, ignored by the configList.
148 # the second one is converted to string.
149 if not isinstance(item, ConfigNothing):
150 list.append( (item_text, item) )
152 def getSetupTitle(id):
153 xmldata = setupdom.childNodes[0].childNodes
154 for x in elementsWithTag(xmldata, "setup"):
155 if x.getAttribute("key") == id:
156 return x.getAttribute("title").encode("UTF-8")
157 raise "unknown setup id '%s'!" % repr(id)