prepare better configSequence
[enigma2.git] / lib / python / Components / NimManager.py
index d806bc3..01ef4bf 100644 (file)
@@ -4,13 +4,19 @@ from config import configElement
 from config import ConfigSubsection
 from config import ConfigSlider
 from config import configSelection
+from config import configSequence
+from config import configsequencearg
 from config import configSatlist
 
+
 import xml.dom.minidom
 from xml.dom import EMPTY_NAMESPACE
 from skin import elementsWithTag
 from Tools import XMLTools
 
+from xml.sax import make_parser
+from xml.sax.handler import ContentHandler
+
 class boundFunction:
        def __init__(self, fnc, *args):
                self.fnc = fnc
@@ -25,21 +31,41 @@ class nimSlot:
                self.name = name
 
 class NimManager:
+       class parseSats(ContentHandler):
+               def __init__(self, satList, satellites):
+                       self.isPointsElement, self.isReboundsElement = 0, 0
+                       self.satList = satList
+                       self.satellites = satellites
+       
+               def startElement(self, name, attrs):
+                       if (name == "sat"):
+                               #print "found sat " + attrs.get('name',"") + " " + str(attrs.get('position',""))
+                               tpos = attrs.get('position',"")
+                               tname = attrs.get('name',"")
+                               self.satellites[tpos] = tname
+                               self.satList.append( (tname, tpos) )
+
        def readSatsfromFile(self):
                self.satellites = { }
+
                #FIXME: path ok???
-               satfile = file('/etc/tuxbox/satellites.xml', 'r')
-               satdom = xml.dom.minidom.parseString(satfile.read())
-               satfile.close()
-
-               for entries in elementsWithTag(satdom.childNodes, "satellites"):
-                       for x in elementsWithTag(entries.childNodes, "sat"):
-                               #print "found sat " + x.getAttribute('name') + " " + str(x.getAttribute('position'))
-                               tpos = x.getAttribute('position')
-                               tname = x.getAttribute('name')
-                               #tname.encode('utf8')
-                               self.satellites[tpos] = tname
-                               self.satList.append( (tname, tpos) )
+               print "Reading satellites.xml"
+               parser = make_parser()
+               satHandler = self.parseSats(self.satList, self.satellites)
+               parser.setContentHandler(satHandler)
+               parser.parse('/etc/tuxbox/satellites.xml')
+    
+               #satdom = xml.dom.minidom.parse('/etc/tuxbox/satellites.xml')
+
+
+               #for entries in elementsWithTag(satdom.childNodes, "satellites"):
+                       #for x in elementsWithTag(entries.childNodes, "sat"):
+                               ##print "found sat " + x.getAttribute('name') + " " + str(x.getAttribute('position'))
+                               #tpos = x.getAttribute('position')
+                               #tname = x.getAttribute('name')
+                               ##tname.encode('utf8')
+                               #self.satellites[tpos] = tname
+                               #self.satList.append( (tname, tpos) )
 
        def getNimType(self, slotID):
                #FIXME get it from /proc
@@ -70,7 +96,7 @@ class NimManager:
                self.readSatsfromFile()                                                                         
                                                                                                
                self.nimCount = self.getNimSocketCount()
-
+               
                self.nimslots = [ ]
                x = 0
                while x < self.nimCount:
@@ -132,11 +158,13 @@ def InitNimManager(nimmgr):
                
                if slot.nimType == nimmgr.nimType["DVB-S"]:
                        config.Nims[x].configMode = configElement(cname + "configMode",configSelection, 0, ("Simple", "Advanced"));
-                       config.Nims[x].diseqcMode = configElement(cname + "diseqcMode",configSelection, 2, ("Single", "Toneburst A/B", "DiSEqC A/B", "DiSEqC A/B/C/D"));
+                       config.Nims[x].diseqcMode = configElement(cname + "diseqcMode",configSelection, 2, ("Single", "Toneburst A/B", "DiSEqC A/B", "DiSEqC A/B/C/D", "Positioner"));
                        config.Nims[x].diseqcA = configElement(cname + "diseqcA",configSatlist, 192, nimmgr.satList);
                        config.Nims[x].diseqcB = configElement(cname + "diseqcB",configSatlist, 130, nimmgr.satList);
                        config.Nims[x].diseqcC = configElement(cname + "diseqcC",configSatlist, 0, nimmgr.satList);
                        config.Nims[x].diseqcD = configElement(cname + "diseqcD",configSatlist, 0, nimmgr.satList);
+                       config.Nims[x].longitude = configElement(cname + "longitude",configSequence, [0,0], configsequencearg.get("FLOAT", [(1,90),(1,999)]));
+                       config.Nims[x].latitude = configElement(cname + "latitude",configSequence, [0,0], configsequencearg.get("FLOAT", [(1,90),(1,999)]));
                        
                        #perhaps the instance of the slot is more useful?
                        config.Nims[x].configMode.addNotifier(boundFunction(nimConfigModeChanged,x))