1 from Screen import Screen
2 from Components.ActionMap import NumberActionMap
3 from Components.config import config #global config instance
4 from Components.config import configSelection
5 from Components.ConfigList import ConfigList
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
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 def getValbyAttr(x, attr):
26 for p in range(x.attributes.length):
27 a = x.attributes.item(p)
37 def addItems(self, list, childNode):
39 if x.nodeType != xml.dom.minidom.Element.nodeType:
41 elif x.tagName == 'item':
42 ItemText = _(getValbyAttr(x, "text"))
43 b = eval(XMLTools.mergeText(x.childNodes));
44 print "item " + ItemText + " " + b.configPath
48 item = b.controlType(b)
50 # the first b is the item itself, ignored by the configList.
51 # the second one is converted to string.
52 list.append( (ItemText, item) )
55 if (self["config"].getCurrent()[1].parent.enabled == True):
56 self["config"].handleKey(config.key["choseElement"])
58 if (self["config"].getCurrent()[1].parent.enabled == True):
59 self["config"].handleKey(config.key["prevElement"])
61 if (self["config"].getCurrent()[1].parent.enabled == True):
62 self["config"].handleKey(config.key["nextElement"])
65 print "save requested"
66 for x in self["config"].list:
71 print "cancel requested"
72 for x in self["config"].list:
76 def keyNumberGlobal(self, number):
77 print "You pressed number " + str(number)
78 if (self["config"].getCurrent()[1].parent.enabled == True):
79 self["config"].handleKey(config.key[str(number)])
82 def __init__(self, session, setup):
83 Screen.__init__(self, session)
85 print "request setup for " + setup
87 xmldata = setupdom.childNodes[0]
89 entries = xmldata.childNodes
93 for x in entries: #walk through the actual nodelist
94 if x.nodeType != xml.dom.minidom.Element.nodeType:
96 elif x.tagName == 'setup':
97 ItemText = getValbyAttr(x, "key")
100 self.addItems(list, x.childNodes);
101 myTitle = getValbyAttr(x, "title")
103 #check for list.entries > 0 else self.close
105 self["config"] = ConfigList(list)
107 self["title"] = Label(_(myTitle));
109 self["oktext"] = Label(_("OK"))
110 self["canceltext"] = Label(_("Cancel"))
111 self["ok"] = Pixmap()
112 self["cancel"] = Pixmap()
114 self["actions"] = NumberActionMap(["SetupActions"],
116 "cancel": self.keyCancel,
118 "left": self.keyLeft,
119 "right": self.keyRight,
120 "save": self.keySave,
121 "1": self.keyNumberGlobal,
122 "2": self.keyNumberGlobal,
123 "3": self.keyNumberGlobal,
124 "4": self.keyNumberGlobal,
125 "5": self.keyNumberGlobal,
126 "6": self.keyNumberGlobal,
127 "7": self.keyNumberGlobal,
128 "8": self.keyNumberGlobal,
129 "9": self.keyNumberGlobal,
130 "0": self.keyNumberGlobal