Merge branch 'vuplus_experimental' of code.vuplus.com:/opt/repository/dvbapp into...
[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 position="center,center" size="560,300" title="Fancontrol Settings in Standby mode" >
14                         <ePixmap pixmap="skin_default/buttons/red.png" position="110,10" size="140,40" alphatest="on" />
15                         <ePixmap pixmap="skin_default/buttons/green.png" position="310,10" size="140,40" alphatest="on" />
16
17                         <widget source="key_red" render="Label" position="110,10" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" foregroundColor="#ffffff" transparent="1" />
18                         <widget source="key_green" render="Label" position="310,10" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" foregroundColor="#ffffff" transparent="1" />
19
20                         <widget name="config" zPosition="2" position="5,70" size="550,200" scrollbarMode="showOnDemand" transparent="1" />
21                         <widget source="current" render="Label" position="150,270" zPosition="1" size="280,30" font="Regular;20" halign="center" valign="center" />
22                 </screen>
23                 """
24
25         def __init__(self,session):
26                 Screen.__init__(self,session)
27                 self.session = session
28                 self["shortcuts"] = ActionMap(["ShortcutActions", "SetupActions" ],
29                 {
30                         "ok": self.keySave,
31                         "cancel": self.keyCancel,
32                         "red": self.keyCancel,
33                         "green": self.keySave,
34                 }, -2)
35                 self.list = []
36                 ConfigListScreen.__init__(self, self.list,session = self.session)
37                 self["key_red"] = StaticText(_("Cancel"))
38                 self["key_green"] = StaticText(_("Save"))
39                 self["current"] = StaticText(_(" "))
40                 self.configSetup()
41                 self.oldfanoffmode = instandbyon.fanoffmode
42                 if instandbyon.fanoffmode is 'ON' :
43                         instandbyon.checkStatusLoopStop()
44
45         def displayCurrentValue(self):
46                 currrent_val = self["config"].getCurrent()[0]+" : "+str(self["config"].getCurrent()[1].value)
47                 self["current"].setText(_(currrent_val))
48                 print currrent_val
49
50         def selectionChanged(self):
51                 if self["config"].getCurrent() == self.pwmEntry:
52                         instandbyon.setPWM(self["config"].getCurrent()[1].value)
53
54         def keyLeft(self):
55                 oldpwmvalue=config.plugins.manualfancontrols.pwmvalue.value
56                 ConfigListScreen.keyLeft(self)
57                 if self["config"].getCurrent() == self.pwmEntry and oldpwmvalue == 5:
58                         self.createSetup()
59                 else:
60                         self.displayCurrentValue()
61                 self.selectionChanged()
62
63         def keyRight(self):
64                 oldpwmvalue=config.plugins.manualfancontrols.pwmvalue.value
65                 ConfigListScreen.keyRight(self)
66                 if self["config"].getCurrent() == self.pwmEntry and oldpwmvalue == 0:
67                         self.createSetup()
68                         while self["config"].getCurrent() != self.pwmEntry:
69                                 self["config"].setCurrentIndex(self["config"].getCurrentIndex()+1)
70                 else:
71                         self.displayCurrentValue()
72                 self.selectionChanged()
73
74         def createSetup(self):
75                 self.list = []
76                 if config.plugins.manualfancontrols.pwmvalue.value > 0:
77                         self.list.append( self.standbyEntry )
78                 self.list.append( self.pwmEntry )
79                 self.list.append( self.periodEntry )
80                 self["config"].list = self.list
81                 self["config"].l.setList(self.list)
82
83         def configSetup(self):
84                 self.standbyEntry = getConfigListEntry(_("FanOFF InStanby"), config.plugins.manualfancontrols.standbymode)
85                 self.pwmEntry = getConfigListEntry(_("PWM value"), config.plugins.manualfancontrols.pwmvalue)
86                 self.periodEntry = getConfigListEntry(_("Status Check Period"), config.plugins.manualfancontrols.checkperiod)
87                 if not self.displayCurrentValue in self["config"].onSelectionChanged:
88                         self["config"].onSelectionChanged.append(self.displayCurrentValue)
89                 self.createSetup()
90
91         def keySave(self):
92                 if instandbyon.fanoffmode is 'OFF' and config.plugins.manualfancontrols.pwmvalue.value == 0:
93                         print "<SimpleFancontrol> instandbyon.fanoffmode 'OFF' -> 'ON'"
94                         instandbyon.fanoffmode = 'ON'
95                         instandbyon.addRecordEventCB()
96                         instandbyon.checkStatusLoopStart()
97                 elif instandbyon.fanoffmode is 'ON' and config.plugins.manualfancontrols.pwmvalue.value != 0:
98                         print "<SimpleFancontrol> instandbyon.fanoffmode 'ON' -> 'OFF'"
99                         instandbyon.fanoffmode = 'OFF'
100                         instandbyon.removeRecordEventCB()
101 #                       instandbyon.checkStatusLoopStop() # stoped at init
102                 elif self.oldfanoffmode is 'ON' :
103                         instandbyon.checkStatusLoopStart()
104                 instandbyon.checkStstus()
105                 ConfigListScreen.keySave(self)
106
107         def cancelConfirm(self, result):
108                 if not result:
109                         return
110                 for x in self["config"].list:
111                         x[1].cancel()
112                 instandbyon.checkStstus()
113                 self.oldfanoffmode = instandbyon.fanoffmode
114                 if self.oldfanoffmode is 'ON' :
115                         instandbyon.checkStatusLoopStart()
116                 self.close()
117
118         def keyCancel(self):
119                 if self["config"].isChanged():
120                         self.session.openWithCallback(self.cancelConfirm, MessageBox, _("Really close without saving settings?"))
121                 else:
122                         instandbyon.checkStstus()
123                         if self.oldfanoffmode is 'ON' :
124                                 instandbyon.checkStatusLoopStart()
125                         self.close()
126
127 def main(session, **kwargs):
128         session.open(ManualFancontrol)
129
130 def Plugins(**kwargs):
131         return [PluginDescriptor(name=_("Manual Fan control"), description="setup Fancontol inStandby mode", where = PluginDescriptor.WHERE_PLUGINMENU, needsRestart = True, fnc=main)]