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.SystemInfo import SystemInfo
13 from Components.PluginComponent import plugins
15 from Components.ConfigList import ConfigListScreen
16 from Components.config import config, getConfigListEntry, ConfigSubsection, ConfigYesNo, ConfigSelection
17 from Components.Network import iNetwork
21 _deviseWOL = "/proc/stb/fp/wol"
23 _flagForceEnable = False
24 _flagSupportWol = _flagForceEnable and True or os.path.exists(_deviseWOL)
26 _tryQuitTable = {"deepstandby":1, "reboot":2, "guirestart":3}
29 if SystemInfo.get("WOWLSupport", False):
32 config.plugins.wolconfig = ConfigSubsection()
33 config.plugins.wolconfig.activate = ConfigYesNo(default = False)
34 config.plugins.wolconfig.location = ConfigSelection(default = "menu", choices = [("menu", _("Show on the Standby Menu")), ("deepstandby", _("Run at the Deep Standby"))])
39 def GetHardwareAddr(ethname):
42 sock = socket.socket(socket.AF_PACKET, socket.SOCK_RAW)
43 sock.bind((ethname, 9999))
45 macaddr = ":".join(["%02X" % ord(x) for x in sock.getsockname()[-1]])
46 except Exception, Message:
51 class WOLSetup(ConfigListScreen, Screen):
53 <screen name="WOLSetup" position="center,center" size="600,390" title="WakeOnLan Setup">
54 <ePixmap pixmap="skin_default/buttons/red.png" position="5,0" size="140,40" alphatest="on" />
55 <ePixmap pixmap="skin_default/buttons/green.png" position="155,0" size="140,40" alphatest="on" />
56 <ePixmap pixmap="skin_default/buttons/yellow.png" position="305,0" size="140,40" alphatest="on" />
57 <ePixmap pixmap="skin_default/buttons/blue.png" position="455,0" size="140,40" alphatest="on" />
59 <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" />
60 <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" />
61 <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" />
62 <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" />
64 <widget name="config" position="5,70" size="590,260" scrollbarMode="showOnDemand" />
65 <widget name="introduction" position="5,345" size="590,40" font="Regular;24" halign="center" />
68 def __init__(self, session):
70 self.session = session
71 Screen.__init__(self, session)
72 ConfigListScreen.__init__(self, self.configlist)
74 self["actions"] = ActionMap(["OkCancelActions", "ColorActions", "WizardActions"], {
75 "cancel": self.OnKeyCancel,
76 "green" : self.OnKeyGreen,
77 "red" : self.OnKeyRed,
78 "blue" : self.OnKeyBlue,
81 self["key_red"] = StaticText(_("Close"))
82 self["key_green"] = StaticText(_("Save"))
83 self["key_yellow"] = StaticText(_(" "))
84 self["key_blue"] = StaticText(_("Default"))
85 self["introduction"] = Label(" ")
87 self.default = {"activate":False, "location":"menu"}
89 "activate":config.plugins.wolconfig.activate.value,
90 "location":config.plugins.wolconfig.location.value,
95 def MakeConfigList(self):
96 self.UpdateConfigList()
98 def UpdateConfigList(self):
102 self.configlist.append(getConfigListEntry(_("WakeOnLan Enable"), config.plugins.wolconfig.activate))
103 if config.plugins.wolconfig.activate.value:
104 self.configlist.append(getConfigListEntry(_("Location"), config.plugins.wolconfig.location))
105 if SystemInfo.get("WOWLSupport", False):
106 if iNetwork.getAdapterAttribute(_ethDevice, 'up'):
107 macaddr = "HWaddr of %s is %s" % (_ethDevice, NetTool.GetHardwareAddr(_ethDevice))
109 macaddr = "Wireless lan is not activated."
111 macaddr = "HWaddr of %s is %s" % (_ethDevice, NetTool.GetHardwareAddr(_ethDevice))
112 else: macaddr = "Wake on Lan disabled"
113 self["introduction"].setText(macaddr)
115 self["config"].list = self.configlist
116 self["config"].l.setList(self.configlist)
119 config.plugins.wolconfig.activate.save()
120 config.plugins.wolconfig.location.save()
121 config.plugins.wolconfig.save()
122 config.plugins.save()
126 print "[WOLSetup] Restore :", self.backup
127 config.plugins.wolconfig.activate.value = self.backup["activate"]
128 config.plugins.wolconfig.location.value = self.backup["location"]
130 def OnKeyGreenCB(self, answer):
137 def OnKeyGreen(self):
138 if config.plugins.wolconfig.activate.value == self.backup["activate"] and config.plugins.wolconfig.location.value == self.backup["location"]:
141 if not config.plugins.wolconfig.activate.value:
142 WOLSetup.ActivateWOL(False, True)
147 message = _("If WOL is enabled, power consumption will be around 2W.\nErP Standby Power Regulation (<0.5W at standby) cannot be met.\nProceed?")
148 self.session.openWithCallback(self.OnKeyGreenCB, MessageBox, message, MessageBox.TYPE_YESNO, default = True)
150 def OnKeyCancel(self):
158 print "[WOLSetup] Set Default :", self.default
159 config.plugins.wolconfig.activate.value = self.default["activate"]
160 config.plugins.wolconfig.location.value = self.default["location"]
161 self.UpdateConfigList()
164 ConfigListScreen.keyLeft(self)
165 self.UpdateConfigList()
168 ConfigListScreen.keyRight(self)
169 self.UpdateConfigList()
172 def ActivateWOL(self=None, enable=True, writeDevice=False):
173 print "[WOLSetup] Support :", _flagSupportWol, " Enable :", enable ," WriteDevice :", writeDevice
174 if not _flagSupportWol:
177 os.system('echo "%s" > %s' % (enable and "enable" or "disble",_deviseWOL))
180 def DeepStandbyNotifierCB(self=None):
181 if config.plugins.wolconfig.activate.value:
182 if config.plugins.wolconfig.location.value == "deepstandby":
183 print "[WOLSetup] Deep Standby with WOL."
184 WOLSetup.ActivateWOL(writeDevice=True)
185 else: print "[WOLSetup] Deep Standby without WOL."
186 else: print "[WOLSetup] Nomal Deep Standby."
188 def SessionStartMain(session, **kwargs):
189 config.misc.DeepStandbyOn.addNotifier(WOLSetup.DeepStandbyNotifierCB, initial_call=False)
191 def PluginMain(session, **kwargs):
192 session.open(WOLSetup)
194 def DeepStandbyWOLMain(session, **kwargs):
195 WOLSetup.ActivateWOL(session, writeDevice=True)
196 session.open(TryQuitMainloop, _tryQuitTable["deepstandby"])
198 def MenuSelected(selected, **kwargs):
199 if selected == "system":
200 return [(_("WakeOnLan Setup"), PluginMain, "wolconfig", 80)]
201 if selected == "shutdown" and config.plugins.wolconfig.activate.value and config.plugins.wolconfig.location.value == "menu":
202 return [(_("Deep Standby with WOL"), DeepStandbyWOLMain, "deep_standby_wol", 80)]
205 def Plugins(**kwargs):
206 if not _flagSupportWol: return []
208 l.append(PluginDescriptor(name=_("WakeOnLan Setup"), where=PluginDescriptor.WHERE_EXTENSIONSMENU, needsRestart=True, fnc=PluginMain))
209 l.append(PluginDescriptor(where=PluginDescriptor.WHERE_SESSIONSTART, fnc=SessionStartMain))
210 l.append(PluginDescriptor(where=PluginDescriptor.WHERE_MENU, fnc=MenuSelected))