def reInit(self): self.interfaceLock.acquire() self.__activeAp = { 'name': 'None', 'passwd': 'None', 'interface1': 'None', 'interface2': 'None' } self.__status = { 'active': False, 'text': self._('No active AP'), 'button': self._('Connect') } self.errorMsg = {'newMsg': False, 'title': None, 'text': None} self.__statistic = { 'startReceived': None, 'startSending': None, 'receiving': '0', 'totalReceived': '0', 'sending': '0', 'totalSent': '0' } #init Thread self.interfaceThread = TerminalInterface(self.mysignal, signalNewMsg) self.statisticThread = Statistic(self.mysignal, signalUpdateStatistic) self.interfaceLock.release()
def initInterfaceList(self): if not self.refreshingInterface: self.refreshingInterface = True self.interfaceListStore = Gtk.ListStore(str) self.interface = TerminalInterface(self.interfaceListSignal, "interfaceListMsg") self.interface.command = ['ifconfig'] self.interface.start()
def __init__(self, setting, tray=None, statusWindow=None): self.setting = setting self._ = self.setting['language'].gettext self.__activeAp = {'name':'None', 'passwd':'None', 'interface1':'None', 'interface2':'None'} self.status = {'active':False,'text':self._('No active AP'),'button':self._('Connect')} self.errorMsg = {'newMsg':False,'title':None, 'text':None} self.interface = TerminalInterface(self.newCmdMsg) self.updatingPage = {'tray':tray, 'statusWindow':statusWindow} self.lock = threading.Lock()
def reInit(self): self.interfaceLock.acquire() self.__activeAp = {'name':'None', 'passwd':'None', 'interface1':'None', 'interface2':'None'} self.__status = {'active':False,'text':self._('No active AP'),'button':self._('Connect')} self.errorMsg = {'newMsg':False,'title':None, 'text':None} self.__statistic = {'startReceived':None,'startSending':None,'receiving':'0', 'totalReceived':'0', 'sending':'0', 'totalSent':'0'} #init Thread self.interfaceThread = TerminalInterface(self.mysignal,signalNewMsg) self.statisticThread = Statistic(self.mysignal,signalUpdateStatistic) self.interfaceLock.release()
class CreateEditAp(Gtk.Window): def __init__(self, setting): Gtk.Window.__init__(self, title='Create AP') self.setting = setting self._ = self.setting['language'].gettext self.initWindow() self.setting['runningAp'].updatingPage['statusWindow'] = self.updateStatusPage self.set_default_icon_from_file(self.setting['iconPath']) def show(self, page=None): self.show_all() if page != None: Gtk.Notebook.do_change_current_page(self.notebook,page-self.notebook.get_current_page()) def initWindow(self): self.connect("destroy", self.on_destroy) self.set_border_width(3) self.notebook = Gtk.Notebook() self.add(self.notebook) self.initStatusPage() self.initInterfaceList() self.initEditPage() self.initCreatePage() self.initSettingPage() self.initAboutPage() def initStatusPage(self): table = Gtk.Table(10,3, True) table.set_border_width(10) table.set_row_spacings(5) table.set_col_spacings(20) #status label self.statusTitleLabel = Gtk.Label(self.setting['runningAp'].status) pangoFont = Pango.FontDescription("Sans 40") self.statusTitleLabel.modify_font(pangoFont) table.attach(self.statusTitleLabel, 0,3,0,3) #information about conection #Name self.createLabel(self._('AP name'),[0,1,3,4], table, aligment='right') self.statusNameAp = Gtk.Label() self.createLabel('None', [1,3,3,4], table, self.statusNameAp, aligment='left') #wifi interface 1 self.createLabel(self._('Wifi interface'),[0,1,4,5], table, aligment='right') self.statusInterface1 = Gtk.Label() self.createLabel('None', [1,3,4,5], table, self.statusInterface1, aligment='left') #wifi interface 2 self.createLabel(self._('Interface with Internet'),[0,1,5,6], table, aligment='right') self.statusInterface2 = Gtk.Label() self.createLabel('None', [1,3,5,6], table, self.statusInterface2, aligment='left') #Receiving self.createLabel(self._('Receiving'),[0,1,6,7], table, aligment='right') self.statusReciving = Gtk.Label() self.createLabel(self._('None'), [1,2,6,7], table, self.statusReciving, aligment='left') #Total Received self.createLabel(self._('Total Received'),[0,1,7,8],table, aligment='right') self.statusTotalReciving = Gtk.Label() self.createLabel(self._('None'), [1,2,7,8],table, self.statusTotalReciving, aligment='left') #Sending self.createLabel(self._('Sending'),[1,2,6,7],table, aligment='right') self.statusSending = Gtk.Label() self.createLabel(self._('None'), [2,3,6,7],table, self.statusSending, aligment='left') #Total Sent self.createLabel(self._('Total Sent'),[1,2,7,8],table, aligment='right') self.statusTotalSending = Gtk.Label() self.createLabel(self._('None'), [2,3,7,8], table, self.statusTotalSending, aligment='left') #connect / disconect button self.connectDisconectButton = Gtk.Button() self.createButton(self._('Connect'),[2,3,9,10],table,self.connectDisconnect,self.connectDisconectButton ) self.updateStatusPage() self.notebook.append_page(table, Gtk.Label(self._('Running AP'))) def connectDisconnect(self, button=None): if self.setting['runningAp'].errorMsg['newMsg']: self.sendErrorDialog(self.setting['runningAp'].errorMsg['title'], self.setting['runningAp'].errorMsg['text']) else: if self.setting['runningAp'].status['active']: self.setting['runningAp'].stopAp() else: Gtk.Notebook.do_change_current_page(self.notebook,+1) def initCreatePage(self): table = Gtk.Table(10,3, True) table.set_border_width(10) table.set_row_spacings(10) table.set_col_spacings(10) #create New Form #acces point name self.createLabel(self._('AP name'),[0,1,0,1], table, aligment='right') #access point name set text self.apName = Gtk.Entry() self.createEntry(self.apName, [1,3,0,1],table, "") #acces point password self.createLabel(self._('Password'),[0,1,1,2],table, aligment='right') #access point password set text self.apPassword = Gtk.Entry() self.createEntry(self.apPassword, [1,3,1,2],table,"",False) #Show password self.showPassword = Gtk.CheckButton(self._("Show password"),table) self.createCheckButton(self.showPassword, [1,3,2,3],table , self.showHidePasswd, True) #wifi interface label self.createLabel(self._('Wifi interface'),[0,1,3,4],table, aligment='right') #wifi interface Combobox self.interface1ComboBox = Gtk.ComboBox.new_with_model(self.interfaceListStore) self.createComboBox(self.interface1ComboBox, [1,3,3,4],table , None) #interface with internet Label self.createLabel(self._('Interface with Internet'),[0,1,4,5],table, aligment='right') #interface with internet Combobox self.interface2ComboBox = Gtk.ComboBox.new_with_model(self.interfaceListStore) self.createComboBox( self.interface2ComboBox, [1,3,4,5], table, None) #refresh interface list button self.createButton(self._('Refresh'),[2,3,5,6], table, self.refreshInterfaceList) #Save and Create AP self.createButton(self._("Only Create"), [1,2,9,10], table, self.onlyCreateAction) self.createButton(self._("Save and Create"), [2,3,9,10], table, self.saveCreateAction) self.notebook.append_page(table, Gtk.Label(self._('New AP'))) def initEditPage(self): table = Gtk.Table(10,3,True) table.set_border_width(10) table.set_row_spacings(10) table.set_col_spacings(10) self.store = Gtk.ListStore(str, str, str) self.setting['userSetting'].getApStore(self.store) self.treeview = Gtk.TreeView(model=self.store) self.createTextViewColumn([self._('AP name'),self._('Interface1'),self._('Interface2')]) scrolled_window = Gtk.ScrolledWindow() scrolled_window.set_policy( Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC) scrolled_window.add(self.treeview) #delete AP buton self.createButton(self._('Delete'),[1,2,9,10], table, self.deleteAP) #create AP button self.createButton(self._('Create'),[2,3,9,10], table, self.createAP) table.attach(scrolled_window, 0, 3, 0, 9) self.notebook.append_page(table, Gtk.Label(self._('Create AP'))) def initSettingPage(self): table = Gtk.Table(10,3,True) table.set_border_width(20) table.set_row_spacings(10) table.set_col_spacings(10) #language label self.createLabel(self._('Language'),[0,1,0,1],table, aligment='right') #init language comboBox self.createLanguageListStore() self.languageComboBox = Gtk.ComboBox.new_with_model(self.languageListStore) defaultPosition = self.setting['language'].getLanguageList().index(self.setting['userSetting'].language['name']) self.createComboBox(self.languageComboBox, [1,3,0,1],table , defaultPosition) self.createButton(self._('Save'),[2,3,9,10], table, self.saveSetting) self.notebook.append_page(table, Gtk.Label(self._('Setting'))) def saveSetting(self, button=None): self.setting['userSetting'].language['name'] = self.getComboBoxSelect(self.languageComboBox) self.setting['language'].update(self.setting) self.setting['userSetting'].save() def createLanguageListStore(self): self.languageListStore = Gtk.ListStore(str) for item in self.setting['language'].getLanguageList(): self.languageListStore.append([item]) def initAboutPage(self): table = Gtk.Table(10,3,False) table.set_border_width(10) # table.set_row_spacings(0) table.set_col_spacings(10) #application name aboutTitleLabel = Gtk.Label(self._('Create AP Gui')) pangoFont = Pango.FontDescription("Sans 40") aboutTitleLabel.modify_font(pangoFont) table.attach(aboutTitleLabel, 0,3,0,2) #Description self.createLabel(self._('\t Gui application for easy creating access points.\n Application allows save configuration for quickly create AP.'),[0,3,2,3],table, aligment='center') #author self.createLabel(self._('Author:'),[0,1,3,4],table, aligment='right') self.createLabel(self._('Jakub Pelikan'),[1,3,3,4],table, aligment='left') #nick self.createLabel(self._('Nick:'),[0,1,4,5],table, aligment='right') self.createLabel(self._('P-eli'),[1,3,4,5],table, aligment='left') #email self.createLabel(self._('Email:'),[0,1,5,6],table, aligment='right') self.createLabel(self._('*****@*****.**'),[1,3,5,6],table, aligment='left') #Website self.createLabel(self._('Website:'),[0,1,7,8],table, aligment='right') website = Gtk.Label() self.createLabel('',[1,3,7,8],table,website, aligment='left') website.set_markup("<a href=\"http://github.com/p-eli/create_ap-gui\" " "title=\"Click to open website\">http://github.com/p-eli/create_ap-gui</a>") self.createLabel('',[0,1,8,9],table, aligment='right') self.createLabel('',[0,1,9,10],table, aligment='right') self.notebook.append_page(table, Gtk.Label(self._('About'))) def createButton(self, text, pos, table, action, button=None): if button == None: button = Gtk.Button.new_with_mnemonic(text) else: button.set_label(text) button.connect("clicked", action) table.attach(button,pos[0],pos[1],pos[2],pos[3]) def createLabel(self, text, pos, table, interfaceLabel=None, aligment='right'): if interfaceLabel == None: interfaceLabel = Gtk.Label(text) else: try: interfaceLabel.set_text(text) except: interfaceLabel.set_text('None') if aligment == 'right': interfaceLabel.set_alignment(1, 0.5) elif aligment == 'left': interfaceLabel.set_alignment(0, 0.5) elif aligment == 'center': interfaceLabel.set_alignment(0.5, 0.5) table.attach(interfaceLabel,pos[0],pos[1],pos[2],pos[3]) def createComboBox(self, name, pos, table, default=None): renderer_text = Gtk.CellRendererText() name.pack_start(renderer_text, True) name.add_attribute(renderer_text, "text", 0) if default != None: name.set_active(default) table.attach(name ,pos[0],pos[1],pos[2],pos[3]) def createEntry(self, name, pos, table, text="", visible=True): name.set_text(text) name.set_visibility(visible) table.attach(name ,pos[0],pos[1],pos[2],pos[3]) def createCheckButton(self, name, pos, table, action, check=True): name.set_active(check) name.connect("clicked", action) table.attach(name ,pos[0],pos[1],pos[2],pos[3]) def createTextViewColumn(self, names): renderer = Gtk.CellRendererText() id = 0 for name in names: column_name = Gtk.TreeViewColumn(name, renderer, text=id) column_name.set_sort_column_id(id) self.treeview.append_column(column_name) id=id+1 def initInterfaceList(self): self.interfaceListStore = Gtk.ListStore(str) self.interface = TerminalInterface(self.readInterfaceList) self.interface.command = ['ifconfig'] self.interface.start() def readInterfaceList(self): output = self.interface.read() if self.interface.is_alive(): self.interface.stop() interfacesList = [] output = output.split('\n') for x in output: stra = re.search(r'(^|\n)[^(:| )]*', x).group() if stra != '': interfacesList.append(stra) for interfaceItem in interfacesList: self.interfaceListStore.append([interfaceItem]) def refreshInterfaceList(self, button): self.initInterfaceList() self.interface1ComboBox.set_model(self.interfaceListStore) self.interface2ComboBox.set_model(self.interfaceListStore) def getComboBoxSelect(self, comboBox): tree_iter = comboBox.get_active_iter() if tree_iter != None: model = comboBox.get_model() return (model[tree_iter][0]) return None def createAP(self, button=None, createAp=None): if self.setting['runningAp'].errorMsg['newMsg']: self.setting['runningAp'].stopAp() self.setting['runningAp'].createNew() if not self.setting['runningAp'].status['active']: if createAp == None: selection = self.treeview.get_selection() model, paths = selection.get_selected_rows() for path in paths: iter = model.get_iter(path) createAp = self.setting['userSetting'].searchAp(model[iter][0],model[iter][1],model[iter][2]) if createAp != None: self.setting['runningAp'].activeAp = createAp self.setting['runningAp'].runAp() else: self.sendErrorDialog(self._('AP is running'), self._('Before start new one, turn off running AP.')) Gtk.Notebook.do_change_current_page(self.notebook,-self.notebook.get_current_page()) def updateStatusPage(self): self.statusTitleLabel.set_text(self.setting['runningAp'].status['text']) self.statusNameAp.set_text(self.setting['runningAp'].activeAp['name']) self.statusInterface1.set_text(self.setting['runningAp'].activeAp['interface1']) self.statusInterface2.set_text(self.setting['runningAp'].activeAp['interface2']) self.statusReciving.set_text('None') self.statusTotalReciving.set_text('None') self.statusSending.set_text('None') self.statusTotalSending.set_text('None') self.connectDisconectButton.set_label(self.setting['runningAp'].status['button']) def saveCreateAction(self, button=None): try: newApConfiguration = self.elaborationNewApForm() self.setting['userSetting'].addAp(newApConfiguration[0],newApConfiguration[1],newApConfiguration[2],newApConfiguration[3]) self.store.append([newApConfiguration[0],newApConfiguration[2],newApConfiguration[3]]) self.createAP(createAp=newApConfiguration) except ValueError: pass def onlyCreateAction(self, button=None): try: newApConfiguration = self.elaborationNewApForm() self.createAP(createAp=newApConfiguration) except ValueError: pass def elaborationNewApForm(self): if self.apName.get_text() != "": if (len(self.apPassword.get_text()) == 0) or len(self.apPassword.get_text()) >= 8: newApConfiguration = [self.apName.get_text(), self.apPassword.get_text(), self.getComboBoxSelect(self.interface1ComboBox),self.getComboBoxSelect(self.interface2ComboBox)] self.apName.set_text("") self.apPassword.set_text("") return newApConfiguration else: self.sendErrorDialog(self._('Invalid password length'), self._('expected length 8..63')) raise ValueError else: self.sendErrorDialog(self._('Ap name is Empty'), self._('Please fill it.')) raise ValueError def sendErrorDialog(self, primaryText, secondaryText): dialog = Gtk.MessageDialog(self, 0, Gtk.MessageType.ERROR, Gtk.ButtonsType.CANCEL, primaryText) dialog.format_secondary_text(secondaryText) dialog.run() dialog.destroy() def deleteAP(self, button): selection = self.treeview.get_selection() model, paths = selection.get_selected_rows() for path in paths: iter = model.get_iter(path) self.setting['userSetting'].removeAp(model[iter][0],model[iter][1],model[iter][2]) model.remove(iter) def showHidePasswd(self, stat): self.apPassword.set_visibility(not stat.get_active()) def on_destroy(self, widget): self.setting['runningAp'].updatingPage['statusWindow'] = None self.setting['createEditAp'] = None self.destroy()
def initInterfaceList(self): self.interfaceListStore = Gtk.ListStore(str) self.interface = TerminalInterface(self.readInterfaceList) self.interface.command = ['ifconfig'] self.interface.start()
class RunningAp(): GObject.signal_new(signalNewMsg, GObject.GObject, GObject.SIGNAL_RUN_FIRST, GObject.TYPE_NONE, ()) GObject.signal_new(signalUpdateStatistic, GObject.GObject, GObject.SIGNAL_RUN_FIRST, GObject.TYPE_NONE, ()) def __init__(self, setting, tray=None, statusWindow=None): self.setting = setting self._ = self.setting['language'].gettext self.updatingPage = {'tray':tray, 'statusWindow':statusWindow} self.interfaceLock = threading.Lock() self.statisticLock = threading.Lock() self.mysignal = GObject.GObject() self.mysignal.connect(signalNewMsg, self.newCmdMsg) self.mysignal.connect(signalUpdateStatistic, self.updateStatistic) self.reInit() def reInit(self): self.interfaceLock.acquire() self.__activeAp = {'name':'None', 'passwd':'None', 'interface1':'None', 'interface2':'None'} self.__status = {'active':False,'text':self._('No active AP'),'button':self._('Connect')} self.errorMsg = {'newMsg':False,'title':None, 'text':None} self.__statistic = {'startReceived':None,'startSending':None,'receiving':'0', 'totalReceived':'0', 'sending':'0', 'totalSent':'0'} #init Thread self.interfaceThread = TerminalInterface(self.mysignal,signalNewMsg) self.statisticThread = Statistic(self.mysignal,signalUpdateStatistic) self.interfaceLock.release() def runAp(self): if self.__status['active']: self.stopAp() if self.errorMsg['newMsg']: self.reInit() self.interfaceLock.acquire() if self.__activeAp['name']!='None': self.interfaceThread.command = ['create_ap'+' '+self.__activeAp['interface1']+' '+self.__activeAp['interface2']+' '+self.__activeAp['name']+' '+self.__activeAp['passwd']] self.interfaceThread.start() self.__status['text'] = self._('Creating AP...') self.__status['button'] = self._('Disconnect') self.__status['active'] = True self.interfaceLock.release() self.runStatistic() self.updatingStatus() def stopAp(self): self.interfaceThread.stop() self.stopStatistic() self.reInit() # self.updatingStatus() def newCmdMsg(self, signal=None): self.interfaceLock.acquire() msg = self.interfaceThread.read() if 'ERROR:' in msg or 'command not found' in msg: self.stopStatistic() self.errorMsg['newMsg'] = True self.errorMsg['title'] = self._('Create failed') self.errorMsg['text'] = msg self.__status['text'] = self._('AP Error') self.__status['button'] = self._('Error details') self.__status['active'] = False elif 'AP-ENABLED' in msg: self.__status['text'] = self._('AP is active') self.__status['button'] = self._('Disconnect') elif 'INTERFACE-DISABLED' in msg: self.__status['text'] = self._('INTERFACE-DISABLED') # elif 'AP-DISABLED' in msg or 'done' in msg: # self.reInit() # else: # self.interfaceLock.release() # return self.interfaceLock.release() self.updatingStatus() def runStatistic(self): if self.__status['active']: self.statisticThread = Statistic(self.mysignal,signalUpdateStatistic) self.statisticThread.command = ['ifconfig'+' '+self.__activeAp['interface1']] self.statisticThread.start() def updateStatistic(self, signal=None): msg = self.statisticThread.read() if 'Device not found' in msg or 'ERROR:' in msg: self.stopStatistic() else: if 'RX' in msg and 'bytes' in msg: self.statisticLock.acquire() line = re.search(regexRX, msg).group(0) line = re.sub(regexBrackets,'\\1', line) self.__statistic['totalReceived'] = line self.statisticLock.release() if 'TX' in msg and 'bytes' in msg: self.statisticLock.acquire() line = re.search(regexTX, msg).group(0) line = re.sub(regexBrackets,'\\1', line) self.__statistic['totalSent'] = line self.statisticLock.release() self.updatingStatus() def stopStatistic(self): self.statisticThread.stop() def updatingStatus(self): if self.updatingPage['statusWindow']: self.updatingPage['statusWindow']() elif self.updatingPage['tray']: self.updatingPage['tray']() def registerPage(self, page): self.updatingPage['statusWindow'] = page self.runStatistic() def unregisterPage(self): self.updatingPage['statusWindow'] = None self.stopStatistic() @property def activeAp(self): return self.__activeAp @activeAp.setter def activeAp(self, data): if self.errorMsg['newMsg']: self.reInit() self.__activeAp['name'] = data[0] self.__activeAp['passwd'] = data[1] if data[2] != None: self.__activeAp['interface1'] = data[2] else: self.__activeAp['interface1'] = '' if data[3] != None: self.__activeAp['interface2'] = data[3] else: self.__activeAp['interface2'] = '' @property def status(self): self.interfaceLock.acquire() value = self.__status self.interfaceLock.release() return value @status.setter def status(self, data): pass @property def totalReceived(self): return self.__statistic['totalReceived'] @property def receiving(self): return self.__statistic['receiving'] @property def sending(self): return self.__statistic['sending'] @property def totalSent(self): return self.__statistic['totalSent']
class RunningAp(): def __init__(self, setting, tray=None, statusWindow=None): self.setting = setting self._ = self.setting['language'].gettext self.__activeAp = {'name':'None', 'passwd':'None', 'interface1':'None', 'interface2':'None'} self.status = {'active':False,'text':self._('No active AP'),'button':self._('Connect')} self.errorMsg = {'newMsg':False,'title':None, 'text':None} self.interface = TerminalInterface(self.newCmdMsg) self.updatingPage = {'tray':tray, 'statusWindow':statusWindow} self.lock = threading.Lock() def runAp(self): if self.__activeAp['name']!='None': self.interface.command = ['create_ap'+' '+self.__activeAp['interface1']+' '+self.__activeAp['interface2']+' '+self.__activeAp['name']+' '+self.__activeAp['passwd']] self.interface.start() self.status['text'] = self._('Creating AP...') self.status['button'] = self._('Disconnect') self.status['active'] = True self.updatingStatus() def createNew(self): self.setting['runningAp'] = RunningAp(self.setting, tray=self.updatingPage['tray'],statusWindow=self.updatingPage['statusWindow']) def stopAp(self): self.lock.acquire() self.interface.stop() self.interface.stop() self.createNew() self.lock.release() def newCmdMsg(self): self.lock.acquire() msg = self.interface.read() if 'ERROR:' in msg or 'command not found' in msg: self.errorMsg['newMsg'] = True self.errorMsg['title'] = self._('Create failed') self.errorMsg['text'] = msg self.status['text'] = self._('AP Error') self.status['button'] = self._('Error details') self.status['active'] = False elif 'AP-ENABLED' in msg: self.status['text'] = self._('AP is active') self.status['button'] = self._('Disconnect') elif 'INTERFACE-DISABLED' in msg: self.status['text'] = self._('INTERFACE-DISABLED') self.updatingStatus() self.lock.release() def updatingStatus(self): if self.updatingPage['statusWindow']: self.updatingPage['statusWindow']() elif self.updatingPage['tray']: self.updatingPage['tray']() @property def activeAp(self): return self.__activeAp @activeAp.setter def activeAp(self, data): self.__activeAp['name'] = data[0] self.__activeAp['passwd'] = data[1] self.__activeAp['interface1'] = data[2] self.__activeAp['interface2'] = data[3]
class RunningAp(): GObject.signal_new(signalNewMsg, GObject.GObject, GObject.SIGNAL_RUN_FIRST, GObject.TYPE_NONE, ()) GObject.signal_new(signalUpdateStatistic, GObject.GObject, GObject.SIGNAL_RUN_FIRST, GObject.TYPE_NONE, ()) def __init__(self, setting, tray=None, statusWindow=None): self.setting = setting self._ = self.setting['language'].gettext self.updatingPage = {'tray': tray, 'statusWindow': statusWindow} self.interfaceLock = threading.Lock() self.statisticLock = threading.Lock() self.mysignal = GObject.GObject() self.mysignal.connect(signalNewMsg, self.newCmdMsg) self.mysignal.connect(signalUpdateStatistic, self.updateStatistic) self.reInit() def reInit(self): self.interfaceLock.acquire() self.__activeAp = { 'name': 'None', 'passwd': 'None', 'interface1': 'None', 'interface2': 'None' } self.__status = { 'active': False, 'text': self._('No active AP'), 'button': self._('Connect') } self.errorMsg = {'newMsg': False, 'title': None, 'text': None} self.__statistic = { 'startReceived': None, 'startSending': None, 'receiving': '0', 'totalReceived': '0', 'sending': '0', 'totalSent': '0' } #init Thread self.interfaceThread = TerminalInterface(self.mysignal, signalNewMsg) self.statisticThread = Statistic(self.mysignal, signalUpdateStatistic) self.interfaceLock.release() def runAp(self): if self.__status['active']: self.stopAp() if self.errorMsg['newMsg']: self.reInit() self.interfaceLock.acquire() if self.__activeAp['name'] != 'None': self.interfaceThread.command = [ 'create_ap' + ' ' + self.__activeAp['interface1'] + ' ' + self.__activeAp['interface2'] + ' ' + self.__activeAp['name'] + ' ' + self.__activeAp['passwd'] ] self.interfaceThread.start() self.__status['text'] = self._('Creating AP...') self.__status['button'] = self._('Disconnect') self.__status['active'] = True self.interfaceLock.release() self.runStatistic() self.updatingStatus() def stopAp(self): self.interfaceThread.stop() self.stopStatistic() self.reInit() # self.updatingStatus() def newCmdMsg(self, signal=None): self.interfaceLock.acquire() msg = self.interfaceThread.read() if 'ERROR:' in msg or 'command not found' in msg: self.stopStatistic() self.errorMsg['newMsg'] = True self.errorMsg['title'] = self._('Create failed') self.errorMsg['text'] = msg self.__status['text'] = self._('AP Error') self.__status['button'] = self._('Error details') self.__status['active'] = False elif 'AP-ENABLED' in msg: self.__status['text'] = self._('AP is active') self.__status['button'] = self._('Disconnect') elif 'INTERFACE-DISABLED' in msg: self.__status['text'] = self._('INTERFACE-DISABLED') # elif 'AP-DISABLED' in msg or 'done' in msg: # self.reInit() # else: # self.interfaceLock.release() # return self.interfaceLock.release() self.updatingStatus() def runStatistic(self): if self.__status['active']: self.statisticThread = Statistic(self.mysignal, signalUpdateStatistic) self.statisticThread.command = [ 'ifconfig' + ' ' + self.__activeAp['interface1'] ] self.statisticThread.start() def updateStatistic(self, signal=None): msg = self.statisticThread.read() if 'Device not found' in msg or 'ERROR:' in msg: self.stopStatistic() else: if 'RX' in msg and 'bytes' in msg: self.statisticLock.acquire() line = re.search(regexRX, msg).group(0) line = re.sub(regexBrackets, '\\1', line) self.__statistic['totalReceived'] = line self.statisticLock.release() if 'TX' in msg and 'bytes' in msg: self.statisticLock.acquire() line = re.search(regexTX, msg).group(0) line = re.sub(regexBrackets, '\\1', line) self.__statistic['totalSent'] = line self.statisticLock.release() self.updatingStatus() def stopStatistic(self): self.statisticThread.stop() def updatingStatus(self): if self.updatingPage['statusWindow']: self.updatingPage['statusWindow']() elif self.updatingPage['tray']: self.updatingPage['tray']() def registerPage(self, page): self.updatingPage['statusWindow'] = page self.runStatistic() def unregisterPage(self): self.updatingPage['statusWindow'] = None self.stopStatistic() @property def activeAp(self): return self.__activeAp @activeAp.setter def activeAp(self, data): if self.errorMsg['newMsg']: self.reInit() self.__activeAp['name'] = data[0] self.__activeAp['passwd'] = data[1] if data[2] != None: self.__activeAp['interface1'] = data[2] else: self.__activeAp['interface1'] = '' if data[3] != None: self.__activeAp['interface2'] = data[3] else: self.__activeAp['interface2'] = '' @property def status(self): self.interfaceLock.acquire() value = self.__status self.interfaceLock.release() return value @status.setter def status(self, data): pass @property def totalReceived(self): return self.__statistic['totalReceived'] @property def receiving(self): return self.__statistic['receiving'] @property def sending(self): return self.__statistic['sending'] @property def totalSent(self): return self.__statistic['totalSent']
class CreatePage(Gtk.Table): def __init__(self, parent, setting): Gtk.Table.__init__(self, 10, 3, True) self.parent = parent self.setting = setting self._ = self.setting['language'].gettext self.set_border_width(10) self.set_row_spacings(10) self.set_col_spacings(10) self.init() def init(self): self.refreshingInterface = False self.interfaceListSignal = GObject.GObject() self.interfaceListSignal.connect('interfaceListMsg', self.readInterfaceList) self.initInterfaceList() #create New Form #acces point name GuiComponent.createLabel(self._('AP name'), [0, 1, 0, 1], self, aligment='right') #access point name set text self.apName = Gtk.Entry() GuiComponent.createEntry(self.apName, [1, 3, 0, 1], self, "") #acces point password GuiComponent.createLabel(self._('Password'), [0, 1, 1, 2], self, aligment='right') #access point password set text self.apPassword = Gtk.Entry() GuiComponent.createEntry(self.apPassword, [1, 3, 1, 2], self, "", False) #Show password self.showPassword = Gtk.CheckButton(self._("Show password"), self) GuiComponent.createCheckButton(self.showPassword, [1, 3, 2, 3], self, self.showHidePasswd, True) #wifi interface label GuiComponent.createLabel(self._('Wifi interface'), [0, 1, 3, 4], self, aligment='right') #wifi interface Combobox self.interface1ComboBox = Gtk.ComboBox.new_with_model( self.interfaceListStore) GuiComponent.createComboBox(self.interface1ComboBox, [1, 3, 3, 4], self, None) #interface with internet Label GuiComponent.createLabel(self._('Interface with Internet'), [0, 1, 4, 5], self, aligment='right') #interface with internet Combobox self.interface2ComboBox = Gtk.ComboBox.new_with_model( self.interfaceListStore) GuiComponent.createComboBox(self.interface2ComboBox, [1, 3, 4, 5], self, None) #refresh interface list button GuiComponent.createButton(self._('Refresh'), [2, 3, 5, 6], self, self.refreshInterfaceList) #Save and Create AP GuiComponent.createButton(self._("Only Create"), [1, 2, 9, 10], self, self.onlyCreateAction) GuiComponent.createButton(self._("Save and Create"), [2, 3, 9, 10], self, self.saveCreateAction) def refreshInterfaceList(self, button): self.initInterfaceList() self.interface1ComboBox.set_model(self.interfaceListStore) self.interface2ComboBox.set_model(self.interfaceListStore) def saveCreateAction(self, button=None): try: newApConfiguration = self.elaborationNewApForm() self.setting['userSetting'].addAp(newApConfiguration[0], newApConfiguration[1], newApConfiguration[2], newApConfiguration[3]) self.parent.editPage.addToStore(newApConfiguration) self.createAP(createAp=newApConfiguration) except ValueError: pass def onlyCreateAction(self, button=None): try: newApConfiguration = self.elaborationNewApForm() self.createAP(createAp=newApConfiguration) except ValueError: pass def elaborationNewApForm(self): if self.apName.get_text() != "": if (len(self.apPassword.get_text()) == 0) or len(self.apPassword.get_text()) >= 8: newApConfiguration = [ self.apName.get_text(), self.apPassword.get_text(), GuiComponent.getComboBoxSelect(self.interface1ComboBox), GuiComponent.getComboBoxSelect(self.interface2ComboBox) ] self.apName.set_text("") self.apPassword.set_text("") return newApConfiguration else: GuiComponent.sendErrorDialog(self.parent, self._('Invalid password length'), self._('expected length 8..63')) raise ValueError else: GuiComponent.sendErrorDialog(self.parent, self._('Ap name is Empty'), self._('Please fill it.')) raise ValueError def showHidePasswd(self, stat): self.apPassword.set_visibility(not stat.get_active()) def initInterfaceList(self): if not self.refreshingInterface: self.refreshingInterface = True self.interfaceListStore = Gtk.ListStore(str) self.interface = TerminalInterface(self.interfaceListSignal, "interfaceListMsg") self.interface.command = ['ifconfig'] self.interface.start() def readInterfaceList(self, signal): output = self.interface.read() if self.interface.is_alive(): self.interface.stop() interfacesList = [] output = output.split('\n') for x in output: stra = re.search(r'(^|\n)[^(:| )]*', x).group() if stra != '': interfacesList.append(stra) for interfaceItem in interfacesList: self.interfaceListStore.append([interfaceItem]) self.refreshingInterface = False def createAP(self, createAp=None): if not self.setting['runningAp'].status['active']: self.setting['runningAp'].activeAp = createAp self.setting['runningAp'].runAp() else: GuiComponent.sendErrorDialog( self.parrent, self._('AP is running'), self._('Before start new one, turn off running AP.')) self.parent.showFirstPage()
class CreatePage(Gtk.Table): def __init__(self, parent, setting): Gtk.Table.__init__(self,10,3, True) self.parent = parent self.setting = setting self._ = self.setting['language'].gettext self.set_border_width(10) self.set_row_spacings(10) self.set_col_spacings(10) self.init() def init(self): self.refreshingInterface = False self.interfaceListSignal = GObject.GObject() self.interfaceListSignal.connect('interfaceListMsg', self.readInterfaceList) self.initInterfaceList() #create New Form #acces point name GuiComponent.createLabel(self._('AP name'),[0,1,0,1], self, aligment='right') #access point name set text self.apName = Gtk.Entry() GuiComponent.createEntry(self.apName, [1,3,0,1],self, "") #acces point password GuiComponent.createLabel(self._('Password'),[0,1,1,2],self, aligment='right') #access point password set text self.apPassword = Gtk.Entry() GuiComponent.createEntry(self.apPassword, [1,3,1,2],self,"",False) #Show password self.showPassword = Gtk.CheckButton(self._("Show password"),self) GuiComponent.createCheckButton(self.showPassword, [1,3,2,3],self , self.showHidePasswd, True) #wifi interface label GuiComponent.createLabel(self._('Wifi interface'),[0,1,3,4],self, aligment='right') #wifi interface Combobox self.interface1ComboBox = Gtk.ComboBox.new_with_model(self.interfaceListStore) GuiComponent.createComboBox(self.interface1ComboBox, [1,3,3,4],self , None) #interface with internet Label GuiComponent.createLabel(self._('Interface with Internet'),[0,1,4,5],self, aligment='right') #interface with internet Combobox self.interface2ComboBox = Gtk.ComboBox.new_with_model(self.interfaceListStore) GuiComponent.createComboBox( self.interface2ComboBox, [1,3,4,5], self, None) #refresh interface list button GuiComponent.createButton(self._('Refresh'),[2,3,5,6], self, self.refreshInterfaceList) #Save and Create AP GuiComponent.createButton(self._("Only Create"), [1,2,9,10], self, self.onlyCreateAction) GuiComponent.createButton(self._("Save and Create"), [2,3,9,10], self, self.saveCreateAction) def refreshInterfaceList(self, button): self.initInterfaceList() self.interface1ComboBox.set_model(self.interfaceListStore) self.interface2ComboBox.set_model(self.interfaceListStore) def saveCreateAction(self, button=None): try: newApConfiguration = self.elaborationNewApForm() self.setting['userSetting'].addAp(newApConfiguration[0],newApConfiguration[1],newApConfiguration[2],newApConfiguration[3]) self.parent.editPage.addToStore(newApConfiguration) self.createAP(createAp=newApConfiguration) except ValueError: pass def onlyCreateAction(self, button=None): try: newApConfiguration = self.elaborationNewApForm() self.createAP(createAp=newApConfiguration) except ValueError: pass def elaborationNewApForm(self): if self.apName.get_text() != "": if (len(self.apPassword.get_text()) == 0) or len(self.apPassword.get_text()) >= 8: newApConfiguration = [self.apName.get_text(), self.apPassword.get_text(), GuiComponent.getComboBoxSelect(self.interface1ComboBox),GuiComponent.getComboBoxSelect(self.interface2ComboBox)] self.apName.set_text("") self.apPassword.set_text("") return newApConfiguration else: GuiComponent.sendErrorDialog(self.parent, self._('Invalid password length'), self._('expected length 8..63')) raise ValueError else: GuiComponent.sendErrorDialog(self.parent, self._('Ap name is Empty'), self._('Please fill it.')) raise ValueError def showHidePasswd(self, stat): self.apPassword.set_visibility(not stat.get_active()) def initInterfaceList(self): if not self.refreshingInterface: self.refreshingInterface = True self.interfaceListStore = Gtk.ListStore(str) self.interface = TerminalInterface(self.interfaceListSignal, "interfaceListMsg") self.interface.command = ['ifconfig'] self.interface.start() def readInterfaceList(self, signal): output = self.interface.read() if self.interface.is_alive(): self.interface.stop() interfacesList = [] output = output.split('\n') for x in output: stra = re.search(r'(^|\n)[^(:| )]*', x).group() if stra != '': interfacesList.append(stra) for interfaceItem in interfacesList: self.interfaceListStore.append([interfaceItem]) self.refreshingInterface = False def createAP(self, createAp=None): if not self.setting['runningAp'].status['active']: self.setting['runningAp'].activeAp = createAp self.setting['runningAp'].runAp() else: GuiComponent.sendErrorDialog(self.parrent, self._('AP is running'), self._('Before start new one, turn off running AP.')) self.parent.showFirstPage()