Example #1
0
class appGUI():
    """The UI itself, all glory belongs to it!"""
    def __init__(self):
        self.conn_status = False
        self.tcount = 0  # Counter for connection twirl indicator

        self.size = ui.get_cols_rows()
        # Happy screen saying that you can't do anything because we're scanning
        # for networks.  :-)
        self.screen_locker = urwid.Filler(
            urwid.Text(('important', _('Scanning networks... stand by...')),
                       align='center'))
        self.no_wlan = urwid.Filler(
            urwid.Text(('important', _('No wireless networks found.')),
                       align='center'))
        self.TITLE = _('Wicd Curses Interface')
        self.WIRED_IDX = 1
        self.WLESS_IDX = 3

        header = urwid.AttrWrap(urwid.Text(self.TITLE, align='right'),
                                'header')
        self.wiredH = urwid.Filler(urwid.Text(_('Wired Networks')))
        self.list_header = urwid.AttrWrap(urwid.Text(gen_list_header()),
                                          'listbar')
        self.wlessH = NSelListBox(
            [urwid.Text(_('Wireless Networks')), self.list_header])

        # Init this earlier to make update_status happy
        self.update_tag = None

        # FIXME: This should be two variables
        self.focusloc = [1, 0]

        # These are empty to make sure that things go my way.
        wiredL, wlessL = [], []

        self.frame = None
        self.diag = None

        self.wiredCB = urwid.Filler(WiredComboBox(wiredL))
        self.wlessLB = urwid.ListBox(wlessL)
        self.update_netlist(force_check=True, firstrun=True)

        # Keymappings proposed by nanotube in #wicd
        keys = [
            ('H', _('Help'), None),
            ('right', _('Config'), None),
            #('  ', '         ', None),
            ('K', _('RfKill'), None),
            ('C', _('Connect'), None),
            ('D', _('Disconn'), None),
            ('R', _('Refresh'), None),
            ('P', _('Prefs'), None),
            ('I', _('Hidden'), None),
            ('A', _('About'), None),
            ('Q', _('Quit'), loop.quit)
        ]

        self.primaryCols = OptCols(keys, self.handle_keys)
        self.status_label = urwid.AttrWrap(urwid.Text(''), 'important')
        self.footer2 = urwid.Columns([self.status_label])
        self.footerList = urwid.Pile([self.primaryCols, self.footer2])

        self.frame = urwid.Frame(self.thePile,
                                 header=header,
                                 footer=self.footerList)
        self.wiredCB.get_body().build_combobox(self.frame, ui, 3)

        # Init the other columns used in the program
        self.init_other_optcols()

        self.frame.set_body(self.thePile)
        # Booleans gallore!
        self.prev_state = False
        self.connecting = False
        self.screen_locked = False
        self.do_diag_lock = False  # Whether the screen is locked beneath a dialog
        self.diag_type = 'none'  # The type of dialog that is up
        self.scanning = False

        self.pref = None

        self.update_status()

        #self.max_wait = ui.max_wait

    def doScan(self, sync=False):
        """ Start wireless scan. """
        self.scanning = True
        wireless.Scan(False)

    def init_other_optcols(self):
        """ Init "tabbed" preferences dialog. """
        self.prefCols = OptCols([('S', _('Save')), (
            'page up',
            _('Tab Left'),
        ), ('page down', _('Tab Right')), ('esc', _('Cancel'))],
                                self.handle_keys)
        self.confCols = OptCols([('S', _('Save')), ('esc', _('Cancel'))],
                                self.handle_keys)

    def lock_screen(self):
        """ Lock the screen. """
        if self.diag_type == 'pref':
            self.do_diag_lock = True
            return True
        self.frame.set_body(self.screen_locker)
        self.screen_locked = True
        self.update_ui()

    def unlock_screen(self):
        """ Unlock the screen. """
        if self.do_diag_lock:
            self.do_diag_lock = False
            return True
        self.update_netlist(force_check=True)
        if not self.diag:
            self.frame.set_body(self.thePile)
        self.screen_locked = False
        self.update_ui()

    def raise_hidden_network_dialog(self):
        """ Show hidden network dialog. """
        dialog = InputDialog(('header', _('Select Hidden Network ESSID')), 7,
                             30, _('Scan'))
        exitcode, hidden = dialog.run(ui, self.frame)
        if exitcode != -1:
            # That dialog will sit there for a while if I don't get rid of it
            self.update_ui()
            wireless.SetHiddenNetworkESSID(misc.noneToString(hidden))
            wireless.Scan(False)
        wireless.SetHiddenNetworkESSID("")

    def update_focusloc(self):
        """
        Update focus location.

        Location of last known focus is remapped to current location.
        """
        # This might need to be cleaned up later.

        if self.thePile.get_focus() == self.wiredCB:
            wlessorwired = self.WIRED_IDX
            where = self.thePile.get_focus().get_body().get_focus()[1]
        else:  # self.thePile.get_focus() == self.wlessLB :
            wlessorwired = self.WLESS_IDX
            if self.wlessLB == self.no_wlan:
                where = None
            else:
                where = self.thePile.get_focus().get_focus()[1]
                #where = self.wlessLB.get_focus()[1]
        self.focusloc = [wlessorwired, where]

    # Be clunky until I get to a later stage of development.
    # Update the list of networks.  Usually called by DBus.
    @wrap_exceptions
    def update_netlist(self,
                       state=None,
                       x=None,
                       force_check=False,
                       firstrun=False):
        """ Update the list of networks. """
        # Don't even try to do this if we are running a dialog
        if self.diag:
            return
        # Run focus-collecting code if we are not running this for the first
        # time
        if not firstrun:
            self.update_focusloc()
            self.list_header.set_text(gen_list_header())
        # Updates the overall network list.
        if not state:
            state, trash = daemon.GetConnectionStatus()
        if force_check or self.prev_state != state:
            wiredL, wlessL = gen_network_list()

            self.wiredCB.get_body().set_list(wiredL)
            self.wiredCB.get_body().build_combobox(self.frame, ui, 3)
            if len(wlessL) != 0:
                if self.wlessLB == self.no_wlan:
                    self.wlessLB = urwid.ListBox(wlessL)
                else:
                    self.wlessLB.body = urwid.SimpleListWalker(wlessL)
            else:
                self.wlessLB = self.no_wlan
            if daemon.GetAlwaysShowWiredInterface() or wired.CheckPluggedIn():
                self.thePile = urwid.Pile([('fixed', 1, self.wiredH),
                                           ('fixed', 1, self.wiredCB),
                                           ('fixed', 2, self.wlessH),
                                           self.wlessLB])
                if not firstrun:
                    self.frame.body = self.thePile

                self.thePile.set_focus(self.focusloc[0])
                if self.focusloc[0] == self.WIRED_IDX:
                    self.thePile.get_focus(). \
                        get_body().set_focus(self.focusloc[1])
                else:
                    if self.wlessLB != self.no_wlan:
                        # Set the focus to the last selected item, but never past the length of the list
                        self.thePile.get_focus().set_focus(
                            min(self.focusloc[1],
                                len(wlessL) - 1))
                    else:
                        self.thePile.set_focus(self.wiredCB)
            else:
                self.thePile = urwid.Pile([('fixed', 2, self.wlessH),
                                           self.wlessLB])
                if not firstrun:
                    self.frame.body = self.thePile
                if self.focusloc[1] is None:
                    self.focusloc[1] = 0
                if self.wlessLB != self.no_wlan:
                    # Set the focus to the last selected item, but never past the length of the list
                    self.wlessLB.set_focus(
                        min(self.focusloc[1],
                            len(wlessL) - 1))

        self.prev_state = state
        if not firstrun:
            self.update_ui()
        if firstrun:
            if wired.GetDefaultWiredNetwork() is not None:
                self.wiredCB.get_body().set_focus(
                    wired.GetWiredProfileList().index(
                        wired.GetDefaultWiredNetwork()))

    @wrap_exceptions
    def update_status(self):
        """ Update the footer / statusbar. """
        wired_connecting = wired.CheckIfWiredConnecting()
        wireless_connecting = wireless.CheckIfWirelessConnecting()
        self.connecting = wired_connecting or wireless_connecting

        fast = not daemon.NeedsExternalCalls()
        if self.connecting:
            if not self.conn_status:
                self.conn_status = True
                gobject.timeout_add(250, self.set_connecting_status, fast)
            return True
        else:
            if check_for_wired(wired.GetWiredIP(''), self.set_status):
                return True
            if not fast:
                iwconfig = wireless.GetIwconfig()
            else:
                iwconfig = ''
            if check_for_wireless(iwconfig, wireless.GetWirelessIP(""),
                                  self.set_status):
                return True
            else:
                self.set_status(_('Not connected'))
                self.update_ui()
                return True

    def set_connecting_status(self, fast):
        """ Set connecting status. """
        wired_connecting = wired.CheckIfWiredConnecting()
        wireless_connecting = wireless.CheckIfWirelessConnecting()
        if wireless_connecting:
            if not fast:
                iwconfig = wireless.GetIwconfig()
            else:
                iwconfig = ''
            essid = wireless.GetCurrentNetwork(iwconfig)
            stat = wireless.CheckWirelessConnectingMessage()
            return self.set_status("%s: %s" % (essid, stat), True)
        if wired_connecting:
            return self.set_status(
                _('Wired Network') + ': ' +
                wired.CheckWiredConnectingMessage(), True)
        else:
            self.conn_status = False
            return False

    def set_status(self, text, from_idle=False):
        """ Set the status text. """
        # Set the status text, usually called by the update_status method
        # from_idle : a check to see if we are being called directly from the
        # mainloop
        # If we are being called as the result of trying to connect to
        # something, and we aren't connecting to something, return False
        # immediately.

        # Cheap little indicator stating that we are actually connecting
        twirl = ['|', '/', '-', '\\']

        if from_idle and not self.connecting:
            self.update_status()
            self.conn_status = False
            return False
        toAppend = ''
        # If we are connecting and being called from the idle function, spin
        # the wheel.
        if from_idle and self.connecting:
            # This is probably the wrong way to do this, but it works for now.
            self.tcount += 1
            toAppend = twirl[self.tcount % 4]
        self.status_label.set_text(text + ' ' + toAppend)
        self.update_ui()
        return True

    def dbus_scan_finished(self):
        """ Handle DBus scan finish. """
        # I'm pretty sure that I'll need this later.
        #if not self.connecting:
        #    gobject.idle_add(self.refresh_networks, None, False, None)
        self.unlock_screen()
        self.scanning = False

    def dbus_scan_started(self):
        """ Handle DBus scan start. """
        self.scanning = True
        if self.diag_type == 'conf':
            self.restore_primary()
        self.lock_screen()

    def restore_primary(self):
        """ Restore screen. """
        self.diag_type = 'none'
        if self.do_diag_lock or self.scanning:
            self.frame.set_body(self.screen_locker)
            self.do_diag_lock = False
        else:
            self.frame.set_body(self.thePile)
        self.diag = None
        self.frame.set_footer(urwid.Pile([self.primaryCols, self.footer2]))
        self.update_ui()

    def handle_keys(self, keys):
        """ Handle keys. """
        if not self.diag:
            # Handle keystrokes
            if "f8" in keys or 'Q' in keys or 'q' in keys:
                loop.quit()
                #return False
            if "f5" in keys or 'R' in keys:
                self.lock_screen()
                self.doScan()
            if 'k' in keys or 'K' in keys:
                wireless.SwitchRfKill()
                self.update_netlist()
            if "D" in keys:
                # Disconnect from all networks.
                daemon.Disconnect()
                self.update_netlist()
            if 'right' in keys:
                if not self.scanning:
                    focus = self.thePile.get_focus()
                    self.frame.set_footer(
                        urwid.Pile([self.confCols, self.footer2]))
                    if focus == self.wiredCB:
                        self.diag = WiredSettingsDialog(
                            self.wiredCB.get_body().get_selected_profile(),
                            self.frame)
                        self.diag.ready_widgets(ui, self.frame)
                        self.frame.set_body(self.diag)
                    else:
                        # wireless list only other option
                        trash, pos = self.thePile.get_focus().get_focus()
                        self.diag = WirelessSettingsDialog(pos, self.frame)
                        self.diag.ready_widgets(ui, self.frame)
                        self.frame.set_body(self.diag)
                    self.diag_type = 'conf'
            if "enter" in keys or 'C' in keys:
                if not self.scanning:
                    focus = self.frame.body.get_focus()
                    if focus == self.wiredCB:
                        self.special = focus
                        self.connect("wired", 0)
                    else:
                        # wless list only other option, if it is around
                        if self.wlessLB != self.no_wlan:
                            wid, pos = self.thePile.get_focus().get_focus()
                            self.connect("wireless", pos)
            if "esc" in keys:
                # Force disconnect here if connection in progress
                if self.connecting:
                    daemon.CancelConnect()
                    # Prevents automatic reconnecting if that option is enabled
                    daemon.SetForcedDisconnect(True)
            if "P" in keys:
                if not self.pref:
                    self.pref = PrefsDialog(self.frame, (0, 1), ui,
                                            dbusmanager.get_dbus_ifaces())
                self.pref.load_settings()
                self.pref.ready_widgets(ui, self.frame)
                self.frame.set_footer(urwid.Pile([self.prefCols,
                                                  self.footer2]))
                self.diag = self.pref
                self.diag_type = 'pref'
                self.frame.set_body(self.diag)
                # Halt here, keypress gets passed to the dialog otherwise
                return True
            if "A" in keys:
                about_dialog(self.frame)
            if "I" in keys:
                self.raise_hidden_network_dialog()
            if "H" in keys or 'h' in keys or '?' in keys:
                # FIXME I shouldn't need this, OptCols messes up this one
                # particular button
                if not self.diag:
                    help_dialog(self.frame)
            if "S" in keys:
                focus = self.thePile.get_focus()
                if focus == self.wiredCB:
                    nettype = 'wired'
                    netname = self.wiredCB.get_body().get_selected_profile()
                else:
                    nettype = 'wireless'
                    netname = str(self.wlessLB.get_focus()[1])
                run_configscript(self.frame, netname, nettype)
            if "O" in keys:
                exitcode, data = AdHocDialog().run(ui, self.frame)
                #data = (essid,ip,channel,use_ics,use_encrypt,key_edit)
                if exitcode == 1:
                    wireless.CreateAdHocNetwork(data[0], data[2], data[1],
                                                "WEP", data[5], data[4], False)
            if 'X' in keys:
                exitcode, data = ForgetDialog().run(ui, self.frame)
                if exitcode == 1:
                    text = _('Are you sure you want to discard settings for '
                             'the selected networks?')
                    text += '\n\n' + '\n'.join(data['essid'])
                    confirm, trash = TextDialog(
                        text,
                        20,
                        50,
                        buttons=[(_('OK'), 1), (_('Cancel'), -1)],
                    ).run(ui, self.frame)
                    if confirm == 1:
                        for x in data['bssid']:
                            wireless.DeleteWirelessNetwork(x)

        for k in keys:
            if urwid.VERSION < (1, 0, 0):
                check_mouse_event = urwid.is_mouse_event
            else:
                check_mouse_event = urwid.util.is_mouse_event
            if check_mouse_event(k):
                event, button, col, row = k
                self.frame.mouse_event(self.size,
                                       event,
                                       button,
                                       col,
                                       row,
                                       focus=True)
                continue
            k = self.frame.keypress(self.size, k)
            if self.diag:
                if k == 'esc' or k == 'q' or k == 'Q':
                    self.restore_primary()
                    break
                # F10 has been changed to S to avoid using function keys,
                # which are often caught by the terminal emulator.
                # But F10 still works, because it doesn't hurt and some users might be used to it.
                if k == 'f10' or k == 'S' or k == 's':
                    self.diag.save_settings()
                    self.restore_primary()
                    break
            if k == "window resize":
                self.size = ui.get_cols_rows()
                continue

    def call_update_ui(self, source, cb_condition):
        """ Update UI. """
        self.update_ui(True)
        return True

    # Redraw the screen
    @wrap_exceptions
    def update_ui(self, from_key=False):
        """ Redraw the screen. """
        if not ui._started:
            return False

        input_data = ui.get_input_nonblocking()
        # Resolve any "alarms" in the waiting
        self.handle_keys(input_data[1])

        # Update the screen
        canvas = self.frame.render((self.size), True)
        ui.draw_screen((self.size), canvas)
        # Get the input data
        if self.update_tag is not None:
            gobject.source_remove(self.update_tag)
        #if from_key:
        return False

    def connect(self, nettype, networkid, networkentry=None):
        """ Initiates the connection process in the daemon. """
        if nettype == "wireless":
            wireless.ConnectWireless(networkid)
        elif nettype == "wired":
            wired.ConnectWired()
        self.update_status()
