示例#1
0
class AdvancedSettingsDialog(urwid.WidgetWrap):
    """
    Settings dialog.

    Both the wired and the wireless settings preferences dialogs use some of the
    same fields.
    This will be used to produce the individual network settings dialogs way far
    below.
    """
    # pylint: disable-msg=W0231
    def __init__(self):
        self.ui = None
        self.body = None

        self.wired = None
        self.networkid = None

        self.encryption_info = None
        self.encryption_combo = None
        self.encrypt_types = None
        self.encryption_chkbox = None

        static_ip_t = _('Use Static IPs')
        ip_t = ('editcp', _('IP') + ':     ')
        netmask_t = ('editcp', _('Netmask') + ':')
        gateway_t = ('editcp', _('Gateway') + ':')

        use_static_dns_t = _('Use Static DNS')
        use_global_dns_t = _('Use global DNS servers')
        dns_dom_t = ('editcp', _('DNS domain') + ':   ')
        search_dom_t = ('editcp', _('Search domain') + ':')
        dns1_t = ('editcp', _('DNS server') + ' 1' + ':' + ' ' * 8)
        dns2_t = ('editcp', _('DNS server') + ' 2' + ':' + ' ' * 8)
        dns3_t = ('editcp', _('DNS server') + ' 3' + ':' + ' ' * 8)

        use_dhcp_h_t = _('Use DHCP Hostname')
        dhcp_h_t = ('editcp', _('DHCP Hostname') + ': ')

        cancel_t = _('Cancel')
        ok_t = _('OK')

        self.static_ip_cb = urwid.CheckBox(static_ip_t,
                on_state_change=self.static_ip_toggle)
        self.ip_edit = DynWrap(urwid.Edit(ip_t), False)
        self.netmask_edit = DynWrap(urwid.Edit(netmask_t), False)
        self.gateway_edit = DynWrap(urwid.Edit(gateway_t), False)

        self.static_dns_cb = DynWrap(
            urwid.CheckBox(use_static_dns_t, on_state_change=self.dns_toggle),
            True,
            ('body', 'editnfc'),
            None
        )
        self.global_dns_cb = DynWrap(
            urwid.CheckBox(use_global_dns_t, on_state_change=self.dns_toggle),
            False,
            ('body', 'editnfc'),
            None
        )
        self.checkb_cols = urwid.Columns([
            self.static_dns_cb,
            self.global_dns_cb
        ])
        self.dns_dom_edit = DynWrap(urwid.Edit(dns_dom_t), False)
        self.search_dom_edit = DynWrap(urwid.Edit(search_dom_t), False)
        self.dns1 = DynWrap(urwid.Edit(dns1_t), False)
        self.dns2 = DynWrap(urwid.Edit(dns2_t), False)
        self.dns3 = DynWrap(urwid.Edit(dns3_t), False)

        self.use_dhcp_h = urwid.CheckBox(
            use_dhcp_h_t,
            False,
            on_state_change=self.use_dhcp_h_toggle
        )
        self.dhcp_h = DynWrap(urwid.Edit(dhcp_h_t), False)

        _blank = urwid.Text('')

        walker = urwid.SimpleListWalker([
            self.static_ip_cb,
            self.ip_edit,
            self.netmask_edit,
            self.gateway_edit,
            _blank,
            self.checkb_cols,
            self.dns_dom_edit,
            self.search_dom_edit,
            self.dns1, self.dns2, self.dns3,
            _blank,
            self.use_dhcp_h,
            self.dhcp_h,
            _blank
        ])

        self._listbox = urwid.ListBox(walker)
        self._frame = urwid.Frame(self._listbox)

        # pylint: disable-msg=E1101
        self.__super.__init__(self._frame)

    def use_dhcp_h_toggle(self, checkb, new_state, user_data=None):
        """ Set sensitivity of widget. """
        self.dhcp_h.set_sensitive(new_state)

    def static_ip_toggle(self, checkb, new_state, user_data=None):
        """ Set sensitivity of widget. """
        for w in [self.ip_edit, self.netmask_edit, self.gateway_edit]:
            w.set_sensitive(new_state)
        self.static_dns_cb.set_state(new_state)
        self.static_dns_cb.set_sensitive(not new_state)
        if new_state:
            self.checkb_cols.set_focus(self.global_dns_cb)
        else:
            self.checkb_cols.set_focus(self.static_dns_cb)

    def dns_toggle(self, checkb, new_state, user_data=None):
        """ Set sensitivity of widget. """
        if checkb == self.static_dns_cb.get_w():
            for w in [
                self.dns_dom_edit,
                self.search_dom_edit,
                self.dns1,
                self.dns2,
                self.dns3
            ]:
                w.set_sensitive(new_state)
            if not new_state:
                self.global_dns_cb.set_state(False, do_callback=False)
            self.global_dns_cb.set_sensitive(new_state)
        # use_global_dns_cb is DynWrapped
        if checkb == self.global_dns_cb.get_w():
            for w in [self.dns_dom_edit, self.search_dom_edit,
                    self.dns1, self.dns2, self.dns3 ]:
                w.set_sensitive(not new_state)

    def set_net_prop(self, option, value):
        """ Set network property. MUST BE OVERRIDEN. """
        raise NotImplementedError

    # Code totally yanked from netentry.py
    def save_settings(self):
        """ Save settings common to wired and wireless settings dialogs. """
        if self.static_ip_cb.get_state():
            for i in [
                self.ip_edit,
                self.netmask_edit,
                self.gateway_edit
            ]:
                i.set_edit_text(i.get_edit_text().strip())

            self.set_net_prop("ip", noneToString(self.ip_edit.get_edit_text()))
            self.set_net_prop("netmask",
                noneToString(self.netmask_edit.get_edit_text()))
            self.set_net_prop("gateway",
                noneToString(self.gateway_edit.get_edit_text()))
        else:
            self.set_net_prop("ip", '')
            self.set_net_prop("netmask", '')
            self.set_net_prop("gateway", '')

        if self.static_dns_cb.get_state() and \
           not self.global_dns_cb.get_state():
            self.set_net_prop('use_static_dns', True)
            self.set_net_prop('use_global_dns', False)
            # Strip addressses before checking them in the daemon.
            for i in [
                self.dns1,
                self.dns2,
                self.dns3,
                self.dns_dom_edit,
                self.search_dom_edit
            ]:
                i.set_edit_text(i.get_edit_text().strip())
            self.set_net_prop('dns_domain',
                noneToString(self.dns_dom_edit.get_edit_text()))
            self.set_net_prop("search_domain",
                noneToString(self.search_dom_edit.get_edit_text()))
            self.set_net_prop("dns1", noneToString(self.dns1.get_edit_text()))
            self.set_net_prop("dns2", noneToString(self.dns2.get_edit_text()))
            self.set_net_prop("dns3", noneToString(self.dns3.get_edit_text()))
        elif self.static_dns_cb.get_state() and \
             self.global_dns_cb.get_state():
            self.set_net_prop('use_static_dns', True)
            self.set_net_prop('use_global_dns', True)
        else:
            self.set_net_prop('use_static_dns', False)
            self.set_net_prop('use_global_dns', False)
            self.set_net_prop('dns_domain', '')
            self.set_net_prop("search_domain", '')
            self.set_net_prop("dns1", '')
            self.set_net_prop("dns2", '')
            self.set_net_prop("dns3", '')
        self.set_net_prop('dhcphostname', self.dhcp_h.get_edit_text())
        self.set_net_prop('usedhcphostname', self.use_dhcp_h.get_state())

    # Prevent comboboxes from dying.
    def ready_widgets(self, ui, body):
        """ Build comboboxes. """
        self.ui = ui
        self.body = body
        self.encryption_combo.build_combobox(body, ui, 14)
        self.change_encrypt_method()

    def combo_on_change(self, combobox, new_index, user_data=None):
        """ Handle change of item in the combobox. """
        self.change_encrypt_method()

    # More or less ripped from netentry.py
    def change_encrypt_method(self):
        """ Change encrypt method based on combobox. """
        #self.lbox_encrypt = urwid.ListBox()
        self.encryption_info = {}
        wid, ID = self.encryption_combo.get_focus()
        methods = self.encrypt_types

        # pylint: disable-msg=E0203
        if self._w.body.body.__contains__(self.pile_encrypt):
            self._w.body.body.pop(self._w.body.body.__len__() - 1)

        # If nothing is selected, select the first entry.
        if ID == -1:
            self.encryption_combo.set_focus(0)
            ID = 0

        theList = []
        for type_ in ['required', 'optional']:
            fields = methods[ID][type_]
            for field in fields:
                try:
                    text = language[field[1].lower().replace(' ', '_')]
                except KeyError:
                    text = field[1].replace(' ', '_')
                edit = MaskingEdit(('editcp', text + ': '))
                edit.set_mask_mode('no_focus')
                theList.append(edit)
                # Add the data to any array, so that the information
                # can be easily accessed by giving the name of the wanted
                # data.
                self.encryption_info[field[0]] = [edit, type_]

                if self.wired:
                    edit.set_edit_text(noneToBlankString(
                        wired.GetWiredProperty(field[0])))
                else:
                    edit.set_edit_text(noneToBlankString(
                        wireless.GetWirelessProperty(self.networkid, field[0])))

        #FIXME: This causes the entire pile to light up upon use.
        # Make this into a listbox?
        self.pile_encrypt = DynWrap(
            urwid.Pile(theList),
            attrs=('editbx', 'editnfc')
        )

        self.pile_encrypt.set_sensitive(self.encryption_chkbox.get_state())

        self._w.body.body.insert(self._w.body.body.__len__(), self.pile_encrypt)
        #self._w.body.body.append(self.pile_encrypt)

    def encryption_toggle(self, chkbox, new_state, user_data=None):
        """ Set sensitivity of widget. """
        self.encryption_combo.set_sensitive(new_state)
        self.pile_encrypt.set_sensitive(new_state)
