Merge commit 'origin/bug_112_enable_extensions_manager' into experimental
[enigma2.git] / lib / python / Plugins / SystemPlugins / TempFanControl / plugin.py
1 from Components.ActionMap import ActionMap
2 from Components.Sensors import sensors
3 from Components.Sources.Sensor import SensorSource
4 from Components.Sources.StaticText import StaticText
5 from Components.ConfigList import ConfigListScreen
6 from Components.config import getConfigListEntry
7
8 from Screens.Screen import Screen
9
10 from Plugins.Plugin import PluginDescriptor
11 from Components.FanControl import fancontrol
12
13 class TempFanControl(Screen, ConfigListScreen):
14         skin = """
15                 <screen position="90,100" size="570,420" title="Fan Control" >
16                         <ePixmap pixmap="skin_default/buttons/red.png" position="0,0" size="140,40" alphatest="on" />
17                         <ePixmap pixmap="skin_default/buttons/green.png" position="140,0" size="140,40" alphatest="on" />
18                         <ePixmap pixmap="skin_default/buttons/yellow.png" position="280,0" size="140,40" alphatest="on" />
19                         <ePixmap pixmap="skin_default/buttons/blue.png" position="420,0" size="140,40" alphatest="on" />
20                         <widget source="red" render="Label" position="0,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" transparent="1" />
21                         <widget source="green" render="Label" position="140,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" transparent="1" />
22                         <widget source="yellow" render="Label" position="280,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#a08500" transparent="1" />
23                         <widget source="blue" render="Label" position="420,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#18188b" transparent="1" />
24                         
25                         <widget name="config" position="10,50" size="550,90" scrollbarMode="showOnDemand" />
26                         
27                         <widget source="SensorTempText0" render="Label" position="10,150" zPosition="1" size="90,40" font="Regular;20" halign="left" valign="top" backgroundColor="#9f1313" transparent="1" />
28                         <widget source="SensorTemp0" render="Label" position="100,150" zPosition="1" size="100,20" font="Regular;19" halign="right">
29                                 <convert type="SensorToText"></convert>
30                         </widget>
31                         <widget source="SensorTempText1" render="Label" position="10,170" zPosition="1" size="90,40" font="Regular;20" halign="left" valign="top" backgroundColor="#9f1313" transparent="1" />
32                         <widget source="SensorTemp1" render="Label" position="100,170" zPosition="1" size="100,20" font="Regular;19" halign="right">
33                                 <convert type="SensorToText"></convert>
34                         </widget>
35                         <widget source="SensorTempText2" render="Label" position="10,190" zPosition="1" size="90,40" font="Regular;20" halign="left" valign="top" backgroundColor="#9f1313" transparent="1" />
36                         <widget source="SensorTemp2" render="Label" position="100,190" zPosition="1" size="100,20" font="Regular;19" halign="right">
37                                 <convert type="SensorToText"></convert>
38                         </widget>
39                         <widget source="SensorTempText3" render="Label" position="10,210" zPosition="1" size="90,40" font="Regular;20" halign="left" valign="top" backgroundColor="#9f1313" transparent="1" />
40                         <widget source="SensorTemp3" render="Label" position="100,210" zPosition="1" size="100,20" font="Regular;19" halign="right">
41                                 <convert type="SensorToText"></convert>
42                         </widget>
43                         <widget source="SensorTempText4" render="Label" position="10,230" zPosition="1" size="90,40" font="Regular;20" halign="left" valign="top" backgroundColor="#9f1313" transparent="1" />
44                         <widget source="SensorTemp4" render="Label" position="100,230" zPosition="1" size="100,20" font="Regular;19" halign="right">
45                                 <convert type="SensorToText"></convert>
46                         </widget>
47                         <widget source="SensorTempText5" render="Label" position="10,250" zPosition="1" size="90,40" font="Regular;20" halign="left" valign="top" backgroundColor="#9f1313" transparent="1" />
48                         <widget source="SensorTemp5" render="Label" position="100,250" zPosition="1" size="100,20" font="Regular;19" halign="right">
49                                 <convert type="SensorToText"></convert>
50                         </widget>
51                         <widget source="SensorTempText6" render="Label" position="10,270" zPosition="1" size="90,40" font="Regular;20" halign="left" valign="top" backgroundColor="#9f1313" transparent="1" />
52                         <widget source="SensorTemp6" render="Label" position="100,270" zPosition="1" size="100,20" font="Regular;19" halign="right">
53                                 <convert type="SensorToText"></convert>
54                         </widget>
55                         <widget source="SensorTempText7" render="Label" position="10,290" zPosition="1" size="90,40" font="Regular;20" halign="left" valign="top" backgroundColor="#9f1313" transparent="1" />
56                         <widget source="SensorTemp7" render="Label" position="100,290" zPosition="1" size="100,20" font="Regular;19" halign="right">
57                                 <convert type="SensorToText"></convert>
58                         </widget>
59                         
60                         <widget source="SensorFanText0" render="Label" position="290,150" zPosition="1" size="90,40" font="Regular;20" halign="left" valign="top" backgroundColor="#9f1313" transparent="1" />
61                         <widget source="SensorFan0" render="Label" position="380,150" zPosition="1" size="150,20" font="Regular;19" halign="right">
62                                 <convert type="SensorToText"></convert>
63                         </widget>
64                         <widget source="SensorFanText1" render="Label" position="290,170" zPosition="1" size="90,40" font="Regular;20" halign="left" valign="top" backgroundColor="#9f1313" transparent="1" />
65                         <widget source="SensorFan1" render="Label" position="380,170" zPosition="1" size="150,20" font="Regular;19" halign="right">
66                                 <convert type="SensorToText"></convert>
67                         </widget>
68                         <widget source="SensorFanText2" render="Label" position="290,190" zPosition="1" size="90,40" font="Regular;20" halign="left" valign="top" backgroundColor="#9f1313" transparent="1" />
69                         <widget source="SensorFan2" render="Label" position="380,190" zPosition="1" size="150,20" font="Regular;19" halign="right">
70                                 <convert type="SensorToText"></convert>
71                         </widget>
72                         <widget source="SensorFanText3" render="Label" position="290,210" zPosition="1" size="90,40" font="Regular;20" halign="left" valign="top" backgroundColor="#9f1313" transparent="1" />
73                         <widget source="SensorFan3" render="Label" position="380,210" zPosition="1" size="150,20" font="Regular;19" halign="right">
74                                 <convert type="SensorToText"></convert>
75                         </widget>
76                         <widget source="SensorFanText4" render="Label" position="290,230" zPosition="1" size="90,40" font="Regular;20" halign="left" valign="top" backgroundColor="#9f1313" transparent="1" />
77                         <widget source="SensorFan4" render="Label" position="380,230" zPosition="1" size="150,20" font="Regular;19" halign="right">
78                                 <convert type="SensorToText"></convert>
79                         </widget>
80                         <widget source="SensorFanText5" render="Label" position="290,250" zPosition="1" size="90,40" font="Regular;20" halign="left" valign="top" backgroundColor="#9f1313" transparent="1" />
81                         <widget source="SensorFan5" render="Label" position="380,250" zPosition="1" size="150,20" font="Regular;19" halign="right">
82                                 <convert type="SensorToText"></convert>
83                         </widget>
84                         <widget source="SensorFanText6" render="Label" position="290,270" zPosition="1" size="90,40" font="Regular;20" halign="left" valign="top" backgroundColor="#9f1313" transparent="1" />
85                         <widget source="SensorFan6" render="Label" position="380,270" zPosition="1" size="150,20" font="Regular;19" halign="right">
86                                 <convert type="SensorToText"></convert>
87                         </widget>
88                         <widget source="SensorFanText7" render="Label" position="290,290" zPosition="1" size="90,40" font="Regular;20" halign="left" valign="top" backgroundColor="#9f1313" transparent="1" />
89                         <widget source="SensorFan7" render="Label" position="380,290" zPosition="1" size="150,20" font="Regular;19" halign="right">
90                                 <convert type="SensorToText"></convert>
91                         </widget>
92                 </screen>"""
93         
94         def __init__(self, session, args = None):
95                 Screen.__init__(self, session)
96                 
97                 templist = sensors.getSensorsList(sensors.TYPE_TEMPERATURE)
98                 tempcount = len(templist)
99                 fanlist = sensors.getSensorsList(sensors.TYPE_FAN_RPM)
100                 fancount = len(fanlist)
101                 
102                 self["red"] = StaticText(_("Cancel"))
103                 self["green"] = StaticText(_("OK"))
104                 self["yellow"] = StaticText("")
105                 self["blue"] = StaticText("")   
106                 
107                 for count in range(8):
108                         if count < tempcount:
109                                 id = templist[count]
110                                 self["SensorTempText%d" % count] = StaticText(sensors.getSensorName(id))                
111                                 self["SensorTemp%d" % count] = SensorSource(sensorid = id)
112                         else:
113                                 self["SensorTempText%d" % count] = StaticText("")
114                                 self["SensorTemp%d" % count] = SensorSource()
115                                 
116                         if count < fancount:
117                                 id = fanlist[count]
118                                 self["SensorFanText%d" % count] = StaticText(sensors.getSensorName(id))         
119                                 self["SensorFan%d" % count] = SensorSource(sensorid = id)
120                         else:
121                                 self["SensorFanText%d" % count] = StaticText("")
122                                 self["SensorFan%d" % count] = SensorSource()
123                 
124                 self.list = []
125                 for count in range(fancontrol.getFanCount()):
126                         self.list.append(getConfigListEntry(_("Fan %d Voltage") % (count + 1), fancontrol.getConfig(count).vlt))
127                         self.list.append(getConfigListEntry(_("Fan %d PWM") % (count + 1), fancontrol.getConfig(count).pwm))
128                 ConfigListScreen.__init__(self, self.list, session = self.session)
129                 #self["config"].list = self.list
130                 #self["config"].setList(self.list)
131                 
132                 self["actions"] = ActionMap(["OkCancelActions", "ColorActions"], 
133                 {
134                         "ok": self.save,
135                         "cancel": self.revert,
136                         "red": self.revert,
137                         "green": self.save
138                 }, -1)
139                 
140         def save(self):
141                 for count in range(fancontrol.getFanCount()):
142                         fancontrol.getConfig(count).vlt.save()
143                         fancontrol.getConfig(count).pwm.save()
144                 self.close()
145                 
146         def revert(self):
147                 for count in range(fancontrol.getFanCount()):
148                         fancontrol.getConfig(count).vlt.load()
149                         fancontrol.getConfig(count).pwm.load()
150                 self.close()
151                 
152 def main(session, **kwargs):
153         session.open(TempFanControl)
154
155 def startMenu(menuid):
156         if menuid != "system":
157                 return []
158         
159         return [(_("Temperature and Fan control"), main, "tempfancontrol", 80)]
160
161 def Plugins(**kwargs):
162         return PluginDescriptor(name = "Temperature and Fan control", description = _("Temperature and Fan control"), where = PluginDescriptor.WHERE_MENU, fnc = startMenu)
163