fix rotor position in infobar for motorized tuner. thx Dimitrij
[openblackhole/openblackhole-enigma2.git] / lib / python / Components / Converter / RotorPosition.py
1 # -*- coding: utf-8 -*-
2 from Converter import Converter
3 from Components.Element import cached
4 from Components.config import config
5 from Tools.Transponder import orbpos
6 from Components.NimManager import nimmanager
7 from enigma import eDVBSatelliteEquipmentControl
8
9 class RotorPosition(Converter, object):
10         DEFAULT = 0
11         WITH_TEXT = 1
12         TUNER_NAME = 2
13
14         def __init__(self, type):
15                 Converter.__init__(self, type)
16                 if type == "WithText":
17                         self.type = self.WITH_TEXT
18                 if type == "TunerName":
19                         self.type = self.TUNER_NAME
20                 else:
21                         self.type = self.DEFAULT
22                 self.LastRotorPos = config.misc.lastrotorposition.value
23                 config.misc.lastrotorposition.addNotifier(self.forceChanged, initial_call=False)
24
25         @cached
26         def getText(self):
27                 self.LastRotorPos = config.misc.lastrotorposition.value
28                 (rotor, tuner) = self.isMotorizedTuner()
29                 if rotor:
30                         self.actualizeCfgLastRotorPosition()
31                         if self.type == self.WITH_TEXT:
32                                 return _("Rotor: ") + orbpos(config.misc.lastrotorposition.value)
33                         if self.type == self.TUNER_NAME:
34                                 active_tuner = self.getActiveTuner()
35                                 if tuner != active_tuner:
36                                         return _("%s:%s") % ("\c0000?0?0" + chr(ord("A")+ tuner), "\c00?0?0?0" + orbpos(config.misc.lastrotorposition.value))
37                                 return ""
38                         return orbpos(config.misc.lastrotorposition.value)
39                 return ""
40
41         text = property(getText)
42
43         def isMotorizedTuner(self):
44                 for x in nimmanager.nim_slots:
45                         for sat in nimmanager.getRotorSatListForNim(x.slot):
46                                 if sat[0]:
47                                         return (True, x.slot)
48                 return (False, None)
49
50         def actualizeCfgLastRotorPosition(self):
51                 if eDVBSatelliteEquipmentControl.getInstance().isRotorMoving():
52                         current_pos = eDVBSatelliteEquipmentControl.getInstance().getTargetOrbitalPosition()
53                         if current_pos != config.misc.lastrotorposition.value:
54                                 self.LastRotorPos = config.misc.lastrotorposition.value = current_pos
55                                 config.misc.lastrotorposition.save()
56
57         def getActiveTuner(self):
58                 if not eDVBSatelliteEquipmentControl.getInstance().isRotorMoving():
59                         service = self.source.service
60                         feinfo = service and service.frontendInfo()
61                         tuner = feinfo and feinfo.getFrontendData()
62                         if tuner:
63                                 return tuner.get("tuner_number")
64                 return ""
65
66         def forceChanged(self, configElement=None):
67                 if self.LastRotorPos != config.misc.lastrotorposition.value:
68                         Converter.changed(self, (self.CHANGED_ALL,))