示例#2
0
class AdvancedSettingsDialog(urwid.WidgetWrap):
    def __init__(self):
        self.ui=None

        static_ip_t = _('Use Static IPs')
        ip_t        = ('editcp',_('IP')+':     ')
        netmask_t   = ('editcp',_('Netmask')+':')
        gateway_t   = ('editcp',_('Gateway')+':')

        use_static_dns_t = _('Use Static DNS')
        use_global_dns_t = _('Use global DNS servers')
        dns_dom_t    = ('editcp',_('DNS domain')+':   ')
        search_dom_t = ('editcp',_('Search domain')+':')
        dns1_t       = ('editcp',_('DNS server')+ ' 1'+':'+' '*8)
        dns2_t       = ('editcp',_('DNS server')+ ' 2'+':'+' '*8)
        dns3_t       = ('editcp',_('DNS server')+ ' 3'+':'+' '*8)
        
        use_dhcp_h_t = _('Use DHCP Hostname')
        dhcp_h_t     = ('editcp',_('DHCP Hostname')+': ')
        
        cancel_t = _('Cancel')
        ok_t = _('OK')
        
        self.static_ip_cb = urwid.CheckBox(static_ip_t,
                on_state_change=self.static_ip_toggle)
        self.ip_edit      = DynWrap(urwid.Edit(ip_t),False)
        self.netmask_edit = DynWrap(urwid.Edit(netmask_t),False)
        self.gateway_edit = DynWrap(urwid.Edit(gateway_t),False)


        self.static_dns_cb = DynWrap(urwid.CheckBox(use_static_dns_t,
                on_state_change=self.dns_toggle),True,('body','editnfc'),None)
        self.global_dns_cb = DynWrap(urwid.CheckBox(use_global_dns_t,
                on_state_change=self.dns_toggle),False,('body','editnfc'),None)
        self.checkb_cols = urwid.Columns([self.static_dns_cb,
                                     self.global_dns_cb])
        self.dns_dom_edit      = DynWrap(urwid.Edit(dns_dom_t)   ,False)
        self.search_dom_edit   = DynWrap(urwid.Edit(search_dom_t),False)
        self.dns1              = DynWrap(urwid.Edit(dns1_t)      ,False)
        self.dns2              = DynWrap(urwid.Edit(dns2_t)      ,False)
        self.dns3              = DynWrap(urwid.Edit(dns3_t)      ,False)

        self.use_dhcp_h        = urwid.CheckBox(use_dhcp_h_t,False,on_state_change=self.use_dhcp_h_toggle)
        self.dhcp_h            = DynWrap(urwid.Edit(dhcp_h_t),False)

        _blank = urwid.Text('')

        walker = urwid.SimpleListWalker([self.static_ip_cb,
                                         self.ip_edit,
                                         self.netmask_edit,
                                         self.gateway_edit,
                                         _blank,
                                         self.checkb_cols,
                                         self.dns_dom_edit,self.search_dom_edit,
                                         self.dns1,self.dns2,self.dns3,
                                         _blank,
                                         self.use_dhcp_h,
                                         self.dhcp_h,
                                         _blank
                                        ])



        self._listbox = urwid.ListBox(walker)
        self._frame = urwid.Frame(self._listbox)
        self.__super.__init__(self._frame)
    
    def use_dhcp_h_toggle(self,checkb,new_state,user_data=None):
        self.dhcp_h.set_sensitive(new_state)

    def static_ip_toggle(self,checkb,new_state,user_data=None):
        for w in [ self.ip_edit,self.netmask_edit,self.gateway_edit ]:
            w.set_sensitive(new_state)
        self.static_dns_cb.set_state(new_state)
        self.static_dns_cb.set_sensitive(not new_state)
        if new_state:
            self.checkb_cols.set_focus(self.global_dns_cb)
        else:
            self.checkb_cols.set_focus(self.static_dns_cb)

        
    def dns_toggle(self,checkb,new_state,user_data=None):
        if checkb == self.static_dns_cb.get_w():
            for w in [ self.dns_dom_edit,self.search_dom_edit,
                    self.dns1,self.dns2,self.dns3 ]:
                w.set_sensitive(new_state)
            if not new_state:
                self.global_dns_cb.set_state(False,do_callback=False)
            self.global_dns_cb.set_sensitive(new_state)
        # use_global_dns_cb is DynWrapped
        if checkb == self.global_dns_cb.get_w():
            for w in [self.dns_dom_edit,self.search_dom_edit,
                    self.dns1,self.dns2,self.dns3 ]:
                w.set_sensitive(not new_state)

    # Code totally yanked from netentry.py
    def save_settings(self):
        """ Save settings common to wired and wireless settings dialogs. """
        if self.static_ip_cb.get_state():
            for i in [self.ip_edit,self.netmask_edit,self.gateway_edit]:
                i.set_edit_text(i.get_edit_text().strip())

            self.set_net_prop("ip", noneToString(self.ip_edit.get_edit_text()))
            self.set_net_prop("netmask", noneToString(self.netmask_edit.get_edit_text()))
            self.set_net_prop("gateway", noneToString(self.gateway_edit.get_edit_text()))
        else:
            self.set_net_prop("ip", '')
            self.set_net_prop("netmask", '')
            self.set_net_prop("gateway", '')

        if self.static_dns_cb.get_state() and \
           not self.global_dns_cb.get_state():
            self.set_net_prop('use_static_dns', True)
            self.set_net_prop('use_global_dns', False)
            # Strip addressses before checking them in the daemon.
            for i in [self.dns1, self.dns2,
                      self.dns3,self.dns_dom_edit, self.search_dom_edit]:
                i.set_edit_text(i.get_edit_text().strip())
            self.set_net_prop('dns_domain', noneToString(self.dns_dom_edit.get_edit_text()))
            self.set_net_prop("search_domain", noneToString(self.search_dom_edit.get_edit_text()))
            self.set_net_prop("dns1", noneToString(self.dns1.get_edit_text()))
            self.set_net_prop("dns2", noneToString(self.dns2.get_edit_text()))
            self.set_net_prop("dns3", noneToString(self.dns3.get_edit_text()))
        elif self.static_dns_cb.get_state() and \
             self.global_dns_cb.get_state():
            self.set_net_prop('use_static_dns', True)
            self.set_net_prop('use_global_dns', True)
        else:
            self.set_net_prop('use_static_dns', False)
            self.set_net_prop('use_global_dns', False)
            self.set_net_prop('dns_domain', '')
            self.set_net_prop("search_domain", '')
            self.set_net_prop("dns1", '')
            self.set_net_prop("dns2", '')
            self.set_net_prop("dns3", '')
        self.set_net_prop('dhcphostname',self.dhcp_h.get_edit_text())
        self.set_net_prop('usedhcphostname',self.use_dhcp_h.get_state())
    # Prevent comboboxes from dying.
    def ready_widgets(self,ui,body):
        pass
