1 from Screen import Screen
2 from MessageBox import MessageBox
3 from Components.ActionMap import NumberActionMap
4 from Components.config import config, KEY_LEFT, KEY_RIGHT, KEY_OK
5 from Components.ConfigList import ConfigList, ConfigListScreen
6 from Components.Label import Label
7 from Components.Pixmap import Pixmap
10 from xml.dom import EMPTY_NAMESPACE
11 from skin import elementsWithTag
13 from Tools import XMLTools
15 # FIXME: use resolveFile!
18 # first we search in the current path
19 setupfile = file('data/setup.xml', 'r')
21 # if not found in the current path, we use the global datadir-path
22 setupfile = file('/usr/share/enigma2/setup.xml', 'r')
23 setupdom = xml.dom.minidom.parseString(setupfile.read())
26 class SetupSummary(Screen):
28 <screen position="6,0" size="120,64">
29 <widget name="SetupTitle" position="6,0" size="120,16" font="Regular;12" />
30 <widget name="SetupEntry" position="6,16" size="120,32" font="Regular;12" />
31 <widget name="SetupValue" position="6,48" size="120,16" font="Regular;12" />
34 def __init__(self, session, parent):
35 Screen.__init__(self, session)
36 self["SetupTitle"] = Label(_(parent.setup_title))
37 self["SetupEntry"] = Label("")
38 self["SetupValue"] = Label("")
40 self.onShow.append(self.addWatcher)
41 self.onHide.append(self.removeWatcher)
44 self.parent.onChangedEntry.append(self.selectionChanged)
45 self.parent["config"].onSelectionChanged.append(self.selectionChanged)
46 self.selectionChanged()
48 def removeWatcher(self):
49 self.parent.onChangedEntry.remove(self.selectionChanged)
50 self.parent["config"].onSelectionChanged.remove(self.selectionChanged)
52 def selectionChanged(self):
53 self["SetupEntry"].text = self.parent.getCurrentEntry()
54 self["SetupValue"].text = self.parent.getCurrentValue()
56 class Setup(ConfigListScreen, Screen):
60 def __init__(self, session, setup):
61 Screen.__init__(self, session)
63 xmldata = setupdom.childNodes[0]
65 entries = xmldata.childNodes
67 self.onChangedEntry = [ ]
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") != setup:
76 self.addItems(list, x.childNodes);
77 myTitle = x.getAttribute("title").encode("UTF-8")
79 #check for list.entries > 0 else self.close
81 self.setup_title = myTitle
82 self["title"] = Label(_(self.setup_title))
84 self["oktext"] = Label(_("OK"))
85 self["canceltext"] = Label(_("Cancel"))
87 self["cancel"] = Pixmap()
89 self["actions"] = NumberActionMap(["SetupActions"],
91 "cancel": self.keyCancel,
95 ConfigListScreen.__init__(self, list, session = session, on_change = self.changedEntry)
100 def changedEntry(self):
101 for x in self.onChangedEntry:
104 def getCurrentEntry(self):
105 return self["config"].getCurrent()[0]
107 def getCurrentValue(self):
108 return str(self["config"].getCurrent()[1].getText())
110 def createSummary(self):
113 def addItems(self, list, childNode):
115 if x.nodeType != xml.dom.minidom.Element.nodeType:
117 elif x.tagName == 'item':
118 item_text = _(x.getAttribute("text").encode("UTF-8") or "??")
119 b = eval(XMLTools.mergeText(x.childNodes));
124 # the first b is the item itself, ignored by the configList.
125 # the second one is converted to string.
126 list.append( (item_text, item) )
129 print "save requested"
130 for x in self["config"].list:
134 def cancelConfirm(self, result):
138 print "cancel requested"
140 for x in self["config"].list:
146 for x in self["config"].list:
147 is_changed |= x[1].isChanged()
150 self.session.openWithCallback(self.cancelConfirm, MessageBox, _("Really close without saving settings?"))
154 def getSetupTitle(id):
155 xmldata = setupdom.childNodes[0].childNodes
156 for x in elementsWithTag(xmldata, "setup"):
157 if x.getAttribute("key") == id:
158 return x.getAttribute("title").encode("UTF-8")