Example #2
0
    def handle_keys(self, keys):
        """ Handle keys. """
        if not self.diag:
            # Handle keystrokes
            if "f8" in keys or 'Q' in keys or 'q' in keys:
                loop.quit()
                #return False
            if "f5" in keys or 'R' in keys:
                self.lock_screen()
                self.doScan()
            if 'k' in keys or 'K' in keys:
                wireless.SwitchRfKill()
                self.update_netlist()
            if "D" in keys:
                # Disconnect from all networks.
                daemon.Disconnect()
                self.update_netlist()
            if 'right' in keys:
                if not self.scanning:
                    focus = self.thePile.get_focus()
                    self.frame.set_footer(
                        urwid.Pile([self.confCols, self.footer2]))
                    if focus == self.wiredCB:
                        self.diag = WiredSettingsDialog(
                            self.wiredCB.get_body().get_selected_profile(),
                            self.frame)
                        self.diag.ready_widgets(ui, self.frame)
                        self.frame.set_body(self.diag)
                    else:
                        # wireless list only other option
                        trash, pos = self.thePile.get_focus().get_focus()
                        self.diag = WirelessSettingsDialog(pos, self.frame)
                        self.diag.ready_widgets(ui, self.frame)
                        self.frame.set_body(self.diag)
                    self.diag_type = 'conf'
            if "enter" in keys or 'C' in keys:
                if not self.scanning:
                    focus = self.frame.body.get_focus()
                    if focus == self.wiredCB:
                        self.special = focus
                        self.connect("wired", 0)
                    else:
                        # wless list only other option, if it is around
                        if self.wlessLB != self.no_wlan:
                            wid, pos = self.thePile.get_focus().get_focus()
                            self.connect("wireless", pos)
            if "esc" in keys:
                # Force disconnect here if connection in progress
                if self.connecting:
                    daemon.CancelConnect()
                    # Prevents automatic reconnecting if that option is enabled
                    daemon.SetForcedDisconnect(True)
            if "P" in keys:
                if not self.pref:
                    self.pref = PrefsDialog(self.frame, (0, 1), ui,
                                            dbusmanager.get_dbus_ifaces())
                self.pref.load_settings()
                self.pref.ready_widgets(ui, self.frame)
                self.frame.set_footer(urwid.Pile([self.prefCols,
                                                  self.footer2]))
                self.diag = self.pref
                self.diag_type = 'pref'
                self.frame.set_body(self.diag)
                # Halt here, keypress gets passed to the dialog otherwise
                return True
            if "A" in keys:
                about_dialog(self.frame)
            if "I" in keys:
                self.raise_hidden_network_dialog()
            if "H" in keys or 'h' in keys or '?' in keys:
                # FIXME I shouldn't need this, OptCols messes up this one
                # particular button
                if not self.diag:
                    help_dialog(self.frame)
            if "S" in keys:
                focus = self.thePile.get_focus()
                if focus == self.wiredCB:
                    nettype = 'wired'
                    netname = self.wiredCB.get_body().get_selected_profile()
                else:
                    nettype = 'wireless'
                    netname = str(self.wlessLB.get_focus()[1])
                run_configscript(self.frame, netname, nettype)
            if "O" in keys:
                exitcode, data = AdHocDialog().run(ui, self.frame)
                #data = (essid,ip,channel,use_ics,use_encrypt,key_edit)
                if exitcode == 1:
                    wireless.CreateAdHocNetwork(data[0], data[2], data[1],
                                                "WEP", data[5], data[4], False)
            if 'X' in keys:
                exitcode, data = ForgetDialog().run(ui, self.frame)
                if exitcode == 1:
                    text = _('Are you sure you want to discard settings for '
                             'the selected networks?')
                    text += '\n\n' + '\n'.join(data['essid'])
                    confirm, trash = TextDialog(
                        text,
                        20,
                        50,
                        buttons=[(_('OK'), 1), (_('Cancel'), -1)],
                    ).run(ui, self.frame)
                    if confirm == 1:
                        for x in data['bssid']:
                            wireless.DeleteWirelessNetwork(x)

        for k in keys:
            if urwid.VERSION < (1, 0, 0):
                check_mouse_event = urwid.is_mouse_event
            else:
                check_mouse_event = urwid.util.is_mouse_event
            if check_mouse_event(k):
                event, button, col, row = k
                self.frame.mouse_event(self.size,
                                       event,
                                       button,
                                       col,
                                       row,
                                       focus=True)
                continue
            k = self.frame.keypress(self.size, k)
            if self.diag:
                if k == 'esc' or k == 'q' or k == 'Q':
                    self.restore_primary()
                    break
                # F10 has been changed to S to avoid using function keys,
                # which are often caught by the terminal emulator.
                # But F10 still works, because it doesn't hurt and some users might be used to it.
                if k == 'f10' or k == 'S' or k == 's':
                    self.diag.save_settings()
                    self.restore_primary()
                    break
            if k == "window resize":
                self.size = ui.get_cols_rows()
                continue