示例#3
0
class AdvancedSettingsDialog(urwid.WidgetWrap):
    """
    Settings dialog.

    Both the wired and the wireless settings preferences dialogs use some of the
    same fields.
    This will be used to produce the individual network settings dialogs way far
    below.
    """

    # pylint: disable-msg=W0231
    def __init__(self):
        self.ui = None
        self.body = None

        self.wired = None
        self.networkid = None

        self.encryption_info = None
        self.encryption_combo = None
        self.encrypt_types = None
        self.encryption_chkbox = None

        static_ip_t = _('Use Static IPs')
        ip_t = ('editcp', _('IP') + ':     ')
        netmask_t = ('editcp', _('Netmask') + ':')
        gateway_t = ('editcp', _('Gateway') + ':')

        use_static_dns_t = _('Use Static DNS')
        use_global_dns_t = _('Use global DNS servers')
        dns_dom_t = ('editcp', _('DNS domain') + ':   ')
        search_dom_t = ('editcp', _('Search domain') + ':')
        dns1_t = ('editcp', _('DNS server') + ' 1' + ':' + ' ' * 8)
        dns2_t = ('editcp', _('DNS server') + ' 2' + ':' + ' ' * 8)
        dns3_t = ('editcp', _('DNS server') + ' 3' + ':' + ' ' * 8)

        use_dhcp_h_t = _('Use DHCP Hostname')
        dhcp_h_t = ('editcp', _('DHCP Hostname') + ': ')

        cancel_t = _('Cancel')
        ok_t = _('OK')

        self.static_ip_cb = urwid.CheckBox(
            static_ip_t, on_state_change=self.static_ip_toggle)
        self.ip_edit = DynWrap(urwid.Edit(ip_t), False)
        self.netmask_edit = DynWrap(urwid.Edit(netmask_t), False)
        self.gateway_edit = DynWrap(urwid.Edit(gateway_t), False)

        self.static_dns_cb = DynWrap(
            urwid.CheckBox(use_static_dns_t, on_state_change=self.dns_toggle),
            True, ('body', 'editnfc'), None)
        self.global_dns_cb = DynWrap(
            urwid.CheckBox(use_global_dns_t, on_state_change=self.dns_toggle),
            False, ('body', 'editnfc'), None)
        self.checkb_cols = urwid.Columns(
            [self.static_dns_cb, self.global_dns_cb])
        self.dns_dom_edit = DynWrap(urwid.Edit(dns_dom_t), False)
        self.search_dom_edit = DynWrap(urwid.Edit(search_dom_t), False)
        self.dns1 = DynWrap(urwid.Edit(dns1_t), False)
        self.dns2 = DynWrap(urwid.Edit(dns2_t), False)
        self.dns3 = DynWrap(urwid.Edit(dns3_t), False)

        self.use_dhcp_h = urwid.CheckBox(
            use_dhcp_h_t, False, on_state_change=self.use_dhcp_h_toggle)
        self.dhcp_h = DynWrap(urwid.Edit(dhcp_h_t), False)

        _blank = urwid.Text('')

        walker = urwid.SimpleListWalker([
            self.static_ip_cb, self.ip_edit, self.netmask_edit,
            self.gateway_edit, _blank, self.checkb_cols, self.dns_dom_edit,
            self.search_dom_edit, self.dns1, self.dns2, self.dns3, _blank,
            self.use_dhcp_h, self.dhcp_h, _blank
        ])

        self._listbox = urwid.ListBox(walker)
        self._frame = urwid.Frame(self._listbox)

        # pylint: disable-msg=E1101
        self.__super.__init__(self._frame)

    def use_dhcp_h_toggle(self, checkb, new_state, user_data=None):
        """ Set sensitivity of widget. """
        self.dhcp_h.set_sensitive(new_state)

    def static_ip_toggle(self, checkb, new_state, user_data=None):
        """ Set sensitivity of widget. """
        for w in [self.ip_edit, self.netmask_edit, self.gateway_edit]:
            w.set_sensitive(new_state)
        self.static_dns_cb.set_state(new_state)
        self.static_dns_cb.set_sensitive(not new_state)
        if new_state:
            self.checkb_cols.set_focus(self.global_dns_cb)
        else:
            self.checkb_cols.set_focus(self.static_dns_cb)

    def dns_toggle(self, checkb, new_state, user_data=None):
        """ Set sensitivity of widget. """
        if checkb == self.static_dns_cb.get_w():
            for w in [
                    self.dns_dom_edit, self.search_dom_edit, self.dns1,
                    self.dns2, self.dns3
            ]:
                w.set_sensitive(new_state)
            if not new_state:
                self.global_dns_cb.set_state(False, do_callback=False)
            self.global_dns_cb.set_sensitive(new_state)
        # use_global_dns_cb is DynWrapped
        if checkb == self.global_dns_cb.get_w():
            for w in [
                    self.dns_dom_edit, self.search_dom_edit, self.dns1,
                    self.dns2, self.dns3
            ]:
                w.set_sensitive(not new_state)

    def set_net_prop(self, option, value):
        """ Set network property. MUST BE OVERRIDEN. """
        raise NotImplementedError

    # Code totally yanked from netentry.py
    def save_settings(self):
        """ Save settings common to wired and wireless settings dialogs. """
        if self.static_ip_cb.get_state():
            for i in [self.ip_edit, self.netmask_edit, self.gateway_edit]:
                i.set_edit_text(i.get_edit_text().strip())

            self.set_net_prop("ip", noneToString(self.ip_edit.get_edit_text()))
            self.set_net_prop("netmask",
                              noneToString(self.netmask_edit.get_edit_text()))
            self.set_net_prop("gateway",
                              noneToString(self.gateway_edit.get_edit_text()))
        else:
            self.set_net_prop("ip", '')
            self.set_net_prop("netmask", '')
            self.set_net_prop("gateway", '')

        if self.static_dns_cb.get_state() and \
           not self.global_dns_cb.get_state():
            self.set_net_prop('use_static_dns', True)
            self.set_net_prop('use_global_dns', False)
            # Strip addressses before checking them in the daemon.
            for i in [
                    self.dns1, self.dns2, self.dns3, self.dns_dom_edit,
                    self.search_dom_edit
            ]:
                i.set_edit_text(i.get_edit_text().strip())
            self.set_net_prop('dns_domain',
                              noneToString(self.dns_dom_edit.get_edit_text()))
            self.set_net_prop(
                "search_domain",
                noneToString(self.search_dom_edit.get_edit_text()))
            self.set_net_prop("dns1", noneToString(self.dns1.get_edit_text()))
            self.set_net_prop("dns2", noneToString(self.dns2.get_edit_text()))
            self.set_net_prop("dns3", noneToString(self.dns3.get_edit_text()))
        elif self.static_dns_cb.get_state() and \
             self.global_dns_cb.get_state():
            self.set_net_prop('use_static_dns', True)
            self.set_net_prop('use_global_dns', True)
        else:
            self.set_net_prop('use_static_dns', False)
            self.set_net_prop('use_global_dns', False)
            self.set_net_prop('dns_domain', '')
            self.set_net_prop("search_domain", '')
            self.set_net_prop("dns1", '')
            self.set_net_prop("dns2", '')
            self.set_net_prop("dns3", '')
        self.set_net_prop('dhcphostname', self.dhcp_h.get_edit_text())
        self.set_net_prop('usedhcphostname', self.use_dhcp_h.get_state())

    # Prevent comboboxes from dying.
    def ready_widgets(self, ui, body):
        """ Build comboboxes. """
        self.ui = ui
        self.body = body
        self.encryption_combo.build_combobox(body, ui, 14)
        self.change_encrypt_method()

    def combo_on_change(self, combobox, new_index, user_data=None):
        """ Handle change of item in the combobox. """
        self.change_encrypt_method()

    # More or less ripped from netentry.py
    def change_encrypt_method(self):
        """ Change encrypt method based on combobox. """
        #self.lbox_encrypt = urwid.ListBox()
        self.encryption_info = {}
        wid, ID = self.encryption_combo.get_focus()
        methods = self.encrypt_types

        # pylint: disable-msg=E0203
        if self._w.body.body.__contains__(self.pile_encrypt):
            self._w.body.body.pop(self._w.body.body.__len__() - 1)

        # If nothing is selected, select the first entry.
        if ID == -1:
            self.encryption_combo.set_focus(0)
            ID = 0

        theList = []
        for type_ in ['required', 'optional']:
            fields = methods[ID][type_]
            for field in fields:
                try:
                    text = language[field[1].lower().replace(' ', '_')]
                except KeyError:
                    text = field[1].replace(' ', '_')
                edit = MaskingEdit(('editcp', text + ': '))
                edit.set_mask_mode('no_focus')
                theList.append(edit)
                # Add the data to any array, so that the information
                # can be easily accessed by giving the name of the wanted
                # data.
                self.encryption_info[field[0]] = [edit, type_]

                if self.wired:
                    edit.set_edit_text(
                        noneToBlankString(wired.GetWiredProperty(field[0])))
                else:
                    edit.set_edit_text(
                        noneToBlankString(
                            wireless.GetWirelessProperty(
                                self.networkid, field[0])))

        #FIXME: This causes the entire pile to light up upon use.
        # Make this into a listbox?
        self.pile_encrypt = DynWrap(urwid.Pile(theList),
                                    attrs=('editbx', 'editnfc'))

        self.pile_encrypt.set_sensitive(self.encryption_chkbox.get_state())

        self._w.body.body.insert(self._w.body.body.__len__(),
                                 self.pile_encrypt)
        #self._w.body.body.append(self.pile_encrypt)

    def encryption_toggle(self, chkbox, new_state, user_data=None):
        """ Set sensitivity of widget. """
        self.encryption_combo.set_sensitive(new_state)
        self.pile_encrypt.set_sensitive(new_state)
