Merge branch 'vuplus_experimental' of /opt/repository/enigma2 into vuplus_experimental
[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.oldfanoffmode = instandbyon.fanoffmode
39                 if instandbyon.fanoffmode is 'ON' :
40                         instandbyon.checkStatusLoopStop()
41
42         def displayCurrentValue(self):
43                 currrent_val = self["config"].getCurrent()[0]+" : "+str(self["config"].getCurrent()[1].value)
44                 self["current"].setText(_(currrent_val))
45                 print currrent_val
46
47         def selectionChanged(self):
48                 if self["config"].getCurrent() == self.pwmEntry:
49                         instandbyon.setPWM(self["config"].getCurrent()[1].value)
50
51         def keyLeft(self):
52                 oldpwmvalue=config.plugins.manualfancontrols.pwmvalue.value
53                 ConfigListScreen.keyLeft(self)
54                 if self["config"].getCurrent() == self.pwmEntry and oldpwmvalue == 5:
55                         self.createSetup()
56                 else:
57                         self.displayCurrentValue()
58                 self.selectionChanged()
59
60         def keyRight(self):
61                 oldpwmvalue=config.plugins.manualfancontrols.pwmvalue.value
62                 ConfigListScreen.keyRight(self)
63                 if self["config"].getCurrent() == self.pwmEntry and oldpwmvalue == 0:
64                         self.createSetup()
65                         while self["config"].getCurrent() != self.pwmEntry:
66                                 self["config"].setCurrentIndex(self["config"].getCurrentIndex()+1)
67                 else:
68                         self.displayCurrentValue()
69                 self.selectionChanged()
70
71         def createSetup(self):
72                 self.list = []
73                 if config.plugins.manualfancontrols.pwmvalue.value > 0:
74                         self.list.append( self.standbyEntry )
75                 self.list.append( self.pwmEntry )
76                 self.list.append( self.periodEntry )
77                 self["config"].list = self.list
78                 self["config"].l.setList(self.list)
79
80         def configSetup(self):
81                 self.standbyEntry = getConfigListEntry(_("FanOFF InStanby"), config.plugins.manualfancontrols.standbymode)
82                 self.pwmEntry = getConfigListEntry(_("PWM value"), config.plugins.manualfancontrols.pwmvalue)
83                 self.periodEntry = getConfigListEntry(_("Status Check Period"), config.plugins.manualfancontrols.checkperiod)
84                 if not self.displayCurrentValue in self["config"].onSelectionChanged:
85                         self["config"].onSelectionChanged.append(self.displayCurrentValue)
86                 self.createSetup()
87
88         def keySave(self):
89                 if instandbyon.fanoffmode is 'OFF' and config.plugins.manualfancontrols.pwmvalue.value == 0:
90                         print "<SimpleFancontrol> instandbyon.fanoffmode 'OFF' -> 'ON'"
91                         instandbyon.fanoffmode = 'ON'
92                         instandbyon.addRecordEventCB()
93                         instandbyon.checkStatusLoopStart()
94                 elif instandbyon.fanoffmode is 'ON' and config.plugins.manualfancontrols.pwmvalue.value != 0:
95                         print "<SimpleFancontrol> instandbyon.fanoffmode 'ON' -> 'OFF'"
96                         instandbyon.fanoffmode = 'OFF'
97                         instandbyon.removeRecordEventCB()
98 #                       instandbyon.checkStatusLoopStop() # stoped at init
99                 elif self.oldfanoffmode is 'ON' :
100                         instandbyon.checkStatusLoopStart()
101                 instandbyon.checkStstus()
102                 ConfigListScreen.keySave(self)
103
104         def cancelConfirm(self, result):
105                 if not result:
106                         return
107                 for x in self["config"].list:
108                         x[1].cancel()
109                 instandbyon.checkStstus()
110                 self.oldfanoffmode = instandbyon.fanoffmode
111                 if self.oldfanoffmode is 'ON' :
112                         instandbyon.checkStatusLoopStart()
113                 self.close()
114
115         def keyCancel(self):
116                 if self["config"].isChanged():
117                         self.session.openWithCallback(self.cancelConfirm, MessageBox, _("Really close without saving settings?"))
118                 else:
119                         instandbyon.checkStstus()
120                         if self.oldfanoffmode is 'ON' :
121                                 instandbyon.checkStatusLoopStart()
122                         self.close()
123
124 def main(session, **kwargs):
125         session.open(ManualFancontrol)
126
127 def Plugins(**kwargs):
128         return [PluginDescriptor(name=_("Manual Fan control"), description="setup Fancontol inStandby mode", where = PluginDescriptor.WHERE_PLUGINMENU, needsRestart = True, fnc=main)]