PEP8: Fix whitespace
[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                 self.LastRotorPos = config.misc.lastrotorposition.value
17                 config.misc.lastrotorposition.addNotifier(self.forceChanged, initial_call=False)
18                 config.misc.showrotorposition.addNotifier(self.show_hide, initial_call=False)
19
20         @cached
21         def getText(self):
22                 if config.misc.showrotorposition.value != "no":
23                         self.LastRotorPos = config.misc.lastrotorposition.value
24                         (rotor, tuner) = self.isMotorizedTuner()
25                         if rotor:
26                                 self.actualizeCfgLastRotorPosition()
27                                 if config.misc.showrotorposition.value == "withtext":
28                                         return _("Rotor: ") + orbpos(config.misc.lastrotorposition.value)
29                                 if config.misc.showrotorposition.value == "tunername":
30                                         active_tuner = self.getActiveTuner()
31                                         if tuner != active_tuner:
32                                                 return _("%s:%s") % ("\c0000?0?0" + chr(ord("A")+ tuner), "\c00?0?0?0" + orbpos(config.misc.lastrotorposition.value))
33                                         return ""
34                                 return orbpos(config.misc.lastrotorposition.value)
35                 return ""
36
37         text = property(getText)
38
39         def isMotorizedTuner(self):
40                 for x in nimmanager.nim_slots:
41                         for sat in nimmanager.getRotorSatListForNim(x.slot):
42                                 if sat[0]:
43                                         return (True, x.slot)
44                 return (False, None)
45
46         def actualizeCfgLastRotorPosition(self):
47                 if eDVBSatelliteEquipmentControl.getInstance().isRotorMoving():
48                         current_pos = eDVBSatelliteEquipmentControl.getInstance().getTargetOrbitalPosition()
49                         if current_pos != config.misc.lastrotorposition.value:
50                                 self.LastRotorPos = config.misc.lastrotorposition.value = current_pos
51                                 config.misc.lastrotorposition.save()
52
53         def getActiveTuner(self):
54                 if not eDVBSatelliteEquipmentControl.getInstance().isRotorMoving():
55                         service = self.source.service
56                         feinfo = service and service.frontendInfo()
57                         tuner = feinfo and feinfo.getAll(True)
58                         if tuner:
59                                 num = tuner.get("tuner_number")
60                                 orb_pos = tuner.get("orbital_position")
61                                 if isinstance(num, int) and orb_pos:
62                                         satList = nimmanager.getRotorSatListForNim(num)
63                                         for sat in satList:
64                                                 if sat[0] == orb_pos:
65                                                         return num
66                 return ""
67
68         def forceChanged(self, configElement=None):
69                 if self.LastRotorPos != config.misc.lastrotorposition.value:
70                         Converter.changed(self, (self.CHANGED_ALL,))
71
72         def show_hide(self, configElement=None):
73                 Converter.changed(self, (self.CHANGED_ALL,))