示例#4
0
class AdvancedSettingsDialog(urwid.WidgetWrap):
    def __init__(self):
        self.ui=None

        static_ip_t = language['use_static_ip']
        ip_t        = ('editcp',language['ip']+':     ')
        netmask_t   = ('editcp',language['netmask']+':')
        gateway_t   = ('editcp',language['gateway']+':')

        use_static_dns_t = language['use_static_dns']
        use_global_dns_t = language['use_global_dns']
        dns_dom_t    = ('editcp',language['dns_domain']+':   ')
        search_dom_t = ('editcp',language['search_domain']+':')
        dns1_t       = ('editcp',language['dns']+ ' 1'+':'+' '*8)
        dns2_t       = ('editcp',language['dns']+ ' 2'+':'+' '*8)
        dns3_t       = ('editcp',language['dns']+ ' 3'+':'+' '*8)
        
        use_dhcp_h_t = ("Use DHCP Hostname")
        dhcp_h_t     = ('editcp',"DHCP Hostname: ")
        
        cancel_t = 'Cancel'
        ok_t = 'OK'
        
        self.static_ip_cb = urwid.CheckBox(static_ip_t,
                on_state_change=self.static_ip_toggle)
        self.ip_edit      = DynWrap(urwid.Edit(ip_t),False)
        self.netmask_edit = DynWrap(urwid.Edit(netmask_t),False)
        self.gateway_edit = DynWrap(urwid.Edit(gateway_t),False)


        self.static_dns_cb = DynWrap(urwid.CheckBox(use_static_dns_t,
                on_state_change=self.dns_toggle),True,('body','editnfc'),None)
        self.global_dns_cb = DynWrap(urwid.CheckBox(use_global_dns_t,
                on_state_change=self.dns_toggle),False,('body','editnfc'),None)
        self.checkb_cols = urwid.Columns([self.static_dns_cb,
                                     self.global_dns_cb])
        self.dns_dom_edit      = DynWrap(urwid.Edit(dns_dom_t)   ,False)
        self.search_dom_edit   = DynWrap(urwid.Edit(search_dom_t),False)
        self.dns1              = DynWrap(urwid.Edit(dns1_t)      ,False)
        self.dns2              = DynWrap(urwid.Edit(dns2_t)      ,False)
        self.dns3              = DynWrap(urwid.Edit(dns3_t)      ,False)

        self.use_dhcp_h        = urwid.CheckBox(use_dhcp_h_t,False,on_state_change=self.use_dhcp_h_toggle)
        self.dhcp_h            = DynWrap(urwid.Edit(dhcp_h_t),False)

        _blank = urwid.Text('')

        walker = urwid.SimpleListWalker([self.static_ip_cb,
                                         self.ip_edit,
                                         self.netmask_edit,
                                         self.gateway_edit,
                                         _blank,
                                         self.checkb_cols,
                                         self.dns_dom_edit,self.search_dom_edit,
                                         self.dns1,self.dns2,self.dns3,
                                         _blank,
                                         self.use_dhcp_h,
                                         self.dhcp_h,
                                         _blank
                                        ])



        self._listbox = urwid.ListBox(walker)
        self._frame = urwid.Frame(self._listbox)
        self.__super.__init__(self._frame)
    
    def use_dhcp_h_toggle(self,checkb,new_state,user_data=None):
        self.dhcp_h.set_sensitive(new_state)

    def static_ip_toggle(self,checkb,new_state,user_data=None):
        for w in [ self.ip_edit,self.netmask_edit,self.gateway_edit ]:
            w.set_sensitive(new_state)
        self.static_dns_cb.set_state(new_state)
        self.static_dns_cb.set_sensitive(not new_state)
        if new_state:
            self.checkb_cols.set_focus(self.global_dns_cb)
        else:
            self.checkb_cols.set_focus(self.static_dns_cb)

        
    def dns_toggle(self,checkb,new_state,user_data=None):
        if checkb == self.static_dns_cb.get_w():
            for w in [ self.dns_dom_edit,self.search_dom_edit,
                    self.dns1,self.dns2,self.dns3 ]:
                w.set_sensitive(new_state)
            if not new_state:
                self.global_dns_cb.set_state(False,do_callback=False)
            self.global_dns_cb.set_sensitive(new_state)
        # use_global_dns_cb is DynWrapped
        if checkb == self.global_dns_cb.get_w():
            for w in [self.dns_dom_edit,self.search_dom_edit,
                    self.dns1,self.dns2,self.dns3 ]:
                w.set_sensitive(not new_state)

    # Code totally yanked from netentry.py
    def save_settings(self):
        """ Save settings common to wired and wireless settings dialogs. """
        if self.static_ip_cb.get_state():
            for i in [self.ip_edit,self.netmask_edit,self.gateway_edit]:
                i.set_edit_text(i.get_edit_text().strip())

            self.set_net_prop("ip", noneToString(self.ip_edit.get_edit_text()))
            self.set_net_prop("netmask", noneToString(self.netmask_edit.get_edit_text()))
            self.set_net_prop("gateway", noneToString(self.gateway_edit.get_edit_text()))
        else:
            self.set_net_prop("ip", '')
            self.set_net_prop("netmask", '')
            self.set_net_prop("gateway", '')

        if self.static_dns_cb.get_state() and \
           not self.global_dns_cb.get_state():
            self.set_net_prop('use_static_dns', True)
            self.set_net_prop('use_global_dns', False)
            # Strip addressses before checking them in the daemon.
            for i in [self.dns1, self.dns2,
                      self.dns3,self.dns_dom_edit, self.search_dom_edit]:
                i.set_edit_text(i.get_edit_text().strip())
            self.set_net_prop('dns_domain', noneToString(self.dns_dom_edit.get_edit_text()))
            self.set_net_prop("search_domain", noneToString(self.search_dom_edit.get_edit_text()))
            self.set_net_prop("dns1", noneToString(self.dns1.get_edit_text()))
            self.set_net_prop("dns2", noneToString(self.dns2.get_edit_text()))
            self.set_net_prop("dns3", noneToString(self.dns3.get_edit_text()))
        elif self.static_dns_cb.get_state() and \
             self.global_dns_cb.get_state():
            self.set_net_prop('use_static_dns', True)
            self.set_net_prop('use_global_dns', True)
        else:
            self.set_net_prop('use_static_dns', False)
            self.set_net_prop('use_global_dns', False)
            self.set_net_prop('dns_domain', '')
            self.set_net_prop("search_domain", '')
            self.set_net_prop("dns1", '')
            self.set_net_prop("dns2", '')
            self.set_net_prop("dns3", '')
        self.set_net_prop('dhcphostname',self.dhcp_h.get_edit_text())
        self.set_net_prop('usedhcphostname',self.use_dhcp_h.get_state())
    # Prevent comboboxes from dying.
    def ready_widgets(self,ui,body):
        pass