ManualFancontrol : add fanOFF mode (PWM 0), and so on
[vuplus_dvbapp] / lib / python / Plugins / SystemPlugins / ManualFancontrol / plugin.py
1 from Screens.Screen import Screen
2 from Components.ConfigList import ConfigListScreen
3 from Components.config import config, getConfigListEntry, ConfigSubsection, ConfigSelection, ConfigInteger
4 from Components.ActionMap import ActionMap,NumberActionMap
5 from Screens.MessageBox import MessageBox
6 from Components.Sources.StaticText import StaticText
7 from Plugins.Plugin import PluginDescriptor
8 from Plugins.SystemPlugins.ManualFancontrol.InstandbyOn import instandbyon
9 import NavigationInstance
10
11 class ManualFancontrol(Screen,ConfigListScreen):
12         skin = """
13                         <screen name="ManualFancontrol" position="center,center" size="560,300" title="Fancontrol Settings in Standby mode" >
14                         <ePixmap pixmap="Vu_HD/buttons/red.png" position="10,10" size="25,25" alphatest="on" />
15                         <ePixmap pixmap="Vu_HD/buttons/green.png" position="290,10" size="25,25" alphatest="on" />
16                         <widget source="key_red" render="Label" position="40,10" zPosition="1" size="140,25" font="Regular;20" halign="center" valign="center" transparent="1" />
17                         <widget source="key_green" render="Label" position="320,10" zPosition="1" size="140,25" font="Regular;20" halign="center" valign="center" transparent="1" />
18                         <widget name="config" zPosition="2" position="5,50" size="550,200" scrollbarMode="showOnDemand" transparent="1" />
19                         <widget source="current" render="Label" position="150,270" zPosition="1" size="280,30" font="Regular;20" halign="center" valign="center" transparent="1" />
20                         </screen>"""
21
22         def __init__(self,session):
23                 Screen.__init__(self,session)
24                 self.session = session
25                 self["shortcuts"] = ActionMap(["ShortcutActions", "SetupActions" ],
26                 {
27                         "ok": self.keySave,
28                         "cancel": self.keyCancel,
29                         "red": self.keyCancel,
30                         "green": self.keySave,
31                 }, -2)
32                 self.list = []
33                 ConfigListScreen.__init__(self, self.list,session = self.session)
34                 self["key_red"] = StaticText(_("Cancel"))
35                 self["key_green"] = StaticText(_("Save"))
36                 self["current"] = StaticText(_(" "))
37                 self.configSetup()
38                 self.backup_pwm = instandbyon.getPWM()
39                 self.OnRecording = False
40
41         def isRecording(self):
42                 recordings = NavigationInstance.instance.getRecordings()
43                 if recordings :
44                         return True
45                 else:
46                         return False
47
48         def displayCurrentValue(self):
49                 currrent_val = self["config"].getCurrent()[0]+" : "+str(self["config"].getCurrent()[1].value)
50                 self["current"].setText(_(currrent_val))
51                 print currrent_val
52
53         def selectionChanged(self):
54                 if self["config"].getCurrent() == self.pwmEntry:
55                         instandbyon.setPWM(self["config"].getCurrent()[1].value)
56
57         def keyLeft(self):
58                 oldpwmvalue=config.plugins.simplefancontrols.pwmvalue.value
59                 ConfigListScreen.keyLeft(self)
60                 if self["config"].getCurrent() == self.pwmEntry and oldpwmvalue == 5:
61                         self.createSetup()
62                 else:
63                         self.displayCurrentValue()
64                 self.selectionChanged()
65
66         def keyRight(self):
67                 oldpwmvalue=config.plugins.simplefancontrols.pwmvalue.value
68                 ConfigListScreen.keyRight(self)
69                 if self["config"].getCurrent() == self.pwmEntry and oldpwmvalue == 0:
70                         self.createSetup()
71                         while self["config"].getCurrent() != self.pwmEntry:
72                                 self["config"].setCurrentIndex(self["config"].getCurrentIndex()+1)
73                 else:
74                         self.displayCurrentValue()
75                 self.selectionChanged()
76
77         def createSetup(self):
78                 self.list = []
79                 if config.plugins.simplefancontrols.pwmvalue.value > 0:
80                         self.list.append( self.standbyEntry )
81                 self.list.append( self.pwmEntry )
82                 self["config"].list = self.list
83                 self["config"].l.setList(self.list)
84
85         def configSetup(self):
86                 self.standbyEntry = getConfigListEntry(_("FanOFF InStanby"), config.plugins.simplefancontrols.standbymode)
87                 self.pwmEntry = getConfigListEntry(_("PWM value"), config.plugins.simplefancontrols.pwmvalue)
88                 if not self.displayCurrentValue in self["config"].onSelectionChanged:
89                         self["config"].onSelectionChanged.append(self.displayCurrentValue)
90                 self.createSetup()
91
92         def newConfig(self):
93                 if self["config"].getCurrent() == self.pwmEntry and config.plugins.simplefancontrols.pwmvalue.value == 0:
94                         self.createSetup()
95
96         def keySave(self):
97                 if instandbyon.fanoffmode is 'OFF' and config.plugins.simplefancontrols.pwmvalue.value == 0:
98                         instandbyon.appendRecordEventCallback()
99                         instandbyon.fanoffmode = 'ON'
100                         print "<SimpleFancontrol> instandbyon.fanoffmode 'OFF' -> 'ON'"
101
102                 elif instandbyon.fanoffmode is 'ON' and config.plugins.simplefancontrols.pwmvalue.value != 0:
103                         instandbyon.removeRecordEventCallback()
104                         instandbyon.fanoffmode = 'OFF'
105                         print "<SimpleFancontrol> instandbyon.fanoffmode 'ON' -> 'OFF'"
106                 if instandbyon.fanoffmode == 'ON' and self.isRecording() and instandbyon.getPWM() != instandbyon.default_pwm_value_onRecordings:
107                         instandbyon.setPWM(instandbyon.default_pwm_value_onRecordings)
108                 ConfigListScreen.keySave(self)
109
110         def cancelConfirm(self, result):
111                 if not result:
112                         return
113                 for x in self["config"].list:
114                         x[1].cancel()
115                 if instandbyon.fanoffmode == 'ON' and self.isRecording():
116                         if instandbyon.getPWM() != instandbyon.default_pwm_value_onRecordings:
117                                 instandbyon.setPWM(instandbyon.default_pwm_value_onRecordings)
118                         else:
119                                 pass
120                 else:
121                         instandbyon.setPWM(config.plugins.simplefancontrols.pwmvalue.value)
122                 self.close()
123
124         def keyCancel(self):
125                 if self["config"].isChanged():
126                         self.session.openWithCallback(self.cancelConfirm, MessageBox, _("Really close without saving settings?"))
127                 else:
128                         if instandbyon.fanoffmode == 'ON' and self.isRecording() and instandbyon.getPWM() != instandbyon.default_pwm_value_onRecordings:
129                                 instandbyon.setPWM(instandbyon.default_pwm_value_onRecordings)
130                         self.close()
131
132 def main(session, **kwargs):
133         session.open(ManualFancontrol)
134
135 def Plugins(**kwargs):
136         return [PluginDescriptor(name=_("Manual Fan control"), description="setup Fancontol inStandby mode", where = PluginDescriptor.WHERE_PLUGINMENU, needsRestart = True, fnc=main)]