1 from Screens.Wizard import wizardManager, WizardSummary
2 from Screens.WizardLanguage import WizardLanguage
3 from Screens.Rc import Rc
4 from Screens.MessageBox import MessageBox
5 from Components.Pixmap import Pixmap, MovingPixmap, MultiPixmap
6 from Components.Sources.Boolean import Boolean
7 from Components.Network import iNetwork
8 from Tools.Directories import resolveFilename, SCOPE_PLUGINS, SCOPE_SKIN_IMAGE
9 from enigma import eTimer
12 class NetworkWizard(WizardLanguage, Rc):
14 <screen position="0,0" size="720,576" title="Welcome..." flags="wfNoBorder" >
15 <widget name="text" position="153,40" size="340,300" font="Regular;22" />
16 <widget source="list" render="Listbox" position="53,340" size="440,180" scrollbarMode="showOnDemand" >
17 <convert type="StringList" />
19 <widget name="config" position="53,340" zPosition="1" size="440,180" transparent="1" scrollbarMode="showOnDemand" />
20 <ePixmap pixmap="skin_default/buttons/button_red.png" position="40,225" zPosition="0" size="15,16" transparent="1" alphatest="on" />
21 <widget name="languagetext" position="55,225" size="95,30" font="Regular;18" />
22 <widget name="wizard" pixmap="skin_default/wizard.png" position="40,50" zPosition="10" size="110,174" alphatest="on" />
23 <widget name="rc" pixmaps="skin_default/rc.png,skin_default/rcold.png" position="500,50" zPosition="10" size="154,500" alphatest="on" />
24 <widget name="arrowdown" pixmap="skin_default/arrowdown.png" position="-100,-100" zPosition="11" size="37,70" alphatest="on" />
25 <widget name="arrowdown2" pixmap="skin_default/arrowdown.png" position="-100,-100" zPosition="11" size="37,70" alphatest="on" />
26 <widget name="arrowup" pixmap="skin_default/arrowup.png" position="-100,-100" zPosition="11" size="37,70" alphatest="on" />
27 <widget name="arrowup2" pixmap="skin_default/arrowup.png" position="-100,-100" zPosition="11" size="37,70" alphatest="on" />
28 <widget source="VKeyIcon" render="Pixmap" pixmap="skin_default/buttons/key_text.png" position="40,260" zPosition="0" size="35,25" transparent="1" alphatest="on" >
29 <convert type="ConditionalShowHide" />
31 <widget name="HelpWindow" pixmap="skin_default/buttons/key_text.png" position="125,170" zPosition="1" size="1,1" transparent="1" alphatest="on" />
33 def __init__(self, session, interface = None):
34 self.xmlfile = resolveFilename(SCOPE_PLUGINS, "SystemPlugins/NetworkWizard/networkwizard.xml")
35 WizardLanguage.__init__(self, session, showSteps = False, showStepSlider = False)
37 self.session = session
38 self["wizard"] = Pixmap()
39 self["HelpWindow"] = Pixmap()
40 self["HelpWindow"].hide()
41 self["VKeyIcon"] = Boolean(False)
43 self.InstalledInterfaceCount = None
44 self.Adapterlist = None
45 self.InterfaceState = None
46 self.isInterfaceUp = None
47 self.WlanPluginInstalled = False
50 if interface is not None:
51 self.selectedInterface = interface
53 self.selectedInterface = None
57 self.AdapterRef = None
63 self.originalInterfaceState = {}
64 self.originalInterfaceStateChanged = False
66 self.rescanTimer = eTimer()
67 self.rescanTimer.callback.append(self.rescanTimerFired)
68 self.getInstalledInterfaceCount()
69 self.isWlanPluginInstalled()
71 def exitWizardQuestion(self, ret = False):
79 self.checkOldInterfaceState()
83 self.rescanTimer.stop()
84 if self.w is not None:
85 from Plugins.SystemPlugins.WirelessLan.Wlan import iWlan
86 iWlan.stopGetNetworkList()
89 def getInstalledInterfaceCount(self):
90 self.originalInterfaceState = {}
92 self.Adapterlist = iNetwork.getAdapterList()
93 self.InstalledInterfaceCount = len(self.Adapterlist)
94 if self.Adapterlist is not None:
95 if self.InstalledInterfaceCount == 1 and self.selectedInterface is None:
96 self.selectedInterface = self.Adapterlist[0]
97 for interface in iNetwork.getAdapterList():
98 self.originalInterfaceState[interface] = {}
99 self.originalInterfaceState[interface]["up"] = iNetwork.getAdapterAttribute(interface, 'up')
101 def selectInterface(self):
102 self.InterfaceState = None
103 if self.selectedInterface is None:
104 if self.InstalledInterfaceCount <= 1:
105 if not iNetwork.isWirelessInterface(self.selectedInterface):
106 self.NextStep = 'nwconfig'
108 self.NextStep = 'scanwlan'
109 self.checkInterface(self.selectedInterface)
111 self.NextStep = 'selectinterface'
112 self.currStep = self.getStepWithID(self.NextStep)
113 self.afterAsyncCode()
115 if not iNetwork.isWirelessInterface(self.selectedInterface):
116 self.NextStep = 'nwconfig'
118 self.NextStep = 'scanwlan'
119 self.checkInterface(self.selectedInterface)
121 def checkOldInterfaceState(self):
122 # disable up interface if it was originally down and config is unchanged.
123 if self.originalInterfaceStateChanged is False:
124 for interface in self.originalInterfaceState.keys():
125 if self.originalInterfaceState[interface]["up"] is False:
126 if iNetwork.checkforInterface(interface) is True:
127 system("ifconfig " + interface + " down")
129 def listInterfaces(self):
131 self.checkOldInterfaceState()
132 list = [(iNetwork.getFriendlyAdapterName(x),x) for x in iNetwork.getAdapterList()]
133 list.append((_("Exit network wizard"), "end"))
136 def InterfaceSelectionMade(self, index):
137 self.selectedInterface = index
138 self.InterfaceSelect(index)
140 def InterfaceSelect(self, index):
142 self.NextStep = 'end'
143 elif index == 'eth0':
144 self.NextStep = 'nwconfig'
146 self.NextStep = 'scanwlan'
148 def InterfaceSelectionMoved(self):
149 self.InterfaceSelect(self.selection)
151 def checkInterface(self,iface):
153 if self.Adapterlist is None:
154 self.Adapterlist = iNetwork.getAdapterList()
155 if self.NextStep is not 'end':
156 if len(self.Adapterlist) == 0:
157 #Reset Network to defaults if network broken
158 iNetwork.resetNetworkConfig('lan', self.resetNetworkConfigCB)
159 self.resetRef = self.session.openWithCallback(self.resetNetworkConfigFinished, MessageBox, _("Please wait while we prepare your network interfaces..."), type = MessageBox.TYPE_INFO, enable_input = False)
160 if iface in iNetwork.getInstalledAdapters():
161 if iface in iNetwork.configuredNetworkAdapters and len(iNetwork.configuredNetworkAdapters) == 1:
162 if iNetwork.getAdapterAttribute(iface, 'up') is True:
163 self.isInterfaceUp = True
165 self.isInterfaceUp = False
166 self.currStep = self.getStepWithID(self.NextStep)
167 self.afterAsyncCode()
169 self.isInterfaceUp = iNetwork.checkforInterface(iface)
170 self.currStep = self.getStepWithID(self.NextStep)
171 self.afterAsyncCode()
173 self.resetNetworkConfigFinished(False)
175 def resetNetworkConfigFinished(self,data):
177 self.currStep = self.getStepWithID(self.NextStep)
178 self.afterAsyncCode()
180 self.currStep = self.getStepWithID(self.NextStep)
181 self.afterAsyncCode()
183 def resetNetworkConfigCB(self,callback,iface):
184 if callback is not None:
186 iNetwork.getInterfaces(self.getInterfacesFinished)
188 def getInterfacesFinished(self, data):
190 if iNetwork.getAdapterAttribute(self.selectedInterface, 'up') is True:
191 self.isInterfaceUp = True
193 self.isInterfaceUp = False
194 self.resetRef.close(True)
196 print "we should never come here!"
198 def AdapterSetupEnd(self, iface):
199 self.originalInterfaceStateChanged = True
200 if iNetwork.getAdapterAttribute(iface, "dhcp") is True:
201 iNetwork.checkNetworkState(self.AdapterSetupEndFinished)
202 self.AdapterRef = self.session.openWithCallback(self.AdapterSetupEndCB, MessageBox, _("Please wait while we test your network..."), type = MessageBox.TYPE_INFO, enable_input = False)
204 self.currStep = self.getStepWithID("confdns")
205 self.afterAsyncCode()
207 def AdapterSetupEndCB(self,data):
209 if iNetwork.isWirelessInterface(self.selectedInterface):
210 if self.WlanPluginInstalled == True:
211 from Plugins.SystemPlugins.WirelessLan.Wlan import iStatus
212 iStatus.getDataForInterface(self.selectedInterface,self.checkWlanStateCB)
214 self.currStep = self.getStepWithID("checklanstatusend")
215 self.afterAsyncCode()
217 self.currStep = self.getStepWithID("checklanstatusend")
218 self.afterAsyncCode()
220 def AdapterSetupEndFinished(self,data):
222 self.InterfaceState = True
224 self.InterfaceState = False
225 self.AdapterRef.close(True)
227 def checkWlanStateCB(self,data,status):
230 if status is not None:
231 text1 = _("Your Dreambox is now ready to use.\n\nYour internet connection is working now.\n\n")
232 text2 = _('Accesspoint:') + "\t" + str(status[self.selectedInterface]["acesspoint"]) + "\n"
233 text3 = _('SSID:') + "\t" + str(status[self.selectedInterface]["essid"]) + "\n"
234 text4 = _('Link Quality:') + "\t" + str(status[self.selectedInterface]["quality"])+ "\n"
235 text5 = _('Signal Strength:') + "\t" + str(status[self.selectedInterface]["signal"]) + "\n"
236 text6 = _('Bitrate:') + "\t" + str(status[self.selectedInterface]["bitrate"]) + "\n"
237 text7 = _('Encryption:') + " " + str(status[self.selectedInterface]["encryption"]) + "\n"
238 text8 = _("Please press OK to continue.")
239 infotext = text1 + text2 + text3 + text4 + text5 + text7 +"\n" + text8
240 self.currStep = self.getStepWithID("checkWlanstatusend")
242 if str(status[self.selectedInterface]["acesspoint"]) == "Not-Associated":
243 self.InterfaceState = False
244 self.afterAsyncCode()
246 def checkNetwork(self):
247 iNetwork.checkNetworkState(self.checkNetworkStateCB)
248 self.checkRef = self.session.openWithCallback(self.checkNetworkCB, MessageBox, _("Please wait while we test your network..."), type = MessageBox.TYPE_INFO, enable_input = False)
250 def checkNetworkCB(self,data):
252 if iNetwork.isWirelessInterface(self.selectedInterface):
253 if self.WlanPluginInstalled == True:
254 from Plugins.SystemPlugins.WirelessLan.Wlan import iStatus
255 iStatus.getDataForInterface(self.selectedInterface,self.checkWlanStateCB)
257 self.currStep = self.getStepWithID("checklanstatusend")
258 self.afterAsyncCode()
260 self.currStep = self.getStepWithID("checklanstatusend")
261 self.afterAsyncCode()
263 def checkNetworkStateCB(self,data):
265 self.InterfaceState = True
267 self.InterfaceState = False
268 self.checkRef.close(True)
270 def rescanTimerFired(self):
271 self.rescanTimer.stop()
274 def updateAPList(self):
275 self.oldlist = self.APList
279 currentListEntry = None
280 newList = self.listAccessPoints()
282 for oldentry in self.oldlist:
283 if oldentry not in newList:
284 newList.append(oldentry)
286 for newentry in newList:
287 if newentry[1] == "<hidden>":
289 self.newAPlist.append(newentry)
291 if len(self.newAPlist):
292 if "<hidden>" not in self.newAPlist:
293 self.newAPlist.append(( _("enter hidden network SSID"), "<hidden>" ))
295 if (self.wizard[self.currStep].has_key("dynamiclist")):
296 currentListEntry = self["list"].getCurrent()
298 for entry in self.newAPlist:
299 if entry == currentListEntry:
302 self.wizard[self.currStep]["evaluatedlist"] = self.newAPlist
303 self['list'].setList(self.newAPlist)
304 self["list"].setIndex(newListIndex)
305 self["list"].updateList(self.newAPlist)
307 def listAccessPoints(self):
309 if self.WlanPluginInstalled is False:
310 self.APList.append( ( _("No networks found"),_("unavailable") ) )
314 from Plugins.SystemPlugins.WirelessLan.Wlan import iWlan
315 iWlan.setInterface(self.selectedInterface)
316 self.w = iWlan.getInterface()
317 aps = iWlan.getNetworkList()
320 self.APList.append( ( _("No networks found"),_("unavailable") ) )
324 print "[NetworkWizard.py] got Accespoints!"
330 tmplist.append( (a['bssid'], a['essid']) )
331 complist.append( (a['bssid'], a['essid']) )
333 for entry in tmplist:
335 for compentry in complist:
336 if compentry[0] == entry[0]:
337 complist.remove(compentry)
338 for entry in complist:
339 self.APList.append( (entry[1], entry[1]) )
341 if "<hidden>" not in self.APList:
342 self.APList.append(( _("enter hidden network SSID"), "<hidden>" ))
344 self.rescanTimer.start(5000)
347 def AccessPointsSelectionMade(self, index):
350 if (self.wizard[self.currStep].has_key("dynamiclist")):
351 for entry in self['list'].list:
352 if entry[1] == "<hidden>":
354 self.WlanList.append( (entry[1], entry[0]) )
355 self.AccessPointsSelect(index)
357 def AccessPointsSelect(self, index):
358 self.NextStep = 'wlanconfig'
360 def AccessPointsSelectionMoved(self):
361 self.AccessPointsSelect(self.selection)
363 def checkWlanSelection(self):
365 self.currStep = self.getStepWithID(self.NextStep)
367 def isWlanPluginInstalled(self):
369 from Plugins.SystemPlugins.WirelessLan.Wlan import iWlan
371 self.WlanPluginInstalled = False
373 self.WlanPluginInstalled = True
375 def listChoices(self):
378 if self.WlanPluginInstalled == True:
379 list.append((_("Configure your wireless LAN again"), "scanwlan"))
380 list.append((_("Configure your internal LAN"), "nwconfig"))
381 list.append((_("Exit network wizard"), "end"))
384 def ChoicesSelectionMade(self, index):
385 self.ChoicesSelect(index)
387 def ChoicesSelect(self, index):
389 self.NextStep = 'end'
390 elif index == 'nwconfig':
391 self.selectedInterface = "eth0"
392 self.NextStep = 'nwconfig'
394 self.NextStep = 'scanwlan'
396 def ChoicesSelectionMoved(self):