modify skin of plugins.
[vuplus_dvbapp] / lib / python / Plugins / SystemPlugins / Fancontrol / plugin.py
1 from Screens.Screen import Screen
2 from Screens.MessageBox import MessageBox
3 from Plugins.Plugin import PluginDescriptor
4 from Components.ActionMap import ActionMap,NumberActionMap
5 from Components.config import config
6 from Components.config import config, getConfigListEntry, ConfigInteger, ConfigSubsection, ConfigSelection
7 from Components.ConfigList import ConfigListScreen
8 from Components.ActionMap import ActionMap
9 from Components.Sources.StaticText import StaticText
10
11
12 config.plugins.fancontrols = ConfigSubsection()
13 config.plugins.fancontrols.standbymode = ConfigSelection(default = "off", choices = [
14         ("off", _("off")), ("on", _("on"))])
15 config.plugins.fancontrols.usetimer = ConfigSelection(default = "off", choices = [
16         ("off", _("no")), ("on", _("yes"))])
17 config.plugins.fancontrols.fanontime = ConfigInteger(default = 5, limits = (1, 100))
18 config.plugins.fancontrols.fanofftime = ConfigInteger(default = 60, limits = (1, 100))
19
20 class FancontrolConfiguration(Screen, ConfigListScreen):
21         skin =  """
22                 <screen position="center,center" size="560,300" title="Standbymode Fancontrol settings" >
23                         <ePixmap pixmap="skin_default/buttons/red.png" position="110,10" size="140,40" alphatest="on" />
24                         <ePixmap pixmap="skin_default/buttons/green.png" position="310,10" size="140,40" alphatest="on" />
25
26                         <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" />
27                         <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" />
28
29                         <widget name="config" zPosition="2" position="5,70" size="550,200" scrollbarMode="showOnDemand" transparent="1" />
30                 </screen>
31                 """
32         def __init__(self, session):
33                 Screen.__init__(self, session)
34                 self.session = session
35                 self.standbyEntry = None
36                 self.usetimerEntry = None
37                 self.fanontimeEntry = None
38                 self.fanofftimeEntry = None
39
40                 self["shortcuts"] = ActionMap(["ShortcutActions", "SetupActions" ],
41                 {
42                         "ok": self.keySave,
43                         "cancel": self.keyCancel,
44                         "red": self.keyCancel,
45                         "green": self.keySave,
46                 }, -2)
47
48                 self.list = []
49                 ConfigListScreen.__init__(self, self.list,session = self.session)
50 #               self.getFaninfo()
51                 self.createSetup()
52
53                 self["key_red"] = StaticText(_("Close"))
54                 self["key_green"] = StaticText(_("Save"))
55
56         def keyLeft(self):
57                 ConfigListScreen.keyLeft(self)
58                 self.newConfig()
59
60         def keyRight(self):
61                 ConfigListScreen.keyRight(self)
62                 self.newConfig()
63
64         def getFaninfo(self):
65                 try:
66                         value=int(open('/proc/stb/system/standby_fan_off','r').read())
67                         if value is 0:
68                                 config.plugins.fancontrols.standbymode.value="on"
69                         else:
70                                 config.plugins.fancontrols.standbymode.value="off"
71                         value=int(open('/proc/stb/system/use_fan_timer','r').read())
72                         if value is 0:
73                                 config.plugins.fancontrols.usetimer.value = "off"
74                         else:
75                                 config.plugins.fancontrols.usetimer.value = "on"
76                         time=int(open('/proc/stb/system/fan_on_time','r').read())
77                         if time > 0 and time < 101:
78                                 config.plugins.fancontrols.fanontime.value = time
79                         else:
80                                 config.plugins.fancontrols.fanontime.value = 1
81                         time=int(open('/proc/stb/system/fan_off_time','r').read())
82                         if time > 0 and time < 101:
83                                 config.plugins.fancontrols.fanofftime.value = time
84                         else:
85                                 config.plugins.fancontrols.fanofftime.value = 1
86                 except:
87                         print 'Error read proc of fan'
88         
89
90         def createSetup(self):
91                 self.list = []
92                 self.standbyEntry = getConfigListEntry(_("Fan basic action"), config.plugins.fancontrols.standbymode)
93                 self.usetimerEntry = getConfigListEntry(_("Use Fan timer"), config.plugins.fancontrols.usetimer)
94                 self.fanontimeEntry = getConfigListEntry(_("Fan on duration time"), config.plugins.fancontrols.fanontime)
95                 self.fanofftimeEntry = getConfigListEntry(_("Fan off duration time"), config.plugins.fancontrols.fanofftime)
96
97                 self.list.append( self.standbyEntry )
98                 if config.plugins.fancontrols.standbymode.value is "off":
99                         self.list.append( self.usetimerEntry )
100                         if config.plugins.fancontrols.usetimer.value is not "off":
101                                 self.list.append( self.fanontimeEntry )
102                                 self.list.append( self.fanofftimeEntry )
103                 
104                 self["config"].list = self.list
105                 self["config"].l.setList(self.list)
106                 if not self.selectionChanged in self["config"].onSelectionChanged:
107                         self["config"].onSelectionChanged.append(self.selectionChanged)
108
109         def newConfig(self):
110                 if self["config"].getCurrent() == self.usetimerEntry or self["config"].getCurrent() == self.standbyEntry:
111                         self.createSetup()
112
113         def selectionChanged(self):
114                 current = self["config"].getCurrent()
115                 print current
116
117         def cancelConfirm(self, result):
118                 if not result:
119                         return
120                 for x in self["config"].list:
121                         x[1].cancel()
122                 self.close()
123
124                         
125         def keyCancel(self):
126                 print "cancel"
127                 if self["config"].isChanged():
128                         self.session.openWithCallback(self.cancelConfirm, MessageBox, _("Really close without saving settings?"))
129                 else:
130                         self.close()
131
132         def keySave(self):
133                 ConfigListScreen.keySave(self)
134                 try:
135                         if config.plugins.fancontrols.standbymode.value is "on":
136                                 open('/proc/stb/system/standby_fan_off','w').write('0')
137                         else:
138                                 open('/proc/stb/system/standby_fan_off','w').write('1')
139                                 if config.plugins.fancontrols.usetimer.value is "off":
140                                         open('/proc/stb/system/use_fan_timer','w').write('0')
141                                 else:
142                                         open('/proc/stb/system/use_fan_timer','w').write('1')
143                                         open('/proc/stb/system/fan_on_time','w').write('%s'%config.plugins.fancontrols.fanontime.value)
144                                         open('/proc/stb/system/fan_off_time','w').write('%s'%config.plugins.fancontrols.fanofftime.value)
145                 except:
146                         print 'Error write proc of fan'
147                 
148         
149 def openconfig(session, **kwargs):
150         session.open(FancontrolConfiguration)
151
152 def selSetup(menuid, **kwargs):
153         if menuid != "system":
154                 return [ ]
155
156         return [(_("Fan Control"), openconfig, "fancontrol_config", 70)]
157
158 def setfancontrol(reason, **kwargs):
159         try:
160                 if config.plugins.fancontrols.standbymode.value == "on":
161                         open('/proc/stb/system/standby_fan_off','w').write('0')
162                 else:
163                         open('/proc/stb/system/standby_fan_off','w').write('1')
164                         if config.plugins.fancontrols.usetimer.value is "off":
165                                 open('/proc/stb/system/use_fan_timer','w').write('0')
166                         else:
167                                 open('/proc/stb/system/use_fan_timer','w').write('1')
168                                 open('/proc/stb/system/fan_on_time','w').write('%s'%config.plugins.fancontrols.fanontime.value)
169                                 open('/proc/stb/system/fan_off_time','w').write('%s'%config.plugins.fancontrols.fanofftime.value)
170         except:
171                 print 'Error to set fan control'
172
173 def Plugins(**kwargs):
174         return [PluginDescriptor(name = "Fancontrols", description = "check Fan Control settings", where = PluginDescriptor.WHERE_AUTOSTART, fnc = setfancontrol),
175         PluginDescriptor(name=_("Fan control"), description="Fan Control", where = PluginDescriptor.WHERE_MENU, fnc=selSetup)]