def add_switcher(self):
     if not hasattr(self, "device_tree") or not self.device_tree:
         self.device_tree = TreeView([DeviceItem()], mask_bound_height=0)
         self.device_tree.set_expand_column(1)
         self.wireless_box.pack_start(self.device_tree, False, False)
         self.wireless_box.reorder_child(
             self.wireless_box.get_children()[-2],
             len(self.wireless_box.get_children()))
         tray_log.debug(self.wireless_box.get_children())
         net_manager.emit_wifi_switch(0)
 def set_active(self, state, emit=False):
     '''
     state format : (dev_state, con_state)
     '''
     tray_log.debug("someone set button", state)
     #print "---------------------"
     #print "someone set off button"
     #print "state", state
     #print "active", self.get_active()
     #print "------------------------"
     (dev_state, con_state) = state
     if dev_state is False:
         self.offbutton.set_active(False)
         self.label.set_sensitive(dev_state)
         self.offbutton.set_sensitive(dev_state)
     else:
         self.label.set_sensitive(dev_state)
         self.offbutton.set_sensitive(dev_state)
         self.offbutton.set_active(con_state)
     if emit:
         self.offbutton.emit("toggled")
    def set_visible_aps(self, show_all=False):
        if not self.__ap_list:
            self.visible_aps = []
            return

        tray_log.debug(len(self.__ap_list))

        if show_all:
            if len(self.__ap_list) <= 10:
                self.visible_aps = self.__ap_list[:]
            else:
                self.visible_aps = self.__ap_list[:10]
            self.more_button.set_ap_list([])
            self.show_all = True

        else:
            if len(self.__ap_list) <= 5:
                self.visible_aps = self.__ap_list[:]
                self.show_all = True
            else:
                self.visible_aps = self.__ap_list[:5]
                self.more_button.set_ap_list(self.__ap_list[5:])
                self.show_all = False
    def __init__(self,
                 connection,
                 ssid,
                 key_mgmt=None,
                 default_width=330,
                 default_height=120,
                 confirm_callback=None, 
                 cancel_callback=None,
                 ):
        '''
        Initialize InputDialog class.
        
        @param title: Input dialog title.
        @param init_text: Initialize input text.
        @param default_width: Width of dialog, default is 330 pixel.
        @param default_height: Height of dialog, default is 330 pixel.
        @param confirm_callback: Callback when user click confirm button, this callback accept one argument that return by user input text.
        @param cancel_callback: Callback when user click cancel button, this callback not need argument.
        '''
        # Init.
        #DialogBox.__init__(self, _("Set password"), default_width, default_height, DIALOG_MASK_SINGLE_PAGE)
        DialogBox.__init__(self,
                           _("Please input password for %s") % ssid,
                           default_width,
                           default_height,
                           DIALOG_MASK_SINGLE_PAGE)

        #self.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_NORMAL)
        self.confirm_callback = confirm_callback
        self.cancel_callback = cancel_callback
    
        self.connection = connection
        
        self.hint_align = gtk.Alignment()
        self.hint_align.set(0.5, 0.5, 0, 0)
        self.hint_align.set_padding(0, 0, 10, 10)
        self.hint_text = Label(_("Please input password for %s")%ssid,
                               enable_select=False,
                               enable_double_click=False)
        self.hint_align.add(self.hint_text)

        self.entry_align = gtk.Alignment()
        self.entry_align.set(0.0, 0.5, 0, 0)
        self.entry_align.set_padding(10, 0, 5, 9)
        if self.connection and isinstance(self.connection, NMRemoteConnection):
            (setting_name, method) = self.connection.guess_secret_info()  
            if setting_name and method:
                init_text = nm_module.secret_agent.agent_get_secrets(self.connection.object_path,
                                                        setting_name,
                                                        method)
            else:
                init_text = ""
        else:
            tray_log.debug()
            self.connection = nm_module.nm_remote_settings.new_wireless_connection(ssid, key_mgmt)
            init_text = ''
        self.entry = PasswordEntry(init_text)
        self.show_key_check = CheckButton(_("Show password"), 0)
        self.show_key_check.connect("toggled", self.show_key_check_button_cb)

        self.entry.set_size(default_width - 22, 25)
        self.main_box = gtk.VBox()
        entry_align = gtk.Alignment(0.0, 0.5, 0, 0)
        entry_align.set_padding(0, 0, 5, 0)
        entry_align.set_size_request(-1, 30)
        entry_align.add(self.entry)
        self.main_box.pack_start(entry_align, False, False)
        self.main_box.pack_start(self.show_key_check, False, False)
        
        self.confirm_button = Button(_("OK"))
        self.cancel_button = Button(_("Cancel"))
        
        self.entry.entry.connect("press-return", lambda w: self.click_confirm_button())
        self.confirm_button.connect("clicked", lambda w: self.click_confirm_button())
        self.cancel_button.connect("clicked", lambda w: self.click_cancel_button())
        
        self.entry_align.add(self.main_box)
        #self.body_box.pack_start(self.hint_align, True, True)
        self.body_box.pack_start(self.entry_align, True, True)

        #self.body_box.pack_start(self.main_box, True, True)
        
        self.right_button_box.set_buttons([self.cancel_button, self.confirm_button])
        self.connect("show", self.focus_input)
    def __init__(
        self,
        connection,
        ssid,
        key_mgmt=None,
        default_width=330,
        default_height=120,
        confirm_callback=None,
        cancel_callback=None,
    ):
        '''
        Initialize InputDialog class.
        
        @param title: Input dialog title.
        @param init_text: Initialize input text.
        @param default_width: Width of dialog, default is 330 pixel.
        @param default_height: Height of dialog, default is 330 pixel.
        @param confirm_callback: Callback when user click confirm button, this callback accept one argument that return by user input text.
        @param cancel_callback: Callback when user click cancel button, this callback not need argument.
        '''
        # Init.
        #DialogBox.__init__(self, _("Set password"), default_width, default_height, DIALOG_MASK_SINGLE_PAGE)
        DialogBox.__init__(self,
                           _("Please input password for %s") % ssid,
                           default_width, default_height,
                           DIALOG_MASK_SINGLE_PAGE)

        #self.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_NORMAL)
        self.confirm_callback = confirm_callback
        self.cancel_callback = cancel_callback

        self.connection = connection

        self.hint_align = gtk.Alignment()
        self.hint_align.set(0.5, 0.5, 0, 0)
        self.hint_align.set_padding(0, 0, 10, 10)
        self.hint_text = Label(_("Please input password for %s") % ssid,
                               enable_select=False,
                               enable_double_click=False)
        self.hint_align.add(self.hint_text)

        self.entry_align = gtk.Alignment()
        self.entry_align.set(0.0, 0.5, 0, 0)
        self.entry_align.set_padding(10, 0, 5, 9)
        if self.connection and isinstance(self.connection, NMRemoteConnection):
            (setting_name, method) = self.connection.guess_secret_info()
            if setting_name and method:
                init_text = nm_module.secret_agent.agent_get_secrets(
                    self.connection.object_path, setting_name, method)
            else:
                init_text = ""
        else:
            tray_log.debug()
            self.connection = nm_module.nm_remote_settings.new_wireless_connection(
                ssid, key_mgmt)
            init_text = ''
        self.entry = PasswordEntry(init_text)
        self.show_key_check = CheckButton(_("Show password"), 0)
        self.show_key_check.connect("toggled", self.show_key_check_button_cb)

        self.entry.set_size(default_width - 22, 25)
        self.main_box = gtk.VBox()
        entry_align = gtk.Alignment(0.0, 0.5, 0, 0)
        entry_align.set_padding(0, 0, 5, 0)
        entry_align.set_size_request(-1, 30)
        entry_align.add(self.entry)
        self.main_box.pack_start(entry_align, False, False)
        self.main_box.pack_start(self.show_key_check, False, False)

        self.confirm_button = Button(_("OK"))
        self.cancel_button = Button(_("Cancel"))

        self.entry.entry.connect("press-return",
                                 lambda w: self.click_confirm_button())
        self.confirm_button.connect("clicked",
                                    lambda w: self.click_confirm_button())
        self.cancel_button.connect("clicked",
                                   lambda w: self.click_cancel_button())

        self.entry_align.add(self.main_box)
        #self.body_box.pack_start(self.hint_align, True, True)
        self.body_box.pack_start(self.entry_align, True, True)

        #self.body_box.pack_start(self.main_box, True, True)

        self.right_button_box.set_buttons(
            [self.cancel_button, self.confirm_button])
        self.connect("show", self.focus_input)
 def set_wired_state(self, widget, new_state, reason):
     if new_state is 20:
         self.wire.set_active(0)
     else:
         tray_log.debug(__name__, new_state, reason)