default to 'complete' scan on DVB-C until problems with invalid NITs are fixed -...
[enigma2.git] / lib / python / Screens / Setup.py
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
7
8 import xml.dom.minidom
9 from xml.dom import EMPTY_NAMESPACE
10 from skin import elementsWithTag
11
12 from Tools import XMLTools
13
14 # FIXME: use resolveFile!
15 # read the setupmenu
16 try:
17         # first we search in the current path
18         setupfile = file('data/setup.xml', 'r')
19 except:
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())
23 setupfile.close()
24
25 class SetupSummary(Screen):
26         skin = """
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" />
31         </screen>"""
32
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("")
38                 self.parent = parent
39                 self.onShow.append(self.addWatcher)
40                 self.onHide.append(self.removeWatcher)
41                 
42         def addWatcher(self):
43                 self.parent.onChangedEntry.append(self.selectionChanged)
44                 self.parent["config"].onSelectionChanged.append(self.selectionChanged)
45                 self.selectionChanged()
46         
47         def removeWatcher(self):
48                 self.parent.onChangedEntry.remove(self.selectionChanged)
49                 self.parent["config"].onSelectionChanged.remove(self.selectionChanged)
50
51         def selectionChanged(self):
52                 self["SetupEntry"].text = self.parent.getCurrentEntry()
53                 self["SetupValue"].text = self.parent.getCurrentValue()
54
55 class Setup(ConfigListScreen, Screen):
56
57         ALLOW_SUSPEND = True
58
59         def __init__(self, session, setup):
60                 Screen.__init__(self, session)
61
62                 xmldata = setupdom.childNodes[0]
63                 
64                 entries = xmldata.childNodes
65
66                 self.onChangedEntry = [ ]
67                 list = []
68                                 
69                 for x in entries:             #walk through the actual nodelist
70                         if x.nodeType != xml.dom.minidom.Element.nodeType:
71                                 continue
72                         elif x.tagName == 'setup':
73                                 if x.getAttribute("key") != setup:
74                                         continue
75                                 self.addItems(list, x.childNodes);
76                                 myTitle = x.getAttribute("title").encode("UTF-8")
77
78                 #check for list.entries > 0 else self.close
79                 
80                 self.setup_title = myTitle
81                 self["title"] = Label(_(self.setup_title))
82
83                 self["oktext"] = Label(_("OK"))
84                 self["canceltext"] = Label(_("Cancel"))
85                 self["ok"] = Pixmap()
86                 self["cancel"] = Pixmap()
87                 
88                 self["actions"] = NumberActionMap(["SetupActions"], 
89                         {
90                                 "cancel": self.keyCancel,
91                                 "save": self.keySave,
92                         }, -2)
93
94                 ConfigListScreen.__init__(self, list, session = session, on_change = self.changedEntry)
95
96                 self.changedEntry()
97
98         # for summary:
99         def changedEntry(self):
100                 for x in self.onChangedEntry:
101                         x()
102
103         def getCurrentEntry(self):
104                 return self["config"].getCurrent()[0]
105
106         def getCurrentValue(self):
107                 return str(self["config"].getCurrent()[1].getText())
108
109         def createSummary(self):
110                 return SetupSummary
111
112         def addItems(self, list, childNode):
113                 for x in childNode:
114                         if x.nodeType != xml.dom.minidom.Element.nodeType:
115                                 continue
116                         elif x.tagName == 'item':
117                                 item_text = _(x.getAttribute("text").encode("UTF-8") or "??")
118                                 b = eval(XMLTools.mergeText(x.childNodes));
119                                 if b == "":
120                                         continue
121                                 #add to configlist
122                                 item = b
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) )
126
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")