1 from Screen import Screen
2 from Components.ActionMap import NumberActionMap
3 from Components.config import config, KEY_LEFT, KEY_RIGHT, KEY_OK
4 from Components.ConfigList import ConfigList, ConfigListScreen
5 from Components.Label import Label
6 from Components.Pixmap import Pixmap
9 from xml.dom import EMPTY_NAMESPACE
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 __init__(self, session, setup):
60 Screen.__init__(self, session)
62 xmldata = setupdom.childNodes[0]
64 entries = xmldata.childNodes
66 self.onChangedEntry = [ ]
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") != setup:
75 self.addItems(list, x.childNodes);
76 myTitle = x.getAttribute("title").encode("UTF-8")
78 #check for list.entries > 0 else self.close
80 self.setup_title = myTitle
81 self["title"] = Label(_(self.setup_title))
83 self["oktext"] = Label(_("OK"))
84 self["canceltext"] = Label(_("Cancel"))
86 self["cancel"] = Pixmap()
88 self["actions"] = NumberActionMap(["SetupActions"],
90 "cancel": self.keyCancel,
94 ConfigListScreen.__init__(self, list, session = session, on_change = self.changedEntry)
99 def changedEntry(self):
100 for x in self.onChangedEntry:
103 def getCurrentEntry(self):
104 return self["config"].getCurrent()[0]
106 def getCurrentValue(self):
107 return str(self["config"].getCurrent()[1].getText())
109 def createSummary(self):
112 def addItems(self, list, childNode):
114 if x.nodeType != xml.dom.minidom.Element.nodeType:
116 elif x.tagName == 'item':
117 item_text = _(x.getAttribute("text").encode("UTF-8") or "??")
118 b = eval(XMLTools.mergeText(x.childNodes));
123 # the first b is the item itself, ignored by the configList.
124 # the second one is converted to string.
125 list.append( (item_text, item) )
127 def getSetupTitle(id):
128 xmldata = setupdom.childNodes[0].childNodes
129 for x in elementsWithTag(xmldata, "setup"):
130 if x.getAttribute("key") == id:
131 return x.getAttribute("title").encode("UTF-8")