Example #3
0
    def handle_keys(self, keys):
        """ Handle keys. """
        if not self.diag:
            # Handle keystrokes
            if "f8" in keys or 'Q' in keys or 'q' in keys:
                loop.quit()
                #return False
            if "f5" in keys or 'R' in keys:
                self.lock_screen()
                self.doScan()
            if 'k' in keys or 'K' in keys:
                wireless.SwitchRfKill()
                self.update_netlist()
            if "D" in keys:
                # Disconnect from all networks.
                daemon.Disconnect()
                self.update_netlist()
            if 'right' in keys:
                if not self.scanning:
                    focus = self.thePile.get_focus()
                    self.frame.set_footer(
                        urwid.Pile([self.confCols, self.footer2])
                    )
                    if focus == self.wiredCB:
                        self.diag = WiredSettingsDialog(
                            self.wiredCB.get_body().get_selected_profile(),
                            self.frame
                        )
                        self.diag.ready_widgets(ui, self.frame)
                        self.frame.set_body(self.diag)
                    else:
                        # wireless list only other option
                        trash, pos = self.thePile.get_focus().get_focus()
                        self.diag = WirelessSettingsDialog(pos, self.frame)
                        self.diag.ready_widgets(ui, self.frame)
                        self.frame.set_body(self.diag)
                    self.diag_type = 'conf'
            if "enter" in keys or 'C' in keys:
                if not self.scanning:
                    focus = self.frame.body.get_focus()
                    if focus == self.wiredCB:
                        self.special = focus
                        self.connect("wired", 0)
                    else:
                        # wless list only other option, if it is around
                        if self.wlessLB != self.no_wlan:
                            wid, pos = self.thePile.get_focus().get_focus()
                            self.connect("wireless", pos)
            if "esc" in keys:
                # Force disconnect here if connection in progress
                if self.connecting:
                    daemon.CancelConnect()
                    # Prevents automatic reconnecting if that option is enabled
                    daemon.SetForcedDisconnect(True)
            if "P" in keys:
                if not self.pref:
                    self.pref = PrefsDialog(
                        self.frame,
                        (0, 1),
                        ui,
                        dbusmanager.get_dbus_ifaces()
                    )
                self.pref.load_settings()
                self.pref.ready_widgets(ui, self.frame)
                self.frame.set_footer(urwid.Pile([self.prefCols, self.footer2]))
                self.diag = self.pref
                self.diag_type = 'pref'
                self.frame.set_body(self.diag)
                # Halt here, keypress gets passed to the dialog otherwise
                return True
            if "A" in keys:
                about_dialog(self.frame)
            if "I" in keys:
                self.raise_hidden_network_dialog()
            if "H" in keys or 'h' in keys or '?' in keys:
                # FIXME I shouldn't need this, OptCols messes up this one
                # particular button
                if not self.diag:
                    help_dialog(self.frame)
            if "S" in keys:
                focus = self.thePile.get_focus()
                if focus == self.wiredCB:
                    nettype = 'wired'
                    netname = self.wiredCB.get_body().get_selected_profile()
                else:
                    nettype = 'wireless'
                    netname = str(self.wlessLB.get_focus()[1])
                run_configscript(self.frame, netname, nettype)
            if "O" in keys:
                exitcode, data = AdHocDialog().run(ui, self.frame)
                #data = (essid,ip,channel,use_ics,use_encrypt,key_edit)
                if exitcode == 1:
                    wireless.CreateAdHocNetwork(
                        data[0],
                        data[2],
                        data[1],
                        "WEP",
                        data[5],
                        data[4],
                        False
                    )
            if 'X' in keys:
                exitcode, data = ForgetDialog().run(ui, self.frame)
                if exitcode == 1:
                    text = _('Are you sure you want to discard settings for '
                        'the selected networks?')
                    text += '\n\n' + '\n'.join(data['essid'])
                    confirm, trash = TextDialog(text, 20, 50,
                        buttons=[(_('OK'), 1), (_('Cancel'), -1)],
                        ).run(ui, self.frame)
                    if confirm == 1:
                        for x in data['bssid']:
                            wireless.DeleteWirelessNetwork(x)

        for k in keys:
            if urwid.VERSION < (1, 0, 0):
                check_mouse_event = urwid.is_mouse_event
            else:
                check_mouse_event = urwid.util.is_mouse_event
            if check_mouse_event(k):
                event, button, col, row = k
                self.frame.mouse_event(
                    self.size, event, button, col, row, focus=True)
                continue
            k = self.frame.keypress(self.size, k)
            if self.diag:
                if  k == 'esc' or k == 'q' or k == 'Q':
                    self.restore_primary()
                    break
                if k == 'f10':
                    self.diag.save_settings()
                    self.restore_primary()
                    break
            if k == "window resize":
                self.size = ui.get_cols_rows()
                continue
