1 from Plugins.Plugin import PluginDescriptor
3 from Screens.Screen import Screen
4 from Components.ActionMap import ActionMap
5 from Components.Label import Label
6 from Components.Sources.StaticText import StaticText
8 from Screens.ChoiceBox import ChoiceBox
9 from Screens.MessageBox import MessageBox
10 from Screens.Standby import TryQuitMainloop
12 from Components.PluginComponent import plugins
14 from Components.ConfigList import ConfigListScreen
15 from Components.config import config, getConfigListEntry, ConfigSubsection, ConfigYesNo, ConfigSelection
19 _deviseWOL = "/proc/stb/fp/wol"
21 _flagForceEnable = False
22 _flagSupportWol = _flagForceEnable and True or os.path.exists(_deviseWOL)
24 _tryQuitTable = {"deepstandby":1, "reboot":2, "guirestart":3}
28 config.plugins.wolconfig = ConfigSubsection()
29 config.plugins.wolconfig.activate = ConfigYesNo(default = False)
30 config.plugins.wolconfig.location = ConfigSelection(default = "menu", choices = [("menu", _("Show on the Standby Menu")), ("deepstandby", _("Run at the Deep Standby"))])
32 class WOLSetup(ConfigListScreen, Screen):
34 <screen name="WOLSetup" position="center,120" size="600,390" title="WakeOnLan Setup">
35 <ePixmap pixmap="skin_default/buttons/red.png" position="5,0" size="140,40" alphatest="on" />
36 <ePixmap pixmap="skin_default/buttons/green.png" position="155,0" size="140,40" alphatest="on" />
37 <ePixmap pixmap="skin_default/buttons/yellow.png" position="305,0" size="140,40" alphatest="on" />
38 <ePixmap pixmap="skin_default/buttons/blue.png" position="455,0" size="140,40" alphatest="on" />
40 <widget source="key_red" render="Label" position="5,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" foregroundColor="#ffffff" transparent="1" />
41 <widget source="key_green" render="Label" position="155,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" foregroundColor="#ffffff" transparent="1" />
42 <widget source="key_yellow" render="Label" position="305,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#a08500" foregroundColor="#ffffff" transparent="1" />
43 <widget source="key_blue" render="Label" position="455,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#18188b" foregroundColor="#ffffff" transparent="1" />
45 <widget name="config" position="5,70" size="590,280" scrollbarMode="showOnDemand" />
46 <widget name="introduction" position="5,365" size="590,20" font="Regular;20" halign="center" />
49 def __init__(self, session):
51 self.session = session
52 Screen.__init__(self, session)
53 ConfigListScreen.__init__(self, self.configlist)
55 self["actions"] = ActionMap(["OkCancelActions", "ColorActions", "WizardActions"], {
56 "cancel": self.OnKeyCancel,
57 "green" : self.OnKeyGreen,
58 "red" : self.OnKeyRed,
59 "blue" : self.OnKeyBlue,
62 self["key_red"] = StaticText(_("Close"))
63 self["key_green"] = StaticText(_("Save"))
64 self["key_yellow"] = StaticText(_(" "))
65 self["key_blue"] = StaticText(_("Default"))
67 self["introduction"] = Label(_(" "))
69 self.default = {"activate":False, "location":"menu"}
71 "activate":config.plugins.wolconfig.activate.value,
72 "location":config.plugins.wolconfig.location.value,
77 def MakeConfigList(self):
78 self.UpdateConfigList()
80 def UpdateConfigList(self):
83 self.configlist.append(getConfigListEntry(_("WakeOnLan Enable"), config.plugins.wolconfig.activate))
84 if config.plugins.wolconfig.activate.value:
85 self.configlist.append(getConfigListEntry(_(" - Location"), config.plugins.wolconfig.location))
87 self["config"].list = self.configlist
88 self["config"].l.setList(self.configlist)
91 config.plugins.wolconfig.activate.save()
92 config.plugins.wolconfig.location.save()
93 config.plugins.wolconfig.save()
98 print "[WOLSetup] Restore :", self.backup
99 config.plugins.wolconfig.activate.value = self.backup["activate"]
100 config.plugins.wolconfig.location.value = self.backup["location"]
102 def OnKeyGreenCB(self, answer):
103 answer = answer and answer[1]
110 def OnKeyGreen(self):
111 if config.plugins.wolconfig.activate.value == self.backup["activate"] and config.plugins.wolconfig.location.value == self.backup["location"]:
114 if not config.plugins.wolconfig.activate.value:
115 WOLSetup.ActivateWOL(False, True)
120 message = _("If WOL is enabled, power consumption will be around 2W.\nErP Standby Power Regulation (<0.5W at standby) cannot be met.\nProceed?")
121 self.session.openWithCallback(self.OnKeyGreenCB, ChoiceBox, title=message, list=((_("Yes"), "y"), (_("No"), "n"),))
123 def OnKeyCancel(self):
131 print "[WOLSetup] Set Default :", self.default
132 config.plugins.wolconfig.activate.value = self.default["activate"]
133 config.plugins.wolconfig.location.value = self.default["location"]
134 self.UpdateConfigList()
137 ConfigListScreen.keyLeft(self)
138 self.UpdateConfigList()
141 ConfigListScreen.keyRight(self)
142 self.UpdateConfigList()
145 def ActivateWOL(self=None, enable=True, writeDevice=False):
146 print "[WOLSetup] Support :", _flagSupportWol, " Enable :", enable ," WriteDevice :", writeDevice
147 if not _flagSupportWol:
150 os.system('echo "%s" > %s' % (enable and "enable" or "disble",_deviseWOL))
151 os.system("ethtool -s %s wol %s" % (_ethDevice, enable and "g" or "d"))
154 def DeepStandbyNotifierCB(self=None):
155 if config.plugins.wolconfig.activate.value:
156 if config.plugins.wolconfig.location.value == "deepstandby":
157 print "[WOLSetup] Deep Standby with WOL."
158 WOLSetup.ActivateWOL(writeDevice=True)
159 else: print "[WOLSetup] Deep Standby without WOL."
160 else: print "[WOLSetup] Nomal Deep Standby."
162 def SessionStartMain(session, **kwargs):
163 config.misc.DeepStandbyOn.addNotifier(WOLSetup.DeepStandbyNotifierCB, initial_call=False)
165 def PluginMain(session, **kwargs):
166 session.open(WOLSetup)
168 def DeepStandbyWOLMain(session, **kwargs):
169 WOLSetup.ActivateWOL(session, writeDevice=True)
170 session.open(TryQuitMainloop, _tryQuitTable["deepstandby"])
172 def MenuSelected(selected, **kwargs):
173 if selected == "system":
174 return [(_("WakeOnLan Setup"), PluginMain, "wolconfig", 80)]
175 if selected == "shutdown" and config.plugins.wolconfig.activate.value and config.plugins.wolconfig.location.value == "menu":
176 return [(_("Deep Standby with WOL"), DeepStandbyWOLMain, "deep_standby_wol", 80)]
179 def Plugins(**kwargs):
180 if not _flagSupportWol: return []
182 l.append(PluginDescriptor(name=_("WakeOnLan Setup"), where=PluginDescriptor.WHERE_EXTENSIONSMENU, needsRestart=True, fnc=PluginMain))
183 l.append(PluginDescriptor(where=PluginDescriptor.WHERE_SESSIONSTART, fnc=SessionStartMain))
184 l.append(PluginDescriptor(where=PluginDescriptor.WHERE_MENU, fnc=MenuSelected))