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"))])
35 def GetHardwareAddr(ethname):
38 sock = socket.socket(socket.AF_PACKET, socket.SOCK_RAW)
39 sock.bind((ethname, 9999))
41 macaddr = ":".join(["%02X" % ord(x) for x in sock.getsockname()[-1]])
42 except Exception, Message:
47 class WOLSetup(ConfigListScreen, Screen):
49 <screen name="WOLSetup" position="center,120" size="600,390" title="WakeOnLan Setup">
50 <ePixmap pixmap="skin_default/buttons/red.png" position="5,0" size="140,40" alphatest="on" />
51 <ePixmap pixmap="skin_default/buttons/green.png" position="155,0" size="140,40" alphatest="on" />
52 <ePixmap pixmap="skin_default/buttons/yellow.png" position="305,0" size="140,40" alphatest="on" />
53 <ePixmap pixmap="skin_default/buttons/blue.png" position="455,0" size="140,40" alphatest="on" />
55 <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" />
56 <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" />
57 <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" />
58 <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" />
60 <widget name="config" position="5,70" size="590,260" scrollbarMode="showOnDemand" />
61 <widget name="introduction" position="5,345" size="590,40" font="Regular;24" halign="center" />
64 def __init__(self, session):
66 self.session = session
67 Screen.__init__(self, session)
68 ConfigListScreen.__init__(self, self.configlist)
70 self["actions"] = ActionMap(["OkCancelActions", "ColorActions", "WizardActions"], {
71 "cancel": self.OnKeyCancel,
72 "green" : self.OnKeyGreen,
73 "red" : self.OnKeyRed,
74 "blue" : self.OnKeyBlue,
77 self["key_red"] = StaticText(_("Close"))
78 self["key_green"] = StaticText(_("Save"))
79 self["key_yellow"] = StaticText(_(" "))
80 self["key_blue"] = StaticText(_("Default"))
81 self["introduction"] = Label(" ")
83 self.default = {"activate":False, "location":"menu"}
85 "activate":config.plugins.wolconfig.activate.value,
86 "location":config.plugins.wolconfig.location.value,
91 def MakeConfigList(self):
92 self.UpdateConfigList()
94 def UpdateConfigList(self):
98 self.configlist.append(getConfigListEntry(_("WakeOnLan Enable"), config.plugins.wolconfig.activate))
99 if config.plugins.wolconfig.activate.value:
100 self.configlist.append(getConfigListEntry(_("Location"), config.plugins.wolconfig.location))
101 macaddr = "HWaddr of %s is %s" % (_ethDevice, NetTool.GetHardwareAddr(_ethDevice))
102 else: macaddr = "Wake on Lan disabled"
103 self["introduction"].setText(macaddr)
105 self["config"].list = self.configlist
106 self["config"].l.setList(self.configlist)
109 config.plugins.wolconfig.activate.save()
110 config.plugins.wolconfig.location.save()
111 config.plugins.wolconfig.save()
112 config.plugins.save()
116 print "[WOLSetup] Restore :", self.backup
117 config.plugins.wolconfig.activate.value = self.backup["activate"]
118 config.plugins.wolconfig.location.value = self.backup["location"]
120 def OnKeyGreenCB(self, answer):
127 def OnKeyGreen(self):
128 if config.plugins.wolconfig.activate.value == self.backup["activate"] and config.plugins.wolconfig.location.value == self.backup["location"]:
131 if not config.plugins.wolconfig.activate.value:
132 WOLSetup.ActivateWOL(False, True)
137 message = _("If WOL is enabled, power consumption will be around 2W.\nErP Standby Power Regulation (<0.5W at standby) cannot be met.\nProceed?")
138 self.session.openWithCallback(self.OnKeyGreenCB, MessageBox, message, MessageBox.TYPE_YESNO, default = True)
140 def OnKeyCancel(self):
148 print "[WOLSetup] Set Default :", self.default
149 config.plugins.wolconfig.activate.value = self.default["activate"]
150 config.plugins.wolconfig.location.value = self.default["location"]
151 self.UpdateConfigList()
154 ConfigListScreen.keyLeft(self)
155 self.UpdateConfigList()
158 ConfigListScreen.keyRight(self)
159 self.UpdateConfigList()
162 def ActivateWOL(self=None, enable=True, writeDevice=False):
163 print "[WOLSetup] Support :", _flagSupportWol, " Enable :", enable ," WriteDevice :", writeDevice
164 if not _flagSupportWol:
167 os.system('echo "%s" > %s' % (enable and "enable" or "disble",_deviseWOL))
170 def DeepStandbyNotifierCB(self=None):
171 if config.plugins.wolconfig.activate.value:
172 if config.plugins.wolconfig.location.value == "deepstandby":
173 print "[WOLSetup] Deep Standby with WOL."
174 WOLSetup.ActivateWOL(writeDevice=True)
175 else: print "[WOLSetup] Deep Standby without WOL."
176 else: print "[WOLSetup] Nomal Deep Standby."
178 def SessionStartMain(session, **kwargs):
179 config.misc.DeepStandbyOn.addNotifier(WOLSetup.DeepStandbyNotifierCB, initial_call=False)
181 def PluginMain(session, **kwargs):
182 session.open(WOLSetup)
184 def DeepStandbyWOLMain(session, **kwargs):
185 WOLSetup.ActivateWOL(session, writeDevice=True)
186 session.open(TryQuitMainloop, _tryQuitTable["deepstandby"])
188 def MenuSelected(selected, **kwargs):
189 if selected == "system":
190 return [(_("WakeOnLan Setup"), PluginMain, "wolconfig", 80)]
191 if selected == "shutdown" and config.plugins.wolconfig.activate.value and config.plugins.wolconfig.location.value == "menu":
192 return [(_("Deep Standby with WOL"), DeepStandbyWOLMain, "deep_standby_wol", 80)]
195 def Plugins(**kwargs):
196 if not _flagSupportWol: return []
198 l.append(PluginDescriptor(name=_("WakeOnLan Setup"), where=PluginDescriptor.WHERE_EXTENSIONSMENU, needsRestart=True, fnc=PluginMain))
199 l.append(PluginDescriptor(where=PluginDescriptor.WHERE_SESSIONSTART, fnc=SessionStartMain))
200 l.append(PluginDescriptor(where=PluginDescriptor.WHERE_MENU, fnc=MenuSelected))