Example #4
0
class appGUI():
    """The UI itself, all glory belongs to it!"""
    def __init__(self):
        self.conn_status = False
        self.tcount = 0  # Counter for connection twirl indicator

        self.size = ui.get_cols_rows()
        # Happy screen saying that you can't do anything because we're scanning
        # for networks.  :-)
        self.screen_locker = urwid.Filler(
            urwid.Text(
                ('important', _('Scanning networks... stand by...')),
                align='center'
            )
        )
        self.no_wlan = urwid.Filler(
            urwid.Text(
                ('important', _('No wireless networks found.')),
                align='center'
            )
        )
        self.TITLE = _('Wicd Curses Interface')
        self.WIRED_IDX = 1
        self.WLESS_IDX = 3

        header = urwid.AttrWrap(urwid.Text(self.TITLE, align='right'), 'header')
        self.wiredH = urwid.Filler(urwid.Text(_('Wired Networks')))
        self.list_header = urwid.AttrWrap(
            urwid.Text(gen_list_header()), 'listbar'
        )
        self.wlessH = NSelListBox([
            urwid.Text(_('Wireless Networks')),
            self.list_header
        ])

        # Init this earlier to make update_status happy
        self.update_tag = None

        # FIXME: This should be two variables
        self.focusloc = [1, 0]

        # These are empty to make sure that things go my way.
        wiredL, wlessL = [], []

        self.frame = None
        self.diag = None

        self.wiredCB = urwid.Filler(WiredComboBox(wiredL))
        self.wlessLB = urwid.ListBox(wlessL)
        self.update_netlist(force_check=True, firstrun=True)

        # Keymappings proposed by nanotube in #wicd
        keys = [
            ('H', _('Help'), None),
            ('right', _('Config'), None),
            #('  ', '         ', None),
            ('K', _('RfKill'), None),
            ('C', _('Connect'), None),
            ('D', _('Disconn'), None),
            ('R', _('Refresh'), None),
            ('P', _('Prefs'), None),
            ('I', _('Hidden'), None),
            ('A', _('About'), None),
            ('Q', _('Quit'), loop.quit)
        ]

        self.primaryCols = OptCols(keys, self.handle_keys)
        self.status_label = urwid.AttrWrap(urwid.Text(''), 'important')
        self.footer2 = urwid.Columns([self.status_label])
        self.footerList = urwid.Pile([self.primaryCols, self.footer2])

        self.frame = urwid.Frame(self.thePile,
                                 header=header,
                                 footer=self.footerList)
        self.wiredCB.get_body().build_combobox(self.frame, ui, 3)

        # Init the other columns used in the program
        self.init_other_optcols()

        self.frame.set_body(self.thePile)
        # Booleans gallore!
        self.prev_state = False
        self.connecting = False
        self.screen_locked = False
        self.do_diag_lock = False  # Whether the screen is locked beneath a dialog
        self.diag_type = 'none'  # The type of dialog that is up
        self.scanning = False

        self.pref = None

        self.update_status()

        #self.max_wait = ui.max_wait

    def doScan(self, sync=False):
        """ Start wireless scan. """
        self.scanning = True
        wireless.Scan(False)

    def init_other_optcols(self):
        """ Init "tabbed" preferences dialog. """
        self.prefCols = OptCols([
            ('f10', _('OK')),
            ('page up', _('Tab Left'), ),
            ('page down', _('Tab Right')),
            ('esc', _('Cancel'))
        ], self.handle_keys)
        self.confCols = OptCols([
            ('f10', _('OK')),
            ('esc', _('Cancel'))
        ], self.handle_keys)

    def lock_screen(self):
        """ Lock the screen. """
        if self.diag_type == 'pref':
            self.do_diag_lock = True
            return True
        self.frame.set_body(self.screen_locker)
        self.screen_locked = True
        self.update_ui()

    def unlock_screen(self):
        """ Unlock the screen. """
        if self.do_diag_lock:
            self.do_diag_lock = False
            return True
        self.update_netlist(force_check=True)
        if not self.diag:
            self.frame.set_body(self.thePile)
        self.screen_locked = False
        self.update_ui()

    def raise_hidden_network_dialog(self):
        """ Show hidden network dialog. """
        dialog = InputDialog(
            ('header', _('Select Hidden Network ESSID')),
            7, 30, _('Scan')
        )
        exitcode, hidden = dialog.run(ui, self.frame)
        if exitcode != -1:
            # That dialog will sit there for a while if I don't get rid of it
            self.update_ui()
            wireless.SetHiddenNetworkESSID(misc.noneToString(hidden))
            wireless.Scan(False)
        wireless.SetHiddenNetworkESSID("")

    def update_focusloc(self):
        """
        Update focus location.

        Location of last known focus is remapped to current location.
        """
        # This might need to be cleaned up later.

        if self.thePile.get_focus() == self.wiredCB:
            wlessorwired = self.WIRED_IDX
            where = self.thePile.get_focus().get_body().get_focus()[1]
        else:  # self.thePile.get_focus() == self.wlessLB :
            wlessorwired = self.WLESS_IDX
            if self.wlessLB == self.no_wlan:
                where = None
            else:
                where = self.thePile.get_focus().get_focus()[1]
                #where = self.wlessLB.get_focus()[1]
        self.focusloc = [wlessorwired, where]

    # Be clunky until I get to a later stage of development.
    # Update the list of networks.  Usually called by DBus.
    @wrap_exceptions
    def update_netlist(self, state=None, x=None, force_check=False,
      firstrun=False):
        """ Update the list of networks. """
        # Don't even try to do this if we are running a dialog
        if self.diag:
            return
        # Run focus-collecting code if we are not running this for the first
        # time
        if not firstrun:
            self.update_focusloc()
            self.list_header.set_text(gen_list_header())
        # Updates the overall network list.
        if not state:
            state, trash = daemon.GetConnectionStatus()
        if force_check or self.prev_state != state:
            wiredL, wlessL = gen_network_list()

            self.wiredCB.get_body().set_list(wiredL)
            self.wiredCB.get_body().build_combobox(self.frame, ui, 3)
            if len(wlessL) != 0:
                if self.wlessLB == self.no_wlan:
                    self.wlessLB = urwid.ListBox(wlessL)
                else:
                    self.wlessLB.body = urwid.SimpleListWalker(wlessL)
            else:
                self.wlessLB = self.no_wlan
            if daemon.GetAlwaysShowWiredInterface() or wired.CheckPluggedIn():
                self.thePile = urwid.Pile([
                    ('fixed', 1, self.wiredH),
                    ('fixed', 1, self.wiredCB),
                    ('fixed', 2, self.wlessH),
                    self.wlessLB]
                )
                if not firstrun:
                    self.frame.body = self.thePile

                self.thePile.set_focus(self.focusloc[0])
                if self.focusloc[0] == self.WIRED_IDX:
                    self.thePile.get_focus(). \
                        get_body().set_focus(self.focusloc[1])
                else:
                    if self.wlessLB != self.no_wlan:
                        self.thePile.get_focus().set_focus(self.focusloc[1])
                    else:
                        self.thePile.set_focus(self.wiredCB)
            else:
                self.thePile = urwid.Pile([
                    ('fixed', 2, self.wlessH),
                    self.wlessLB
                ])
                if not firstrun:
                    self.frame.body = self.thePile
                if self.focusloc[1] is None:
                    self.focusloc[1] = 0
                if self.wlessLB != self.no_wlan:
                    self.wlessLB.set_focus(self.focusloc[1])

        self.prev_state = state
        if not firstrun:
            self.update_ui()
        if firstrun:
            if wired.GetDefaultWiredNetwork() is not None:
                self.wiredCB.get_body().set_focus(
                    wired.GetWiredProfileList().index(
                        wired.GetDefaultWiredNetwork()
                    )
                )

    @wrap_exceptions
    def update_status(self):
        """ Update the footer / statusbar. """
        wired_connecting = wired.CheckIfWiredConnecting()
        wireless_connecting = wireless.CheckIfWirelessConnecting()
        self.connecting = wired_connecting or wireless_connecting

        fast = not daemon.NeedsExternalCalls()
        if self.connecting:
            if not self.conn_status:
                self.conn_status = True
                gobject.timeout_add(250, self.set_connecting_status, fast)
            return True
        else:
            if check_for_wired(wired.GetWiredIP(''), self.set_status):
                return True
            if not fast:
                iwconfig = wireless.GetIwconfig()
            else:
                iwconfig = ''
            if check_for_wireless(iwconfig, wireless.GetWirelessIP(""),
                    self.set_status):
                return True
            else:
                self.set_status(_('Not connected'))
                self.update_ui()
                return True

    def set_connecting_status(self, fast):
        """ Set connecting status. """
        wired_connecting = wired.CheckIfWiredConnecting()
        wireless_connecting = wireless.CheckIfWirelessConnecting()
        if wireless_connecting:
            if not fast:
                iwconfig = wireless.GetIwconfig()
            else:
                iwconfig = ''
            essid = wireless.GetCurrentNetwork(iwconfig)
            stat = wireless.CheckWirelessConnectingMessage()
            return self.set_status("%s: %s" % (essid, stat), True)
        if wired_connecting:
            return self.set_status(_('Wired Network') +
                    ': ' + wired.CheckWiredConnectingMessage(), True)
        else:
            self.conn_status = False
            return False

    def set_status(self, text, from_idle=False):
        """ Set the status text. """
        # Set the status text, usually called by the update_status method
        # from_idle : a check to see if we are being called directly from the
        # mainloop
        # If we are being called as the result of trying to connect to
        # something, and we aren't connecting to something, return False
        # immediately.

        # Cheap little indicator stating that we are actually connecting
        twirl = ['|', '/', '-', '\\']

        if from_idle and not self.connecting:
            self.update_status()
            self.conn_status = False
            return False
        toAppend = ''
        # If we are connecting and being called from the idle function, spin
        # the wheel.
        if from_idle and self.connecting:
            # This is probably the wrong way to do this, but it works for now.
            self.tcount += 1
            toAppend = twirl[self.tcount % 4]
        self.status_label.set_text(text + ' ' + toAppend)
        self.update_ui()
        return True

    def dbus_scan_finished(self):
        """ Handle DBus scan finish. """
        # I'm pretty sure that I'll need this later.
        #if not self.connecting:
        #    gobject.idle_add(self.refresh_networks, None, False, None)
        self.unlock_screen()
        self.scanning = False

    def dbus_scan_started(self):
        """ Handle DBus scan start. """
        self.scanning = True
        if self.diag_type == 'conf':
            self.restore_primary()
        self.lock_screen()

    def restore_primary(self):
        """ Restore screen. """
        self.diag_type = 'none'
        if self.do_diag_lock or self.scanning:
            self.frame.set_body(self.screen_locker)
            self.do_diag_lock = False
        else:
            self.frame.set_body(self.thePile)
        self.diag = None
        self.frame.set_footer(urwid.Pile([self.primaryCols, self.footer2]))
        self.update_ui()

    def handle_keys(self, keys):
        """ Handle keys. """
        if not self.diag:
            # Handle keystrokes
            if "f8" in keys or 'Q' in keys or 'q' in keys:
                loop.quit()
                #return False
            if "f5" in keys or 'R' in keys:
                self.lock_screen()
                self.doScan()
            if 'k' in keys or 'K' in keys:
                wireless.SwitchRfKill()
                self.update_netlist()
            if "D" in keys:
                # Disconnect from all networks.
                daemon.Disconnect()
                self.update_netlist()
            if 'right' in keys:
                if not self.scanning:
                    focus = self.thePile.get_focus()
                    self.frame.set_footer(
                        urwid.Pile([self.confCols, self.footer2])
                    )
                    if focus == self.wiredCB:
                        self.diag = WiredSettingsDialog(
                            self.wiredCB.get_body().get_selected_profile(),
                            self.frame
                        )
                        self.diag.ready_widgets(ui, self.frame)
                        self.frame.set_body(self.diag)
                    else:
                        # wireless list only other option
                        trash, pos = self.thePile.get_focus().get_focus()
                        self.diag = WirelessSettingsDialog(pos, self.frame)
                        self.diag.ready_widgets(ui, self.frame)
                        self.frame.set_body(self.diag)
                    self.diag_type = 'conf'
            if "enter" in keys or 'C' in keys:
                if not self.scanning:
                    focus = self.frame.body.get_focus()
                    if focus == self.wiredCB:
                        self.special = focus
                        self.connect("wired", 0)
                    else:
                        # wless list only other option, if it is around
                        if self.wlessLB != self.no_wlan:
                            wid, pos = self.thePile.get_focus().get_focus()
                            self.connect("wireless", pos)
            if "esc" in keys:
                # Force disconnect here if connection in progress
                if self.connecting:
                    daemon.CancelConnect()
                    # Prevents automatic reconnecting if that option is enabled
                    daemon.SetForcedDisconnect(True)
            if "P" in keys:
                if not self.pref:
                    self.pref = PrefsDialog(
                        self.frame,
                        (0, 1),
                        ui,
                        dbusmanager.get_dbus_ifaces()
                    )
                self.pref.load_settings()
                self.pref.ready_widgets(ui, self.frame)
                self.frame.set_footer(urwid.Pile([self.prefCols, self.footer2]))
                self.diag = self.pref
                self.diag_type = 'pref'
                self.frame.set_body(self.diag)
                # Halt here, keypress gets passed to the dialog otherwise
                return True
            if "A" in keys:
                about_dialog(self.frame)
            if "I" in keys:
                self.raise_hidden_network_dialog()
            if "H" in keys or 'h' in keys or '?' in keys:
                # FIXME I shouldn't need this, OptCols messes up this one
                # particular button
                if not self.diag:
                    help_dialog(self.frame)
            if "S" in keys:
                focus = self.thePile.get_focus()
                if focus == self.wiredCB:
                    nettype = 'wired'
                    netname = self.wiredCB.get_body().get_selected_profile()
                else:
                    nettype = 'wireless'
                    netname = str(self.wlessLB.get_focus()[1])
                run_configscript(self.frame, netname, nettype)
            if "O" in keys:
                exitcode, data = AdHocDialog().run(ui, self.frame)
                #data = (essid,ip,channel,use_ics,use_encrypt,key_edit)
                if exitcode == 1:
                    wireless.CreateAdHocNetwork(
                        data[0],
                        data[2],
                        data[1],
                        "WEP",
                        data[5],
                        data[4],
                        False
                    )
            if 'X' in keys:
                exitcode, data = ForgetDialog().run(ui, self.frame)
                if exitcode == 1:
                    text = _('Are you sure you want to discard settings for '
                        'the selected networks?')
                    text += '\n\n' + '\n'.join(data['essid'])
                    confirm, trash = TextDialog(text, 20, 50,
                        buttons=[(_('OK'), 1), (_('Cancel'), -1)],
                        ).run(ui, self.frame)
                    if confirm == 1:
                        for x in data['bssid']:
                            wireless.DeleteWirelessNetwork(x)

        for k in keys:
            if urwid.VERSION < (1, 0, 0):
                check_mouse_event = urwid.is_mouse_event
            else:
                check_mouse_event = urwid.util.is_mouse_event
            if check_mouse_event(k):
                event, button, col, row = k
                self.frame.mouse_event(
                    self.size, event, button, col, row, focus=True)
                continue
            k = self.frame.keypress(self.size, k)
            if self.diag:
                if  k == 'esc' or k == 'q' or k == 'Q':
                    self.restore_primary()
                    break
                if k == 'f10':
                    self.diag.save_settings()
                    self.restore_primary()
                    break
            if k == "window resize":
                self.size = ui.get_cols_rows()
                continue

    def call_update_ui(self, source, cb_condition):
        """ Update UI. """
        self.update_ui(True)
        return True

    # Redraw the screen
    @wrap_exceptions
    def update_ui(self, from_key=False):
        """ Redraw the screen. """
        if not ui._started:
            return False

        input_data = ui.get_input_nonblocking()
        # Resolve any "alarms" in the waiting
        self.handle_keys(input_data[1])

        # Update the screen
        canvas = self.frame.render((self.size), True)
        ui.draw_screen((self.size), canvas)
        # Get the input data
        if self.update_tag is not None:
            gobject.source_remove(self.update_tag)
        #if from_key:
        return False

    def connect(self, nettype, networkid, networkentry=None):
        """ Initiates the connection process in the daemon. """
        if nettype == "wireless":
            wireless.ConnectWireless(networkid)
        elif nettype == "wired":
            wired.ConnectWired()
        self.update_status()
