1 from config import config #global config instance
3 from config import configElement
4 from config import ConfigSubsection
5 from config import ConfigSlider
6 from config import configSelection
7 from config import configSequence
8 from config import configsequencearg
9 from config import configSatlist
12 import xml.dom.minidom
13 from xml.dom import EMPTY_NAMESPACE
14 from skin import elementsWithTag
15 from Tools import XMLTools
17 from xml.sax import make_parser
18 from xml.sax.handler import ContentHandler
21 def __init__(self, fnc, *args):
24 def __call__(self, *args):
25 self.fnc(*self.args + args)
28 def __init__(self, slotid, nimtype, name):
30 self.nimType = nimtype
34 class parseSats(ContentHandler):
35 def __init__(self, satList, satellites):
36 self.isPointsElement, self.isReboundsElement = 0, 0
37 self.satList = satList
38 self.satellites = satellites
40 def startElement(self, name, attrs):
42 #print "found sat " + attrs.get('name',"") + " " + str(attrs.get('position',""))
43 tpos = attrs.get('position',"")
44 tname = attrs.get('name',"")
45 self.satellites[tpos] = tname
46 self.satList.append( (tname, tpos) )
48 def readSatsfromFile(self):
52 print "Reading satellites.xml"
53 parser = make_parser()
54 satHandler = self.parseSats(self.satList, self.satellites)
55 parser.setContentHandler(satHandler)
56 parser.parse('/etc/tuxbox/satellites.xml')
58 #satdom = xml.dom.minidom.parse('/etc/tuxbox/satellites.xml')
61 #for entries in elementsWithTag(satdom.childNodes, "satellites"):
62 #for x in elementsWithTag(entries.childNodes, "sat"):
63 ##print "found sat " + x.getAttribute('name') + " " + str(x.getAttribute('position'))
64 #tpos = x.getAttribute('position')
65 #tname = x.getAttribute('name')
66 ##tname.encode('utf8')
67 #self.satellites[tpos] = tname
68 #self.satList.append( (tname, tpos) )
70 def getNimType(self, slotID):
71 #FIXME get it from /proc
73 return self.nimType["DVB-S"]
75 return self.nimType["empty/unknown"]
77 def getNimName(self, slotID):
78 #FIXME get it from /proc
81 def getNimSocketCount(self):
82 #FIXME get it from /proc
85 def getConfigPrefix(self, slotid):
86 return "config.Nim" + ("A","B","C","D")[slotid] + "."
90 self.nimType = { "empty/unknown": -1,
96 self.readSatsfromFile()
98 self.nimCount = self.getNimSocketCount()
102 while x < self.nimCount:
103 tType = self.getNimType(x)
104 tName = self.getNimName(x)
105 tNim = nimSlot(x, tType, tName)
106 self.nimslots.append(tNim)
109 InitNimManager(self) #init config stuff
113 for slot in self.nimslots:
114 nimText = "Socket " + ("A", "B", "C", "D")[slot.slotid] + ": "
115 if slot.nimType == -1:
116 nimText += "empty/unknown"
118 nimText += slot.name + " ("
119 nimText += ("DVB-S", "DVB-C", "DVB-T")[slot.nimType] + ")"
120 list.append((nimText, slot))
123 def getSatListForNim(self, slotid):
124 print "slotid:", slotid
126 print "self.satellites:", self.satList[config.Nims[slotid].diseqcA.value]
127 print "diseqcA:", config.Nims[slotid].diseqcA.value
128 if (config.Nims[slotid].diseqcMode.value <= 3):
129 list.append(self.satList[config.Nims[slotid].diseqcA.value])
130 if (0 < config.Nims[slotid].diseqcMode.value <= 3):
131 list.append(self.satList[config.Nims[slotid].diseqcB.value])
132 if (config.Nims[slotid].diseqcMode.value == 3):
133 list.append(self.satList[config.Nims[slotid].diseqcC.value])
134 list.append(self.satList[config.Nims[slotid].diseqcD.value])
137 #callbacks for c++ config
138 def nimConfigModeChanged(self, slotid, mode):
139 print "nimConfigModeChanged set to " + str(mode)
140 def nimDiseqcModeChanged(self, slotid, mode):
141 print "nimDiseqcModeChanged set to " + str(mode)
142 def nimPortAChanged(self, slotid, val):
143 print "nimDiseqcA set to " + str(val)
144 def nimPortBChanged(self, slotid, val):
145 print "nimDiseqcB set to " + str(val)
146 def nimPortCChanged(self, slotid, val):
147 print "nimDiseqcC set to " + str(val)
148 def nimPortDChanged(self, slotid, val):
149 print "nimDiseqcD set to " + str(val)
152 def InitNimManager(nimmgr):
153 config.Nims = [ConfigSubsection()] * nimmgr.nimCount
155 def nimConfigModeChanged(slotid, configElement):
156 nimmgr.nimConfigModeChanged(slotid, configElement.value)
157 def nimDiseqcModeChanged(slotid, configElement):
158 nimmgr.nimDiseqcModeChanged(slotid, configElement.value)
160 def nimPortAChanged(slotid, configElement):
161 nimmgr.nimPortAChanged(slotid, configElement.vals[configElement.value][1])
162 def nimPortBChanged(slotid, configElement):
163 nimmgr.nimPortBChanged(slotid, configElement.vals[configElement.value][1])
164 def nimPortCChanged(slotid, configElement):
165 nimmgr.nimPortCChanged(slotid, configElement.vals[configElement.value][1])
166 def nimPortDChanged(slotid, configElement):
167 nimmgr.nimPortDChanged(slotid, configElement.vals[configElement.value][1])
169 for slot in nimmgr.nimslots:
171 cname = nimmgr.getConfigPrefix(x)
173 if slot.nimType == nimmgr.nimType["DVB-S"]:
174 config.Nims[x].configMode = configElement(cname + "configMode",configSelection, 0, ("Simple", "Advanced"));
175 config.Nims[x].diseqcMode = configElement(cname + "diseqcMode",configSelection, 2, ("Single", "Toneburst A/B", "DiSEqC A/B", "DiSEqC A/B/C/D", "Positioner"));
176 config.Nims[x].diseqcA = configElement(cname + "diseqcA",configSatlist, 192, nimmgr.satList);
177 config.Nims[x].diseqcB = configElement(cname + "diseqcB",configSatlist, 130, nimmgr.satList);
178 config.Nims[x].diseqcC = configElement(cname + "diseqcC",configSatlist, 0, nimmgr.satList);
179 config.Nims[x].diseqcD = configElement(cname + "diseqcD",configSatlist, 0, nimmgr.satList);
180 config.Nims[x].longitude = configElement(cname + "longitude",configSequence, [0,0], configsequencearg.get("FLOAT", [(0,90),(0,999)]));
181 config.Nims[x].latitude = configElement(cname + "latitude",configSequence, [0,0], configsequencearg.get("FLOAT", [(0,90),(0,999)]));
183 #perhaps the instance of the slot is more useful?
184 config.Nims[x].configMode.addNotifier(boundFunction(nimConfigModeChanged,x))
185 config.Nims[x].diseqcMode.addNotifier(boundFunction(nimDiseqcModeChanged,x))
186 config.Nims[x].diseqcA.addNotifier(boundFunction(nimPortAChanged,x))
187 config.Nims[x].diseqcB.addNotifier(boundFunction(nimPortBChanged,x))
188 config.Nims[x].diseqcC.addNotifier(boundFunction(nimPortCChanged,x))
189 config.Nims[x].diseqcD.addNotifier(boundFunction(nimPortDChanged,x))
191 print "pls add support for this frontend type!"
193 nimmanager = NimManager()