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
62 self.originalInterfaceState = {}
63 self.originalInterfaceStateChanged = False
65 self.rescanTimer = eTimer()
66 self.rescanTimer.callback.append(self.rescanTimerFired)
67 self.getInstalledInterfaceCount()
68 self.isWlanPluginInstalled()
70 def exitWizardQuestion(self, ret = False):
78 self.checkOldInterfaceState()
84 WizardLanguage.back(self)
87 self.rescanTimer.stop()
88 if self.w is not None:
89 from Plugins.SystemPlugins.WirelessLan.Wlan import iWlan
90 iWlan.stopGetNetworkList()
93 def getInstalledInterfaceCount(self):
94 self.originalInterfaceState = {}
95 self.Adapterlist = iNetwork.getAdapterList()
96 self.InstalledInterfaceCount = len(self.Adapterlist)
97 if self.Adapterlist is not None:
98 if self.InstalledInterfaceCount == 1 and self.selectedInterface is None:
99 self.selectedInterface = self.Adapterlist[0]
100 for interface in iNetwork.getAdapterList():
101 self.originalInterfaceState[interface] = {}
102 self.originalInterfaceState[interface]["up"] = iNetwork.getAdapterAttribute(interface, 'up')
104 def selectInterface(self):
105 self.InterfaceState = None
106 if self.selectedInterface is None:
107 if self.InstalledInterfaceCount <= 1:
108 if not iNetwork.isWirelessInterface(self.selectedInterface):
109 self.NextStep = 'nwconfig'
111 self.NextStep = 'asknetworktype'
112 self.checkInterface(self.selectedInterface)
114 self.NextStep = 'selectinterface'
115 self.currStep = self.getStepWithID(self.NextStep)
116 self.afterAsyncCode()
118 if not iNetwork.isWirelessInterface(self.selectedInterface):
119 self.NextStep = 'nwconfig'
121 self.NextStep = 'asknetworktype'
122 self.checkInterface(self.selectedInterface)
124 def checkOldInterfaceState(self):
125 # disable up interface if it was originally down and config is unchanged.
126 if self.originalInterfaceStateChanged is False:
127 for interface in self.originalInterfaceState.keys():
128 if interface == self.selectedInterface:
129 if self.originalInterfaceState[interface]["up"] is False:
130 if iNetwork.checkforInterface(interface) is True:
131 system("ifconfig " + interface + " down")
133 def listInterfaces(self):
134 self.checkOldInterfaceState()
135 list = [(iNetwork.getFriendlyAdapterName(x),x) for x in iNetwork.getAdapterList()]
136 list.append((_("Exit network wizard"), "end"))
139 def InterfaceSelectionMade(self, index):
140 self.selectedInterface = index
141 self.InterfaceSelect(index)
143 def InterfaceSelect(self, index):
145 self.NextStep = 'end'
146 elif index == 'eth0':
147 self.NextStep = 'nwconfig'
149 self.NextStep = 'asknetworktype'
151 def InterfaceSelectionMoved(self):
152 self.InterfaceSelect(self.selection)
154 def checkInterface(self,iface):
156 if self.Adapterlist is None:
157 self.Adapterlist = iNetwork.getAdapterList()
158 if self.NextStep is not 'end':
159 if len(self.Adapterlist) == 0:
160 #Reset Network to defaults if network broken
161 iNetwork.resetNetworkConfig('lan', self.resetNetworkConfigCB)
162 self.resetRef = self.session.openWithCallback(self.resetNetworkConfigFinished, MessageBox, _("Please wait while we prepare your network interfaces..."), type = MessageBox.TYPE_INFO, enable_input = False)
163 if iface in iNetwork.getInstalledAdapters():
164 if iface in iNetwork.configuredNetworkAdapters and len(iNetwork.configuredNetworkAdapters) == 1:
165 if iNetwork.getAdapterAttribute(iface, 'up') is True:
166 self.isInterfaceUp = True
168 self.isInterfaceUp = False
169 self.currStep = self.getStepWithID(self.NextStep)
170 self.afterAsyncCode()
172 self.isInterfaceUp = iNetwork.checkforInterface(iface)
173 self.currStep = self.getStepWithID(self.NextStep)
174 self.afterAsyncCode()
176 self.resetNetworkConfigFinished(False)
178 def resetNetworkConfigFinished(self,data):
180 self.currStep = self.getStepWithID(self.NextStep)
181 self.afterAsyncCode()
183 self.currStep = self.getStepWithID(self.NextStep)
184 self.afterAsyncCode()
186 def resetNetworkConfigCB(self,callback,iface):
187 if callback is not None:
189 iNetwork.getInterfaces(self.getInterfacesFinished)
191 def getInterfacesFinished(self, data):
193 if iNetwork.getAdapterAttribute(self.selectedInterface, 'up') is True:
194 self.isInterfaceUp = True
196 self.isInterfaceUp = False
197 self.resetRef.close(True)
199 print "we should never come here!"
201 def AdapterSetupEnd(self, iface):
202 self.originalInterfaceStateChanged = True
203 if iNetwork.getAdapterAttribute(iface, "dhcp") is True:
204 iNetwork.checkNetworkState(self.AdapterSetupEndFinished)
205 self.AdapterRef = self.session.openWithCallback(self.AdapterSetupEndCB, MessageBox, _("Please wait while we test your network..."), type = MessageBox.TYPE_INFO, enable_input = False)
207 self.currStep = self.getStepWithID("confdns")
208 self.afterAsyncCode()
210 def AdapterSetupEndCB(self,data):
212 if iNetwork.isWirelessInterface(self.selectedInterface):
213 if self.WlanPluginInstalled == True:
214 from Plugins.SystemPlugins.WirelessLan.Wlan import iStatus
215 iStatus.getDataForInterface(self.selectedInterface,self.checkWlanStateCB)
217 self.currStep = self.getStepWithID("checklanstatusend")
218 self.afterAsyncCode()
220 self.currStep = self.getStepWithID("checklanstatusend")
221 self.afterAsyncCode()
223 def AdapterSetupEndFinished(self,data):
225 self.InterfaceState = True
227 self.InterfaceState = False
228 self.AdapterRef.close(True)
230 def checkWlanStateCB(self,data,status):
233 if status is not None:
234 text1 = _("Your Dreambox is now ready to use.\n\nYour internet connection is working now.\n\n")
235 text2 = _('Accesspoint:') + "\t" + str(status[self.selectedInterface]["accesspoint"]) + "\n"
236 text3 = _('SSID:') + "\t" + str(status[self.selectedInterface]["essid"]) + "\n"
237 text4 = _('Link Quality:') + "\t" + str(status[self.selectedInterface]["quality"])+ "\n"
238 text5 = _('Signal Strength:') + "\t" + str(status[self.selectedInterface]["signal"]) + "\n"
239 text6 = _('Bitrate:') + "\t" + str(status[self.selectedInterface]["bitrate"]) + "\n"
240 text7 = _('Encryption:') + " " + str(status[self.selectedInterface]["encryption"]) + "\n"
241 text8 = _("Please press OK to continue.")
242 infotext = text1 + text2 + text3 + text4 + text5 + text7 +"\n" + text8
243 self.currStep = self.getStepWithID("checkWlanstatusend")
245 if str(status[self.selectedInterface]["accesspoint"]) == "Not-Associated":
246 self.InterfaceState = False
247 self.afterAsyncCode()
249 def checkNetwork(self):
250 iNetwork.checkNetworkState(self.checkNetworkStateCB)
251 self.checkRef = self.session.openWithCallback(self.checkNetworkCB, MessageBox, _("Please wait while we test your network..."), type = MessageBox.TYPE_INFO, enable_input = False)
253 def checkNetworkCB(self,data):
255 if iNetwork.isWirelessInterface(self.selectedInterface):
256 if self.WlanPluginInstalled == True:
257 from Plugins.SystemPlugins.WirelessLan.Wlan import iStatus
258 iStatus.getDataForInterface(self.selectedInterface,self.checkWlanStateCB)
260 self.currStep = self.getStepWithID("checklanstatusend")
261 self.afterAsyncCode()
263 self.currStep = self.getStepWithID("checklanstatusend")
264 self.afterAsyncCode()
266 def checkNetworkStateCB(self,data):
268 self.InterfaceState = True
270 self.InterfaceState = False
271 self.checkRef.close(True)
273 def rescanTimerFired(self):
274 self.rescanTimer.stop()
277 def updateAPList(self):
278 self.oldlist = self.APList
282 currentListEntry = None
283 newList = self.listAccessPoints()
285 for oldentry in self.oldlist:
286 if oldentry not in newList:
287 newList.append(oldentry)
289 for newentry in newList:
290 self.newAPlist.append(newentry)
292 if len(self.newAPlist):
293 if (self.wizard[self.currStep].has_key("dynamiclist")):
294 currentListEntry = self["list"].getCurrent()
295 if currentListEntry is not None:
297 for entry in self.newAPlist:
298 if entry == currentListEntry:
301 self.wizard[self.currStep]["evaluatedlist"] = self.newAPlist
302 self['list'].setList(self.newAPlist)
303 if newListIndex is not None:
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"), None ) )
312 from Plugins.SystemPlugins.WirelessLan.Wlan import iWlan
313 iWlan.setInterface(self.selectedInterface)
314 self.w = iWlan.getInterface()
315 aps = iWlan.getNetworkList()
317 print "[NetworkWizard.py] got Accespoints!"
323 tmplist.append( (a['bssid'], a['essid']) )
324 complist.append( (a['bssid'], a['essid']) )
326 for entry in tmplist:
328 for compentry in complist:
329 if compentry[0] == entry[0]:
330 complist.remove(compentry)
331 for entry in complist:
332 self.APList.append( (entry[1], entry[1]) )
334 self.APList.append( ( _("No networks found"), None ) )
336 self.rescanTimer.start(4000)
340 def AccessPointsSelectionMoved(self):
341 self.ap = self.selection
342 self.NextStep = 'wlanconfig'
344 def checkWlanSelection(self):
346 self.currStep = self.getStepWithID(self.NextStep)
348 def isWlanPluginInstalled(self):
350 from Plugins.SystemPlugins.WirelessLan.Wlan import iWlan
352 self.WlanPluginInstalled = False
354 self.WlanPluginInstalled = True
356 def listChoices(self):
359 if self.WlanPluginInstalled == True:
360 list.append((_("Configure your wireless LAN again"), "scanwlan"))
361 list.append((_("Configure your internal LAN"), "nwconfig"))
362 list.append((_("Exit network wizard"), "end"))
365 def ChoicesSelectionMade(self, index):
366 self.ChoicesSelect(index)
368 def ChoicesSelect(self, index):
370 self.NextStep = 'end'
371 elif index == 'nwconfig':
372 self.selectedInterface = "eth0"
373 self.NextStep = 'nwconfig'
375 self.NextStep = 'asknetworktype'
377 def ChoicesSelectionMoved(self):