Example #5
0
    def handle_keys(self, keys):
        """ Handle keys. """
        if not self.diag:
            # Handle keystrokes
            if "f8" in keys or "Q" in keys or "q" in keys:
                loop.quit()
                # return False
            if "f5" in keys or "R" in keys:
                self.lock_screen()
                self.doScan()
            if "k" in keys or "K" in keys:
                wireless.SwitchRfKill()
                self.update_netlist()
            if "D" in keys:
                # Disconnect from all networks.
                daemon.Disconnect()
                self.update_netlist()
            if "right" in keys:
                if not self.scanning:
                    focus = self.thePile.get_focus()
                    self.frame.set_footer(urwid.Pile([self.confCols, self.footer2]))
                    if focus == self.wiredCB:
                        self.diag = WiredSettingsDialog(self.wiredCB.get_body().get_selected_profile(), self.frame)
                        self.diag.ready_widgets(ui, self.frame)
                        self.frame.set_body(self.diag)
                    else:
                        # wireless list only other option
                        trash, pos = self.thePile.get_focus().get_focus()
                        self.diag = WirelessSettingsDialog(pos, self.frame)
                        self.diag.ready_widgets(ui, self.frame)
                        self.frame.set_body(self.diag)
                    self.diag_type = "conf"
            if "enter" in keys or "C" in keys:
                if not self.scanning:
                    focus = self.frame.body.get_focus()
                    if focus == self.wiredCB:
                        self.special = focus
                        self.connect("wired", 0)
                    else:
                        # wless list only other option, if it is around
                        if self.wlessLB != self.no_wlan:
                            wid, pos = self.thePile.get_focus().get_focus()
                            self.connect("wireless", pos)
            if "esc" in keys:
                # Force disconnect here if connection in progress
                if self.connecting:
                    daemon.CancelConnect()
                    # Prevents automatic reconnecting if that option is enabled
                    daemon.SetForcedDisconnect(True)
            if "P" in keys:
                if not self.pref:
                    self.pref = PrefsDialog(self.frame, (0, 1), ui, dbusmanager.get_dbus_ifaces())
                self.pref.load_settings()
                self.pref.ready_widgets(ui, self.frame)
                self.frame.set_footer(urwid.Pile([self.prefCols, self.footer2]))
                self.diag = self.pref
                self.diag_type = "pref"
                self.frame.set_body(self.diag)
                # Halt here, keypress gets passed to the dialog otherwise
                return True
            if "A" in keys:
                about_dialog(self.frame)
            if "I" in keys:
                self.raise_hidden_network_dialog()
            if "H" in keys or "h" in keys or "?" in keys:
                # FIXME I shouldn't need this, OptCols messes up this one
                # particular button
                if not self.diag:
                    help_dialog(self.frame)
            if "S" in keys:
                focus = self.thePile.get_focus()
                if focus == self.wiredCB:
                    nettype = "wired"
                    netname = self.wiredCB.get_body().get_selected_profile()
                else:
                    nettype = "wireless"
                    netname = str(self.wlessLB.get_focus()[1])
                run_configscript(self.frame, netname, nettype)
            if "O" in keys:
                exitcode, data = AdHocDialog().run(ui, self.frame)
                # data = (essid,ip,channel,use_ics,use_encrypt,key_edit)
                if exitcode == 1:
                    wireless.CreateAdHocNetwork(data[0], data[2], data[1], "WEP", data[5], data[4], False)
            if "X" in keys:
                exitcode, data = ForgetDialog().run(ui, self.frame)
                if exitcode == 1:
                    text = _("Are you sure you want to discard settings for " "the selected networks?")
                    text += "\n\n" + "\n".join(data["essid"])
                    confirm, trash = TextDialog(text, 20, 50, buttons=[(_("OK"), 1), (_("Cancel"), -1)]).run(
                        ui, self.frame
                    )
                    if confirm == 1:
                        for x in data["bssid"]:
                            wireless.DeleteWirelessNetwork(x)

        for k in keys:
            if urwid.VERSION < (1, 0, 0):
                check_mouse_event = urwid.is_mouse_event
            else:
                check_mouse_event = urwid.util.is_mouse_event
            if check_mouse_event(k):
                event, button, col, row = k
                self.frame.mouse_event(self.size, event, button, col, row, focus=True)
                continue
            k = self.frame.keypress(self.size, k)
            if self.diag:
                if k == "esc" or k == "q" or k == "Q":
                    self.restore_primary()
                    break
                # F10 has been changed to S to avoid using function keys,
                # which are often caught by the terminal emulator.
                # But F10 still works, because it doesn't hurt and some users might be used to it.
                if k == "f10" or k == "S" or k == "s":
                    self.diag.save_settings()
                    self.restore_primary()
                    break
            if k == "window resize":
                self.size = ui.get_cols_rows()
                continue
Example #6
0
    def handle_keys(self, keys):
        if not self.diag:
            # Handle keystrokes
            if "f8" in keys or 'Q' in keys or 'q' in keys:
                loop.quit()
                #return False
            if "f5" in keys or 'R' in keys:
                self.lock_screen()
                self.doScan()
            if 'k' in keys or 'K' in keys:
                wireless.SwitchRfKill()
                self.update_netlist()
            if "D" in keys:
                # Disconnect from all networks.
                daemon.Disconnect()
                self.update_netlist()
            if 'right' in keys:
                if not self.scanning:
                    focus = self.thePile.get_focus()
                    self.frame.set_footer(
                        urwid.Pile([self.confCols, self.footer2]))
                    if focus == self.wiredCB:
                        self.diag = WiredSettingsDialog(
                            self.wiredCB.get_body().get_selected_profile())
                        self.frame.set_body(self.diag)
                    else:
                        # wireless list only other option
                        wid, pos = self.thePile.get_focus().get_focus()
                        self.diag = WirelessSettingsDialog(pos, self.frame)
                        self.diag.ready_widgets(ui, self.frame)
                        self.frame.set_body(self.diag)
                    self.diag_type = 'conf'
            if "enter" in keys or 'C' in keys:
                if not self.scanning:
                    focus = self.frame.body.get_focus()
                    if focus == self.wiredCB:
                        self.special = focus
                        self.connect("wired", 0)
                    else:
                        # wless list only other option, if it is around
                        if self.wlessLB != self.no_wlan:
                            wid, pos = self.thePile.get_focus().get_focus()
                            self.connect("wireless", pos)
            if "esc" in keys:
                # Force disconnect here if connection in progress
                if self.connecting:
                    daemon.CancelConnect()
                    # Prevents automatic reconnecting if that option is enabled
                    daemon.SetForcedDisconnect(True)
            if "P" in keys:
                if not self.pref:
                    self.pref = PrefsDialog(self.frame, (0, 1), ui,
                                            dbusmanager.get_dbus_ifaces())
                self.pref.load_settings()
                self.pref.ready_widgets(ui, self.frame)
                self.frame.set_footer(urwid.Pile([self.prefCols,
                                                  self.footer2]))
                self.diag = self.pref
                self.diag_type = 'pref'
                self.frame.set_body(self.diag)
                # Halt here, keypress gets passed to the dialog otherwise
                return True
            if "A" in keys:
                about_dialog(self.frame)
            if "I" in keys:
                self.raise_hidden_network_dialog()
            if "H" in keys or 'h' in keys or '?' in keys:
                # FIXME I shouldn't need this, OptCols messes up this one
                # particular button
                if not self.diag:
                    help_dialog(self.frame)
            if "S" in keys:
                focus = self.thePile.get_focus()
                if focus == self.wiredCB:
                    nettype = 'wired'
                    netname = self.wiredCB.get_body().get_selected_profile()
                else:
                    nettype = 'wireless'
                    netname = str(self.wlessLB.get_focus()[1])
                run_configscript(self.frame, netname, nettype)
            if "O" in keys:
                exitcode, data = AdHocDialog().run(ui, self.frame)
                #data = (essid,ip,channel,use_ics,use_encrypt,key_edit)
                if exitcode == 1:
                    wireless.CreateAdHocNetwork(data[0], data[2], data[1],
                                                "WEP", data[5], data[4], False)

        for k in keys:
            if urwid.util.is_mouse_event(k):
                event, button, col, row = k
                self.frame.mouse_event(self.size,
                                       event,
                                       button,
                                       col,
                                       row,
                                       focus=True)
                continue
            k = self.frame.keypress(self.size, k)
            if self.diag:
                if k == 'esc' or k == 'q' or k == 'Q':
                    self.restore_primary()
                    break
                if k == 'f10':
                    self.diag.save_settings()
                    self.restore_primary()
                    break
            if k == "window resize":
                self.size = ui.get_cols_rows()
                continue