コード例 #1
0
    def create_source_update_frequency_table(self):
        main_table = gtk.Table(3, 2)
        main_table.set_row_spacings(CONTENT_ROW_SPACING)

        dir_title_label = Label(_("Refresh package lists"))

        # auto update check button
        self.is_auto_update_button = CheckButton(label_text=_('Upgrade automatically'))
        self.is_auto_update_button.connect('released', self.change_auto_update)
        self.is_auto_update_button.set_active(utils.is_auto_update())

        self.update_label = Label(_("Time interval: "))
        self.update_spin = SpinBox(int(get_update_interval()), 0, 168, 1)
        self.update_spin.connect("value-changed", lambda w, v: set_update_interval(v))
        self.hour_lablel = Label(_(" hour"))
        self.hour_lablel.set_size_request(50, 12)
        spin_hbox = gtk.HBox(spacing=3)
        spin_hbox.pack_start(self.update_label, False, False)
        spin_hbox.pack_start(self.update_spin, False, False)
        spin_hbox.pack_start(self.hour_lablel, False, False)

        main_table.attach(dir_title_label, 0, 2, 0, 1, yoptions=gtk.FILL)
        main_table.attach(create_separator_box(), 0, 2, 1, 2, yoptions=gtk.FILL)
        main_table.attach(self.is_auto_update_button, 0, 1, 2, 3, xoptions=gtk.FILL)
        main_table.attach(spin_hbox, 1, 2, 2, 3, xpadding=10, xoptions=gtk.FILL)
        return main_table
コード例 #2
0
    def create_source_update_frequency_table(self):
        main_table = gtk.Table(3, 2)
        main_table.set_row_spacings(CONTENT_ROW_SPACING)
        
        dir_title_label = Label(_("Update applications lists"))
        dir_title_label.set_size_request(200, 12)
        label_align = gtk.Alignment()
        label_align.set_padding(0, 0, 0, 0)
        label_align.add(dir_title_label)

        self.is_auto_update_button = CheckButton(label_text=_('Update automatically'))
        self.is_auto_update_button.connect('toggled', self.change_auto_update)
        
        self.update_label = Label(_("Time interval: "))
        self.update_spin = SpinBox(int(get_update_interval()), 0, 168, 1)
        self.update_spin.connect("value-changed", lambda w, v: set_update_interval(v))
        self.hour_lablel = Label(_(" hour"))
        self.hour_lablel.set_size_request(50, 12)
        spin_hbox = gtk.HBox(spacing=3)
        spin_hbox.pack_start(self.update_label, False, False)
        spin_hbox.pack_start(self.update_spin, False, False)
        spin_hbox.pack_start(self.hour_lablel, False, False)

        main_table.attach(label_align, 0, 2, 0, 1, yoptions=gtk.FILL, xpadding=8)
        main_table.attach(create_separator_box(), 0, 2, 1, 2, yoptions=gtk.FILL)
        main_table.attach(self.is_auto_update_button, 0, 1, 2, 3, xpadding=10, xoptions=gtk.FILL)
        main_table.attach(spin_hbox, 1, 2, 2, 3, xpadding=10, xoptions=gtk.FILL)

        if is_auto_update():
            self.is_auto_update_button.set_active(True)
        else:
            self.is_auto_update_button.toggled()

        return main_table
コード例 #3
0
ファイル: preference.py プロジェクト: kissthink/deepin-store
    def create_source_update_frequency_table(self):
        main_table = gtk.Table(3, 2)
        main_table.set_row_spacings(CONTENT_ROW_SPACING)

        dir_title_label = Label(_("Refresh package lists"))

        # auto update check button
        self.is_auto_update_button = CheckButton(label_text=_('Upgrade automatically'))
        self.is_auto_update_button.connect('released', self.change_auto_update)
        self.is_auto_update_button.set_active(utils.is_auto_update())

        self.update_label = Label(_("Time interval: "))
        self.update_spin = SpinBox(int(get_update_interval()), 0, 168, 1)
        self.update_spin.connect("value-changed", lambda w, v: set_update_interval(v))
        self.hour_lablel = Label(_(" hour"))
        self.hour_lablel.set_size_request(50, 12)
        spin_hbox = gtk.HBox(spacing=3)
        spin_hbox.pack_start(self.update_label, False, False)
        spin_hbox.pack_start(self.update_spin, False, False)
        spin_hbox.pack_start(self.hour_lablel, False, False)

        main_table.attach(dir_title_label, 0, 2, 0, 1, yoptions=gtk.FILL)
        main_table.attach(create_separator_box(), 0, 2, 1, 2, yoptions=gtk.FILL)
        main_table.attach(self.is_auto_update_button, 0, 1, 2, 3, xoptions=gtk.FILL)
        main_table.attach(spin_hbox, 1, 2, 2, 3, xpadding=10, xoptions=gtk.FILL)
        return main_table
コード例 #4
0
    def __row_entry_spin(self, label_name, table, types):
        label = Label(label_name,
                      text_size=CONTENT_FONT_SIZE,
                      enable_select=False,
                      enable_double_click=False)
        label.set_can_focus(False)

        label_align = style.wrap_with_align(label, width = 260)

        entry = InputEntry()
        entry.set_size(self.ENTRY_WIDTH, 22)
        spin = SpinBox(0, 0, 49151, 1, 60)
        spin.value_entry.connect("changed", lambda w, v: spin.update_and_emit(int(v)))

        hbox = gtk.HBox(spacing=10)
        hbox.set_size_request(-1 ,22)
        hbox_align = style.wrap_with_align(hbox, align="left")
        hbox.pack_start(entry)
        hbox.pack_start(spin)

        table.row_attach((label_align, hbox_align))
        return [entry, spin]
コード例 #5
0
    def __row_entry_spin(self, label_name, table, types):
        label = Label(label_name,
                      text_size=CONTENT_FONT_SIZE,
                      enable_select=False,
                      enable_double_click=False)
        label.set_can_focus(False)

        label_align = style.wrap_with_align(label, width=260)

        entry = InputEntry()
        entry.set_size(self.ENTRY_WIDTH, 22)
        spin = SpinBox(0, 0, 49151, 1, 60)
        spin.value_entry.connect("changed",
                                 lambda w, v: spin.update_and_emit(int(v)))

        hbox = gtk.HBox(spacing=10)
        hbox.set_size_request(-1, 22)
        hbox_align = style.wrap_with_align(hbox, align="left")
        hbox.pack_start(entry)
        hbox.pack_start(spin)

        table.row_attach((label_align, hbox_align))
        return [entry, spin]
コード例 #6
0
ファイル: preference.py プロジェクト: kissthink/deepin-store
class MirrorsBox(BaseBox):
    def __init__(self):
        BaseBox.__init__(self)

        self.current_mirror_item = None

        self.select_best_mirror_button_texts = {
                "normal": _("Select the best mirror"),
                "wait": _("Waiting"),
                "success": _("Successfully")
                }

        self.main_box.pack_start(self.create_mirror_select_table(), True, True)
        self.main_box.pack_start(self.create_source_update_frequency_table(), False, True)
        self.mirror_test_obj = None

        global_event.register_event("mirror-test-finished", self.finish_mirror_test)
        global_event.register_event("cancel-mirror-test", self.cancel_mirror_test)
        global_event.register_event("mirror-backend-changed", self.mirror_changed_handler)

    def create_source_update_frequency_table(self):
        main_table = gtk.Table(3, 2)
        main_table.set_row_spacings(CONTENT_ROW_SPACING)

        dir_title_label = Label(_("Refresh package lists"))

        # auto update check button
        self.is_auto_update_button = CheckButton(label_text=_('Upgrade automatically'))
        self.is_auto_update_button.connect('released', self.change_auto_update)
        self.is_auto_update_button.set_active(utils.is_auto_update())

        self.update_label = Label(_("Time interval: "))
        self.update_spin = SpinBox(int(get_update_interval()), 0, 168, 1)
        self.update_spin.connect("value-changed", lambda w, v: set_update_interval(v))
        self.hour_lablel = Label(_(" hour"))
        self.hour_lablel.set_size_request(50, 12)
        spin_hbox = gtk.HBox(spacing=3)
        spin_hbox.pack_start(self.update_label, False, False)
        spin_hbox.pack_start(self.update_spin, False, False)
        spin_hbox.pack_start(self.hour_lablel, False, False)

        main_table.attach(dir_title_label, 0, 2, 0, 1, yoptions=gtk.FILL)
        main_table.attach(create_separator_box(), 0, 2, 1, 2, yoptions=gtk.FILL)
        main_table.attach(self.is_auto_update_button, 0, 1, 2, 3, xoptions=gtk.FILL)
        main_table.attach(spin_hbox, 1, 2, 2, 3, xpadding=10, xoptions=gtk.FILL)
        return main_table

    def change_auto_update(self, widget, data=None):
        widget_active = widget.get_active()
        self.update_spin.set_sensitive(widget_active)
        self.update_label.set_sensitive(widget_active)
        self.hour_lablel.set_sensitive(widget_active)

        utils.set_auto_update(widget_active)

        daemon_running = is_dbus_name_exists(DSC_UPDATE_DAEMON_NAME)
        if widget_active and not daemon_running:
            dsc_daemon_path = os.path.join(get_parent_dir(__file__, 2), 'update_data/apt/dsc-daemon.py')
            subprocess.Popen(['python', dsc_daemon_path], stderr=subprocess.STDOUT, shell=False)
        elif not widget_active and daemon_running:
            session = dbus.SessionBus()
            dbus_obj = session.get_object(DSC_UPDATE_DAEMON_NAME, DSC_UPDATE_DAEMON_PATH)
            iface = dbus.Interface(dbus_obj, DSC_UPDATE_DAEMON_NAME)
            iface.quit()

    def select_best_mirror(self, widget):
        widget.set_label(self.select_best_mirror_button_texts["wait"])
        widget.set_sensitive(False)
        global_event.emit("toggle-waiting-dialog", True)
        utils.ThreadMethod(self.change_to_nearest_mirror_thread, (widget, )).start()

    def cancel_mirror_test(self):
        if self.mirror_test_obj:
            self.mirror_test_obj.cancel()
            self.mirror_test_obj = None
            self.finish_mirror_test("")

    def change_to_nearest_mirror_thread(self, widget):
        from mirror_speed.ip_detect import get_nearest_mirrors
        hostnames = get_nearest_mirrors()
        self.mirror_test_obj = MirrorTest(hostnames)
        hostname = self.mirror_test_obj.run()
        for mirror in self.mirrors_list:
            if mirror.hostname == hostname:
                global_event.emit("mirror-test-finished", mirror)
                break

    def finish_mirror_test(self, mirror):
        for item in self.mirror_view.visible_items:
            if item.mirror == mirror:
                self.mirror_view.visible_item(item)
        self.select_best_mirror_button.set_sensitive(True)
        self.select_best_mirror_button.set_label(self.select_best_mirror_button_texts["normal"])

    def create_mirror_select_table(self):
        main_table = gtk.Table(3, 2)
        main_table.set_row_spacings(CONTENT_ROW_SPACING)

        mirror_select_title = Label(_("Select mirror"))
        self.select_best_mirror_button = Button(self.select_best_mirror_button_texts["normal"])
        self.select_best_mirror_button.connect("clicked", self.select_best_mirror)

        self.mirrors_dir = os.path.join(get_parent_dir(__file__, 2), 'mirrors')
        self.current_mirror_hostname = utils.get_current_mirror_hostname()
        self.mirror_items = self.get_mirror_items()
        self.mirror_view = TreeView(self.mirror_items,
                                enable_drag_drop=False,
                                enable_multiple_select=False,
                                mask_bound_height=0,
                             )
        self.mirror_view.set_expand_column(1)
        self.mirror_view.set_size_request(-1, 280)
        self.mirror_view.draw_mask = self.mirror_treeview_draw_mask

        main_table.attach(mirror_select_title, 0, 1, 0, 1, yoptions=gtk.FILL)
        main_table.attach(self.select_best_mirror_button, 1, 2, 0, 1, xoptions=gtk.FILL)
        main_table.attach(create_separator_box(), 0, 2, 1, 2, xoptions=gtk.FILL)
        main_table.attach(self.mirror_view, 0, 2, 2, 3, xoptions=gtk.FILL)


        return main_table

    def mirror_changed_handler(self, mirror):
        item = None
        for i in self.mirror_view.visible_items:
            if i.mirror == mirror:
                item = i
                break
        if item:
            self.current_mirror_item = item
            for i in self.mirror_items:
                if i != item and i.radio_button.active == True:
                    i.radio_button.active = False
                elif i == item:
                    i.radio_button.active = True
            self.mirror_view.queue_draw()
            self.mirror_view.visible_item(item)

    def mirror_treeview_draw_mask(self, cr, x, y, w, h):
        cr.set_source_rgba(1, 1, 1, 0.5)
        cr.rectangle(x, y, w, h)
        cr.fill()

    def get_mirror_items(self):
        items = []
        self.mirrors_list = get_mirrors()
        for m in self.mirrors_list:
            item = MirrorItem(m, self.mirror_clicked_callback)
            if m.hostname == self.current_mirror_hostname:
                item.radio_button.active = True
                self.current_mirror_item = item
            items.append(item)

        items.sort(key=lambda item:item.mirror.priority)
        return items

    def mirror_clicked_callback(self, item):
        if item != self.current_mirror_item:
            global_event.emit('start-change-mirror', item.mirror)
コード例 #7
0
    def __init__(self, connection, set_button_cb, settings_obj=None):
        gtk.VBox.__init__(self)
        self.tab_name = _("Wireless")
        self.connection = connection 
        self.set_button = set_button_cb
        # 新增settings_obj变量,用于访问shared_methods.Settings对象
        self.settings_obj = settings_obj

        self.wireless = self.connection.get_setting("802-11-wireless")
        ### UI
        self.ssid_label = Label(_("SSID:"),
                                enable_select=False,
                                enable_double_click=False)
        self.ssid_entry = InputEntry()
        self.ssid_entry.set_size(self.ENTRY_WIDTH, 22)

        self.mode_label = Label(_("Mode:"),
                               enable_select=False,
                               enable_double_click=False)
        self.mode_combo = ComboBox([(_("Infrastructure"),"infrastructure"),(_("Ad-hoc"), "adhoc")], fixed_width=130)
        
        # TODO need to put this section to personal wifi
        self.band_label = Label(_("Band:"),
                               enable_select=False,
                               enable_double_click=False)
                                
        self.band_combo = ComboBox([(_("Automatic"), None),
                                    ("a (5 GHZ)", "a"),
                                    ("b/g (2.4)", "bg")],
                                    fixed_width=self.ENTRY_WIDTH)
        self.channel_label = Label(_("Channel:"),
                                   enable_select=False,
                                   enable_double_click=False)
        self.channel_spin = SpinBox(0, 0, 1500, 1, self.ENTRY_WIDTH)
        # BSSID
        self.bssid_label = Label(_("BSSID:"),
                                 enable_select=False,
                                 enable_double_click=False)
        self.bssid_entry = MACEntry()
        self.mac_address_label = Label(_("Device Mac Address:"),
                                 enable_select=False,
                                 enable_double_click=False)
        self.mac_entry = MACEntry()
        self.clone_addr_label = Label(_("Cloned Mac Address:"),
                                 enable_select=False,
                                 enable_double_click=False)
        self.clone_entry = MACEntry()

        self.mtu_label = Label(_("MTU:"),
                           enable_select=False,
                           enable_double_click=False)
        self.mtu_spin = SpinBox(0, 0, 1500, 1, 130)

        self.table = gtk.Table(8, 2, False)

        """
        wrap with alignment
        """
        widget_list = ["ssid_label", "ssid_entry", "mode_label", "mode_combo",
                       "band_label", "band_combo", "channel_label", "channel_spin",
                       "bssid_label", "bssid_entry", "mac_address_label", "mac_entry",
                       "clone_addr_label", "clone_entry", "mtu_label", "mtu_spin"]

        for widget in widget_list:
            item = getattr(self, widget)
            if widget.endswith("label"):
                item.set_can_focus(False)
                align = style.wrap_with_align(item, width=210)
            else:
                align = style.wrap_with_align(item, align="left")
            setattr(self, widget + "_align", align)

        #TODO UI change
        style.draw_background_color(self)
        #align = style.set_box_with_align(self.table, 'text')
        style.set_table(self.table)

        self.section = SettingSection(_("Default Settings"), always_show= False, revert=True, label_right=True, has_seperator=False)
        self.pack_start(self.section, False, False)
        self.section.toggle_off = self.use_default_setting
        self.section.toggle_on = self.use_user_setting
        self.section.load([self.table])
        #self.pack_start(self.table, False, False)
        #self.table.set_size_request(340, 227)

        #self.ssid_entry.set_size_request(130, 22)
        self.bssid_entry.set_size_request(130, 22)
        self.mac_entry.set_size_request(130, 22)
        self.clone_entry.set_size_request(130, 22)

        self.reset()
        #self.mode_combo.connect("item-selected", self.mode_combo_selected)
        self.band_combo.connect("item-selected", self.band_combo_selected)
        self.mtu_spin.connect("value-changed", self.spin_value_changed, "mtu")
        self.mtu_spin.value_entry.connect("changed", self.spin_user_set)
        self.channel_spin.connect("value-changed", self.spin_value_changed, "channel")
        self.ssid_entry.entry.connect("changed", self.entry_changed, "ssid")
        self.bssid_entry.connect("changed", self.entry_changed, "bssid")
        self.mac_entry.connect("changed", self.entry_changed, "mac_address")
        self.clone_entry.connect("changed", self.entry_changed, "cloned_mac_address")
コード例 #8
0
class DscPreferenceDialog(PreferenceDialog):
    def __init__(self):
        PreferenceDialog.__init__(self, 566, 488)

        self.current_mirror_item = None
        self.normal_settings = gtk.VBox()
        self.normal_settings.set_spacing(TABLE_ROW_SPACING)
        self.normal_settings.pack_start(self.create_uninstall_box(), False, True)
        self.normal_settings.pack_start(self.create_download_dir_table(), False, True)

        self.normal_settings_align = gtk.Alignment(0, 0, 1, 1)
        self.normal_settings_align.set_padding(padding_left=5, padding_right=5, padding_top=25, padding_bottom=10)
        self.normal_settings_align.add(self.normal_settings)

        self.mirror_settings = gtk.VBox()
        self.mirror_settings.set_app_paintable(True)
        self.mirror_settings.connect("expose-event", self.mirror_settings_align_expose)
        self.mirror_settings.set_spacing(TABLE_ROW_SPACING)
        self.mirror_settings.pack_start(self.create_mirror_select_table(), False, True)
        self.mirror_settings.pack_start(self.create_source_update_frequency_table(), False, True)

        self.mirror_settings_inner_align = gtk.Alignment(0.5, 0.5, 1, 1)
        self.mirror_settings_inner_align.set_padding(padding_top=25, padding_bottom=10, padding_left=0, padding_right=0)
        self.mirror_settings_inner_align.add(self.mirror_settings)

        self.mirror_settings_scrolled_win = ScrolledWindow()
        self.mirror_settings_scrolled_win.add_child(self.mirror_settings_inner_align)

        self.mirror_settings_align = gtk.Alignment(0, 0, 1, 1)
        self.mirror_settings_align.set_padding(padding_left=0, padding_right=0, padding_top=0, padding_bottom=3)
        self.mirror_settings_align.add(self.mirror_settings_scrolled_win)

        self.set_preference_items([
            (_("General"), self.normal_settings_align),
            (_("Mirrors"), self.mirror_settings_align),
            (_("About"), AboutBox()),
            ])
        
    def mirror_settings_align_expose(self, widget, event=None):
        cr = widget.window.cairo_create()
        rect = widget.allocation

        # draw backgound
        cr.rectangle(*rect)
        #cr.set_source_rgb(*color_hex_to_cairo("#ff0000"))
        cr.set_source_rgba(1, 1, 1, 0)
        cr.fill()

    def mirror_select_action(self, repo_urls):
        self.data_manager.change_source_list(repo_urls, reply_handler=handle_dbus_reply, error_handler=handle_dbus_error)

    def create_mirror_select_table(self):
        vbox = gtk.VBox()
        vbox.set_size_request(423, -1)
        main_table = gtk.Table(2, 2)
        main_table.set_row_spacings(CONTENT_ROW_SPACING)
        
        dir_title_label = Label(_("Select mirror"))
        dir_title_label.set_size_request(423, 12)
        label_align = gtk.Alignment()
        label_align.set_padding(0, 0, 10, 0)
        label_align.add(dir_title_label)

        self.mirrors_dir = os.path.join(get_parent_dir(__file__, 2), 'mirrors')
        self.current_mirror_hostname = utils.get_current_mirror_hostname()
        self.mirror_items = self.get_mirror_items()
        self.mirror_view = TreeView(self.mirror_items,
                                enable_drag_drop=False,
                                enable_multiple_select=False,
                                #mask_bound_height=0,
                             )
        self.mirror_view.set_expand_column(1)
        self.mirror_view.set_size_request(-1, len(self.mirror_view.visible_items) * self.mirror_view.visible_items[0].get_height())
        self.mirror_view.draw_mask = self.mirror_treeview_draw_mask
        #self.display_current_mirror()

        self.mirror_test_progressbar = ProgressBar()

        main_table.attach(label_align, 0, 2, 0, 1, yoptions=gtk.FILL, xpadding=8)
        main_table.attach(create_separator_box(), 0, 2, 1, 2, yoptions=gtk.FILL)
        
        title = _("Select best mirror")
        info_message = _("Please wait. The process will take 30 seconds or more depending on your network connection")
        self.select_best_mirror_dialog = WaitingDialog(title, info_message, self.cancel_mirror_test)
        global_event.register_event("mirror-changed", self.mirror_changed_handler)
        global_event.register_event("update-list-finish", self.update_list_finish_handler)

        vbox.pack_start(main_table, False, False)
        vbox.pack_start(self.mirror_view, False, False)

        return vbox

    def cancel_mirror_test(self, widget):
        try:
            self.mirror_test.terminated = True
            gobject.source_remove(self.update_status_id)
        except:
            pass
        self.select_best_mirror_dialog.hide_all()

    def update_list_finish_handler(self):
        self.select_best_mirror_dialog.hide_all()

    def mirror_changed_handler(self, item):
        for i in self.mirror_items:
            if i != item and i.radio_button.active == True:
                i.radio_button.active = False
            elif i == item:
                i.radio_button.active = True
        self.mirror_view.queue_draw()
    
    def test_mirror_action(self, widget):
        self.select_best_mirror_dialog.set_transient_for(self)
        self.select_best_mirror_dialog.set_position(gtk.WIN_POS_CENTER_ON_PARENT)
        self.select_best_mirror_dialog.show_all()
        distro = aptsources.distro.get_distro()
        #distro.get_sources(SourcesList())
        pipe = os.popen("dpkg --print-architecture")
        arch = pipe.read().strip()
        test_file = "dists/%s/Contents-%s.gz" % \
                    (
                    distro.codename,
                    #"quantal",
                    arch,
                    )

        self.mirror_test = MirrorTest(self.mirrors_list, test_file)
        self.mirror_test.start()

        # now run the tests in a background thread, and update the UI on each event
        self.update_status_id = gtk.timeout_add(100, self.update_progress)

    def update_progress(self):
        if self.mirror_test.running:
            return True
        else:
            time.sleep(1)
            if self.mirror_test.best != None:
                for item in self.mirror_items:
                    if item.mirror == self.mirror_test.best[1]:
                        print item.mirror.get_repo_urls()
                        self.mirror_clicked_callback(item)
            else:
                self.select_best_mirror_dialog.loading_widget.hide_all()
                self.select_best_mirror_dialog.info_message_label.set_text(_("Test for downloading mirror failed. Please check your network connection."))
                self.select_best_mirror_dialog.close_button.set_label(_("Close"))
            return False

    def mirror_treeview_draw_mask(self, cr, x, y, w, h):
        cr.set_source_rgba(1, 1, 1, 0.9)
        cr.rectangle(x, y, w, h)
        cr.fill()

    def get_mirror_items(self):
        items = []
        self.mirrors_list = []
        for ini_file in os.listdir(self.mirrors_dir):
            m = Mirror(os.path.join(self.mirrors_dir, ini_file))
            item = MirrorItem(m, self.mirror_clicked_callback)
            if m.hostname == self.current_mirror_hostname:
                item.radio_button.active = True
                self.current_mirror_item = item
            self.mirrors_list.append(m)
            items.append(item)
        
        items.sort(key=lambda x:x.mirror.priority)
        
        return items

    def mirror_clicked_callback(self, item):
        if item != self.current_mirror_item:
            self.current_mirror_item = item
            global_event.emit('change-mirror', item)
            self.hide_all()

    def create_source_update_frequency_table(self):
        main_table = gtk.Table(3, 2)
        main_table.set_row_spacings(CONTENT_ROW_SPACING)
        
        dir_title_label = Label(_("Update applications lists"))
        dir_title_label.set_size_request(200, 12)
        label_align = gtk.Alignment()
        label_align.set_padding(0, 0, 0, 0)
        label_align.add(dir_title_label)

        self.is_auto_update_button = CheckButton(label_text=_('Update automatically'))
        self.is_auto_update_button.connect('toggled', self.change_auto_update)
        
        self.update_label = Label(_("Time interval: "))
        self.update_spin = SpinBox(int(get_update_interval()), 0, 168, 1)
        self.update_spin.connect("value-changed", lambda w, v: set_update_interval(v))
        self.hour_lablel = Label(_(" hour"))
        self.hour_lablel.set_size_request(50, 12)
        spin_hbox = gtk.HBox(spacing=3)
        spin_hbox.pack_start(self.update_label, False, False)
        spin_hbox.pack_start(self.update_spin, False, False)
        spin_hbox.pack_start(self.hour_lablel, False, False)

        main_table.attach(label_align, 0, 2, 0, 1, yoptions=gtk.FILL, xpadding=8)
        main_table.attach(create_separator_box(), 0, 2, 1, 2, yoptions=gtk.FILL)
        main_table.attach(self.is_auto_update_button, 0, 1, 2, 3, xpadding=10, xoptions=gtk.FILL)
        main_table.attach(spin_hbox, 1, 2, 2, 3, xpadding=10, xoptions=gtk.FILL)

        if is_auto_update():
            self.is_auto_update_button.set_active(True)
        else:
            self.is_auto_update_button.toggled()

        return main_table

    def create_download_dir_table(self):    
        main_table = gtk.Table(4, 2)
        main_table.set_row_spacings(CONTENT_ROW_SPACING)
        
        dir_title_label = Label(_("Download settings"))
        dir_title_label.set_size_request(200, 12)
        label_align = gtk.Alignment()
        label_align.set_padding(0, 0, 0, 0)
        label_align.add(dir_title_label)

        download_number_label = Label(_('Max download task number: '))
        self.download_number_comobox = ComboBox(
                items = [(str(i+1), i+1) for i in range(10)],
                select_index = int(get_download_number())-1,
                )
        self.download_number_comobox.connect("item-selected", self.download_number_comobox_changed)
        download_number_hbox = gtk.HBox(spacing=5)
        download_number_hbox.pack_start(download_number_label, False, False)
        download_number_hbox.pack_start(self.download_number_comobox, False, False)
        
        change_download_dir_label = Label(_("Download directory: "))
        self.dir_entry = InputEntry()
        self.dir_entry.set_text(get_software_download_dir())
        self.dir_entry.set_editable(False)
        self.dir_entry.set_size(200, 25)
        
        modify_button = Button(_("Change"))
        modify_button.connect("clicked", self.change_download_save_dir)
        download_dir_hbox = gtk.HBox(spacing=5)
        download_dir_hbox.pack_start(change_download_dir_label, False, False)
        download_dir_hbox.pack_start(self.dir_entry, False, False)
        download_dir_hbox.pack_start(modify_button, False, False)
        
        main_table.attach(label_align, 0, 2, 0, 1, yoptions=gtk.FILL, xpadding=8)
        main_table.attach(create_separator_box(), 0, 2, 1, 2, yoptions=gtk.FILL)
        main_table.attach(download_number_hbox, 0, 2, 2, 3, xpadding=10, xoptions=gtk.FILL)
        main_table.attach(download_dir_hbox, 0, 2, 3, 4, xpadding=10, xoptions=gtk.FILL)
        return main_table

    def create_uninstall_box(self):
        main_table = gtk.Table(2, 2)
        main_table.set_row_spacings(CONTENT_ROW_SPACING)
        uninstall_title_label = Label(_("On uninstall software"))
        uninstall_title_label.set_size_request(350, 12)
        
        # mini_check_button

        self.delete_check_button = CheckButton(_("Delete configuration files"))
        self.delete_check_button.set_active(get_purg_flag())
        self.delete_check_button.connect("toggled", lambda w: set_purge_flag(self.delete_check_button.get_active()))
        
        main_table.attach(uninstall_title_label, 0, 2, 0, 1, yoptions=gtk.FILL, xpadding=8)
        main_table.attach(create_separator_box(), 0, 2, 1, 2, yoptions=gtk.FILL)
        main_table.attach(self.delete_check_button, 0, 1, 2, 3, yoptions=gtk.FILL)
        
        return main_table

    def change_download_save_dir(self, widget):
        local_dir = WinDir(False).run()
        if local_dir:
            local_dir = os.path.expanduser(local_dir)
            if local_dir != get_software_download_dir():
                self.dir_entry.set_editable(True)        
                self.dir_entry.set_text(local_dir)
                self.dir_entry.set_editable(False)
                set_software_download_dir(local_dir)
                global_event.emit('download-directory-changed')

    def download_number_comobox_changed(self, widget, name, value, index):
        set_download_number(value)
        global_event.emit('max-download-number-changed', value)

    def change_auto_update(self, widget, data=None):
        self.update_spin.set_sensitive(widget.get_active())
        set_auto_update(widget.get_active())
        self.update_label.set_sensitive(widget.get_active())
        self.hour_lablel.set_sensitive(widget.get_active())
        dsc_daemon_path = os.path.join(get_parent_dir(__file__, 2), 'update_data/apt/dsc-daemon.py')
        if widget.get_active():
            subprocess.Popen(['python', dsc_daemon_path], stderr=subprocess.STDOUT, shell=False)
コード例 #9
0
    def row_spin(self, label_name, low, high, table=None):
        label = self.__label(label_name)
        spin = SpinBox(0, low, high, 1, self.right_width)
        self._wrap_align((label, spin), table)

        return spin
コード例 #10
0
class Wireless(gtk.VBox):
    ENTRY_WIDTH = 222

    def __init__(self, connection, set_button_cb, settings_obj=None):
        gtk.VBox.__init__(self)
        self.tab_name = _("Wireless")
        self.connection = connection
        self.set_button = set_button_cb
        # 新增settings_obj变量,用于访问shared_methods.Settings对象
        self.settings_obj = settings_obj

        self.wireless = self.connection.get_setting("802-11-wireless")
        ### UI
        self.ssid_label = Label(_("SSID:"),
                                enable_select=False,
                                enable_double_click=False)
        self.ssid_entry = InputEntry()
        self.ssid_entry.set_size(self.ENTRY_WIDTH, 22)

        self.mode_label = Label(_("Mode:"),
                                enable_select=False,
                                enable_double_click=False)
        self.mode_combo = ComboBox([(_("Infrastructure"), "infrastructure"),
                                    (_("Ad-hoc"), "adhoc")],
                                   fixed_width=130)

        # TODO need to put this section to personal wifi
        self.band_label = Label(_("Band:"),
                                enable_select=False,
                                enable_double_click=False)

        self.band_combo = ComboBox([(_("Automatic"), None), ("a (5 GHZ)", "a"),
                                    ("b/g (2.4)", "bg")],
                                   fixed_width=self.ENTRY_WIDTH)
        self.channel_label = Label(_("Channel:"),
                                   enable_select=False,
                                   enable_double_click=False)
        self.channel_spin = SpinBox(0, 0, 1500, 1, self.ENTRY_WIDTH)
        # BSSID
        self.bssid_label = Label(_("BSSID:"),
                                 enable_select=False,
                                 enable_double_click=False)
        self.bssid_entry = MACEntry()
        self.mac_address_label = Label(_("Device Mac Address:"),
                                       enable_select=False,
                                       enable_double_click=False)
        self.mac_entry = MACEntry()
        self.clone_addr_label = Label(_("Cloned Mac Address:"),
                                      enable_select=False,
                                      enable_double_click=False)
        self.clone_entry = MACEntry()

        self.mtu_label = Label(_("MTU:"),
                               enable_select=False,
                               enable_double_click=False)
        self.mtu_spin = SpinBox(0, 0, 1500, 1, 130)

        self.table = gtk.Table(8, 2, False)
        """
        wrap with alignment
        """
        widget_list = [
            "ssid_label", "ssid_entry", "mode_label", "mode_combo",
            "band_label", "band_combo", "channel_label", "channel_spin",
            "bssid_label", "bssid_entry", "mac_address_label", "mac_entry",
            "clone_addr_label", "clone_entry", "mtu_label", "mtu_spin"
        ]

        for widget in widget_list:
            item = getattr(self, widget)
            if widget.endswith("label"):
                item.set_can_focus(False)
                align = style.wrap_with_align(item, width=210)
            else:
                align = style.wrap_with_align(item, align="left")
            setattr(self, widget + "_align", align)

        #TODO UI change
        style.draw_background_color(self)
        #align = style.set_box_with_align(self.table, 'text')
        style.set_table(self.table)

        self.section = SettingSection(_("Default Settings"),
                                      always_show=False,
                                      revert=True,
                                      label_right=True,
                                      has_seperator=False)
        self.pack_start(self.section, False, False)
        self.section.toggle_off = self.use_default_setting
        self.section.toggle_on = self.use_user_setting
        self.section.load([self.table])
        #self.pack_start(self.table, False, False)
        #self.table.set_size_request(340, 227)

        #self.ssid_entry.set_size_request(130, 22)
        self.bssid_entry.set_size_request(130, 22)
        self.mac_entry.set_size_request(130, 22)
        self.clone_entry.set_size_request(130, 22)

        self.reset()
        #self.mode_combo.connect("item-selected", self.mode_combo_selected)
        self.band_combo.connect("item-selected", self.band_combo_selected)
        self.mtu_spin.connect("value-changed", self.spin_value_changed, "mtu")
        self.mtu_spin.value_entry.connect("changed", self.spin_user_set)
        self.channel_spin.connect("value-changed", self.spin_value_changed,
                                  "channel")
        self.ssid_entry.entry.connect("changed", self.entry_changed, "ssid")
        self.bssid_entry.connect("changed", self.entry_changed, "bssid")
        self.mac_entry.connect("changed", self.entry_changed, "mac_address")
        self.clone_entry.connect("changed", self.entry_changed,
                                 "cloned_mac_address")

    def use_default_setting(self):
        log.debug()
        self.bssid_entry.set_address("")
        self.mac_entry.set_address("")
        self.clone_entry.set_address("")
        self.mtu_spin.set_value(0)

    def use_user_setting(self):
        pass

    def spin_user_set(self, widget, value):
        if value == "":
            return
        value = int(value)
        if self.mtu_spin.lower_value <= value <= self.mtu_spin.upper_value:
            self.mtu_spin.update_and_emit(value)
        elif value < self.mtu_spin.lower_value:
            self.mtu_spin.update_and_emit(self.mtu_spin.lower_value)
        else:
            self.mtu_spin.update_and_emit(self.mtu_spin.upper_value)

    def spin_value_changed(self, widget, value, types):
        setattr(self.wireless, types, value)
        is_valid = self.connection.check_setting_finish()
        self.settings_obj.set_button("save", is_valid)

    def entry_changed(self, widget, content, types):
        is_valid = True
        if types == "ssid":
            setattr(self.wireless, types, content)
        else:
            from nmlib.nm_utils import TypeConvert
            if (content == "") or TypeConvert.is_valid_mac_address(content):
                setattr(self.wireless, types, content)
                #check_settings(self.connection, self.set_button)
                is_valid = self.connection.check_setting_finish()
            else:
                is_valid = False
                #Dispatcher.set_button("save", False)
        self.settings_obj.mac_is_valid = is_valid
        self.settings_obj.set_button("save", is_valid)

    def band_combo_selected(self, widget, content, value, index):
        self.wirless.band = value

    def mode_combo_selected(self, widget, content, value, index):
        self.wireless.mode = value
        self.wireless.adapt_wireless_commit()
        self.reset_table()

    def reset_table(self):
        container_remove_all(self.table)
        mode = self.mode_combo.get_current_item()[1]

        #self.table.attach(self.ssid_label_align, 0, 1, 0, 1)
        #self.table.attach(self.ssid_entry_align, 1, 2, 0, 1)
        # Mode
        self.table.attach(self.mode_label_align, 0, 1, 1, 2)
        self.table.attach(self.mode_combo_align, 1, 2, 1, 2)
        if mode == "adhoc":
            self.table.attach(self.band_label_align, 0, 1, 2, 3)
            self.table.attach(self.band_combo_align, 1, 2, 2, 3)
            self.table.attach(self.channel_label_align, 0, 1, 3, 4)
            self.table.attach(self.channel_spin_align, 1, 2, 3, 4)

        # Bssid
        self.table.attach(self.bssid_label_align, 0, 1, 4, 5)
        self.table.attach(self.bssid_entry_align, 1, 2, 4, 5)

        # MAC
        self.table.attach(self.mac_address_label_align, 0, 1, 5, 6)
        self.table.attach(self.mac_entry_align, 1, 2, 5, 6)
        # MAC_CLONE
        self.table.attach(self.clone_addr_label_align, 0, 1, 6, 7)
        self.table.attach(self.clone_entry_align, 1, 2, 6, 7)
        # MTU
        self.table.attach(self.mtu_spin_align, 1, 2, 7, 8)
        self.table.attach(self.mtu_label_align, 0, 1, 7, 8)

    def reset(self):
        wireless = self.wireless
        ## retrieve wireless info
        setting_list = ['bssid', 'mac_address', 'cloned_mac_address', 'mtu']
        if wireless.ssid != None:
            self.ssid_entry.set_text(wireless.ssid)

        if wireless.bssid != None:
            self.bssid_entry.set_address(wireless.bssid)

        if wireless.mode == 'infrastructure':
            #self.mode_combo.set_select_index(0)
            self.mode_combo.set_select_index(0)
        else:
            #self.mode_combo.set_select_index(1)
            self.mode_combo.set_select_index(1)

        if wireless.mac_address != None:
            self.mac_entry.set_address(wireless.mac_address)

        if wireless.cloned_mac_address != None:
            self.clone_entry.set_address(wireless.cloned_mac_address)

        if wireless.mtu != None:
            self.mtu_spin.set_value(int(wireless.mtu))

        if any(map(lambda i: getattr(wireless, i), setting_list)):
            self.section.set_active(False)

        self.reset_table()

    def save_change(self):

        self.wireless.ssid = self.ssid_entry.get_text()
        self.wireless.mode = self.mode_combo.get_current_item()[0]

        if self.bssid_entry.get_address() != "":
            self.wireless.bssid = self.bssid_entry.get_address()
        if self.mac_entry.get_address() != "":
            self.wireless.mac_address = self.mac_entry.get_address()
        if self.clone_entry.get_address() != "":
            self.wireless.cloned_mac_address = self.clone_entry.get_address()

        self.wireless.mtu = self.mtu_spin.get_value()
        self.wireless.adapt_wireless_commit()
コード例 #11
0
    def __init__(self, connection, set_button_cb, settings_obj=None):
        gtk.VBox.__init__(self)
        self.tab_name = _("Wireless")
        self.connection = connection
        self.set_button = set_button_cb
        # 新增settings_obj变量,用于访问shared_methods.Settings对象
        self.settings_obj = settings_obj

        self.wireless = self.connection.get_setting("802-11-wireless")
        ### UI
        self.ssid_label = Label(_("SSID:"),
                                enable_select=False,
                                enable_double_click=False)
        self.ssid_entry = InputEntry()
        self.ssid_entry.set_size(self.ENTRY_WIDTH, 22)

        self.mode_label = Label(_("Mode:"),
                                enable_select=False,
                                enable_double_click=False)
        self.mode_combo = ComboBox([(_("Infrastructure"), "infrastructure"),
                                    (_("Ad-hoc"), "adhoc")],
                                   fixed_width=130)

        # TODO need to put this section to personal wifi
        self.band_label = Label(_("Band:"),
                                enable_select=False,
                                enable_double_click=False)

        self.band_combo = ComboBox([(_("Automatic"), None), ("a (5 GHZ)", "a"),
                                    ("b/g (2.4)", "bg")],
                                   fixed_width=self.ENTRY_WIDTH)
        self.channel_label = Label(_("Channel:"),
                                   enable_select=False,
                                   enable_double_click=False)
        self.channel_spin = SpinBox(0, 0, 1500, 1, self.ENTRY_WIDTH)
        # BSSID
        self.bssid_label = Label(_("BSSID:"),
                                 enable_select=False,
                                 enable_double_click=False)
        self.bssid_entry = MACEntry()
        self.mac_address_label = Label(_("Device Mac Address:"),
                                       enable_select=False,
                                       enable_double_click=False)
        self.mac_entry = MACEntry()
        self.clone_addr_label = Label(_("Cloned Mac Address:"),
                                      enable_select=False,
                                      enable_double_click=False)
        self.clone_entry = MACEntry()

        self.mtu_label = Label(_("MTU:"),
                               enable_select=False,
                               enable_double_click=False)
        self.mtu_spin = SpinBox(0, 0, 1500, 1, 130)

        self.table = gtk.Table(8, 2, False)
        """
        wrap with alignment
        """
        widget_list = [
            "ssid_label", "ssid_entry", "mode_label", "mode_combo",
            "band_label", "band_combo", "channel_label", "channel_spin",
            "bssid_label", "bssid_entry", "mac_address_label", "mac_entry",
            "clone_addr_label", "clone_entry", "mtu_label", "mtu_spin"
        ]

        for widget in widget_list:
            item = getattr(self, widget)
            if widget.endswith("label"):
                item.set_can_focus(False)
                align = style.wrap_with_align(item, width=210)
            else:
                align = style.wrap_with_align(item, align="left")
            setattr(self, widget + "_align", align)

        #TODO UI change
        style.draw_background_color(self)
        #align = style.set_box_with_align(self.table, 'text')
        style.set_table(self.table)

        self.section = SettingSection(_("Default Settings"),
                                      always_show=False,
                                      revert=True,
                                      label_right=True,
                                      has_seperator=False)
        self.pack_start(self.section, False, False)
        self.section.toggle_off = self.use_default_setting
        self.section.toggle_on = self.use_user_setting
        self.section.load([self.table])
        #self.pack_start(self.table, False, False)
        #self.table.set_size_request(340, 227)

        #self.ssid_entry.set_size_request(130, 22)
        self.bssid_entry.set_size_request(130, 22)
        self.mac_entry.set_size_request(130, 22)
        self.clone_entry.set_size_request(130, 22)

        self.reset()
        #self.mode_combo.connect("item-selected", self.mode_combo_selected)
        self.band_combo.connect("item-selected", self.band_combo_selected)
        self.mtu_spin.connect("value-changed", self.spin_value_changed, "mtu")
        self.mtu_spin.value_entry.connect("changed", self.spin_user_set)
        self.channel_spin.connect("value-changed", self.spin_value_changed,
                                  "channel")
        self.ssid_entry.entry.connect("changed", self.entry_changed, "ssid")
        self.bssid_entry.connect("changed", self.entry_changed, "bssid")
        self.mac_entry.connect("changed", self.entry_changed, "mac_address")
        self.clone_entry.connect("changed", self.entry_changed,
                                 "cloned_mac_address")
コード例 #12
0
class Wired(gtk.VBox):
    ENTRY_WIDTH = 222
    LEFT_PADDING = 210
    def __init__(self, connection, set_button, settings_obj=None):
        gtk.VBox.__init__(self)
        self.tab_name = _("Wired")
        self.set_button = set_button
        # 新增settings_obj变量,用于访问shared_methods.Settings对象
        self.settings_obj = settings_obj
        self.connection = connection
        
        self.ethernet_setting = connection.get_setting("802-3-ethernet")

        table = gtk.Table(3, 2, False)
        
        mac_address = Label(_("Device Mac Address:"),
                            text_size=CONTENT_FONT_SIZE,
                            enable_select=False,
                            enable_double_click=False)
        mac_address.set_can_focus(False)

        self.mac_entry = MACEntry()

        clone_addr = Label(_("Cloned Mac Address:"),
                           text_size=CONTENT_FONT_SIZE,
                           enable_select=False,
                           enable_double_click=False)
        clone_addr.set_can_focus(False)
        self.clone_entry = MACEntry()

        mtu = Label("MTU:", 
                    text_size=CONTENT_FONT_SIZE,
                    enable_select=False,
                    enable_double_click=False)
        mtu.set_can_focus(False)
        self.mtu_spin = SpinBox(0,0, 1500, 1, 130)
        
        '''
        Park table
        '''
        table.attach(style.wrap_with_align(mac_address, width=self.LEFT_PADDING), 0, 1, 0, 1)
        table.attach(style.wrap_with_align(self.mac_entry), 1, 2, 0, 1)
        table.attach(style.wrap_with_align(clone_addr, width=self.LEFT_PADDING), 0, 1, 1, 2)
        table.attach(style.wrap_with_align(self.clone_entry), 1,2, 1, 2)
        table.attach(style.wrap_with_align(mtu, width=self.LEFT_PADDING), 0,1,2,3)
        table.attach(style.wrap_with_align(self.mtu_spin), 1,2,2,3)

        # TODO UI change
        style.draw_background_color(self)
        #align = style.set_box_with_align(table, "text")
        #self.add(align)
        style.set_table(table)
        table_align = gtk.Alignment(0, 0, 0, 0)
        default_button = DefaultToggle(_("Default Setting"))
        default_button.toggle_off = self.use_default_setting
        default_button.toggle_on = self.use_user_setting
        default_button.load([table])
        table_align.add(default_button)
        self.pack_start(table_align, False, False)

        self.mac_entry.set_size_request(130, 22)
        self.clone_entry.set_size_request(130, 22)
        ## retrieve wired info
        self._init = True
        self.mac_entry.connect("changed", self.save_settings, "mac_address")
        self.clone_entry.connect("changed", self.save_settings, "cloned_mac_address")
        self.mtu_spin.connect("value_changed", self.save_settings, "mtu")
        self.mtu_spin.value_entry.connect("changed", self.spin_user_set)

        setting_list = (mac, clone_mac, mtu) = self.ethernet_setting.mac_address, self.ethernet_setting.cloned_mac_address, self.ethernet_setting.mtu
        #print mac, clone_mac, mtu
        if mac != None:
            self.mac_entry.set_address(mac)
        if clone_mac !=None:
            self.clone_entry.set_address(clone_mac)
        if mtu != None:
            self.mtu_spin.set_value(int(mtu))
        
        if any(setting_list):
            default_button.set_active(False)
        self._init = False

    def save_settings(self, widget, value, types):
        if type(value) is str:
            if (value == "") or TypeConvert.is_valid_mac_address(value):
                setattr(self.ethernet_setting, types, value)
                #if self.connection.check_setting_finish():
                    #Dispatcher.set_button("save", True)
                is_valid = self.connection.check_setting_finish()
            else:
                is_valid = False
                #Dispatcher.set_button("save", False)
            self.settings_obj.mac_is_valid = is_valid
            if not self._init:
                self.settings_obj.set_button("save", is_valid)
        else:
            setattr(self.ethernet_setting, types, value)
            if self.connection.check_setting_finish() and not self._init:
                Dispatcher.set_button("save", True)

    def spin_user_set(self, widget, value):
        if value == "":
            return
        value = int(value)
        if self.mtu_spin.lower_value <= value <= self.mtu_spin.upper_value:
            self.mtu_spin.update_and_emit(value)
        elif value < self.mtu_spin.lower_value:
            self.mtu_spin.update_and_emit(self.mtu_spin.lower_value)
        else:
            self.mtu_spin.update_and_emit(self.mtu_spin.upper_value)

    def use_default_setting(self):
        self.mac_entry.set_address("")
        self.clone_entry.set_address("")
        self.mtu_spin.set_value(0)

    def use_user_setting(self):
        pass
コード例 #13
0
    def __init__(self,
                 connection,
                 set_button_cb,
                 need_ssid=False,
                 settings_obj=None):
        gtk.VBox.__init__(self)
        self.tab_name = _("Security")
        self.connection = connection
        self.set_button = set_button_cb
        # 新增settings_obj变量,用于访问shared_methods.Settings对象
        self.settings_obj = settings_obj
        self.settings_obj.initial_lock = True

        self.need_ssid = need_ssid
        self.presave_index = None

        if self.need_ssid:
            log.info("enter hidden network settings")
            self.add_ssid_entry()

        if self.connection.get_setting(
                "802-11-wireless").security == "802-11-wireless-security":
            self.has_security = True
            self.setting = self.connection.get_setting(
                "802-11-wireless-security")
        else:
            self.has_security = False
        self.security_label = Label(_("Security:"),
                                    enable_select=False,
                                    enable_double_click=False)
        self.key_label = Label(_("Key:"),
                               enable_select=False,
                               enable_double_click=False)
        self.wep_index_label = Label(_("Wep index:"),
                                     enable_select=False,
                                     enable_double_click=False)

        self.auth_label = Label(_("Authentication:"),
                                enable_select=False,
                                enable_double_click=False)
        self.password_label = Label(_("Password:"******"None"), None),
                           (_("WEP (Hex or ASCII)"), "none"),
                           (_("WEP 104/128-bit Passphrase"), "none"),
                           (_("WPA WPA2 Personal"), "wpa-psk")]
        #entry_item = map(lambda l: (l[1],l[0]), enumerate(self.encry_list))
        self.security_combo = ComboBox(self.encry_list,
                                       fixed_width=self.ENTRY_WIDTH)
        #self.security_combo.set_size_request(self.ENTRY_WIDTH, 22)

        self.key_entry = PasswordEntry()
        self.password_entry = PasswordEntry()
        self.show_key_check = CheckButton(_("Show password"), padding_x=0)
        self.show_key_check.connect("toggled", self.show_key_check_button_cb)
        self.wep_index_spin = SpinBox(0, 1, 4, 1, self.ENTRY_WIDTH)
        self.auth_combo = ComboBox([(_("Shared Key"), "shared"),
                                    (_("Open System"), "open")],
                                   fixed_width=self.ENTRY_WIDTH)

        ## advance button
        self.align = gtk.Alignment(0, 1.0, 0, 0)
        self.align.set_padding(0, 0, 376, 0)
        self.align.set_size_request(-1, 30)
        self.button = Button(_("Advanced"))
        self.align.add(self.button)

        ## Create table
        self.table = gtk.Table(5, 4)
        #TODO UI change
        label_list = [
            "security_label", "key_label", "wep_index_label", "auth_label",
            "password_label"
        ]
        widget_list = [
            "password_entry", "key_entry", "wep_index_spin", "auth_combo",
            "security_combo"
        ]
        for label in label_list:
            l = getattr(self, label)
            l.set_can_focus(False)
            align = style.wrap_with_align(l, width=210)
            setattr(self, label + "_align", align)

        for w in widget_list:
            l = getattr(self, w)
            align = style.wrap_with_align(l, align="left")
            setattr(self, w + "_align", align)

        self.show_key_check_align = style.wrap_with_align(self.show_key_check,
                                                          align="left")

        self.reset(self.has_security)
        self.security_combo.connect("item-selected", self.change_encry_type)
        self.key_entry.entry.connect("changed", self.save_wep_pwd)
        self.password_entry.entry.connect("changed", self.save_wpa_pwd)
        self.wep_index_spin.connect("value-changed", self.wep_index_spin_cb)
        self.auth_combo.connect("item-selected", self.save_auth_cb)

        style.set_table(self.table)
        table_align = gtk.Alignment(0, 0, 0, 0)
        table_align.add(self.table)
        style.draw_background_color(self)
        width, height = self.ENTRY_WIDTH, 22
        self.key_entry.set_size(width, height)
        self.password_entry.set_size(width, height)
        self.wep_index_spin.set_size_request(width, height)
        self.auth_combo.set_size_request(width, height)
        self.security_combo.set_size_request(width, height)
        self.pack_start(table_align, False, False)
        self.pack_start(self.align, False, False, 0)
        self.settings_obj.initial_lock = False
コード例 #14
0
    def __init__(self, connection, set_button, settings_obj=None):
        gtk.VBox.__init__(self)
        self.tab_name = _("Wired")
        self.set_button = set_button
        # 新增settings_obj变量,用于访问shared_methods.Settings对象
        self.settings_obj = settings_obj
        self.connection = connection
        
        self.ethernet_setting = connection.get_setting("802-3-ethernet")

        table = gtk.Table(3, 2, False)
        
        mac_address = Label(_("Device Mac Address:"),
                            text_size=CONTENT_FONT_SIZE,
                            enable_select=False,
                            enable_double_click=False)
        mac_address.set_can_focus(False)

        self.mac_entry = MACEntry()

        clone_addr = Label(_("Cloned Mac Address:"),
                           text_size=CONTENT_FONT_SIZE,
                           enable_select=False,
                           enable_double_click=False)
        clone_addr.set_can_focus(False)
        self.clone_entry = MACEntry()

        mtu = Label("MTU:", 
                    text_size=CONTENT_FONT_SIZE,
                    enable_select=False,
                    enable_double_click=False)
        mtu.set_can_focus(False)
        self.mtu_spin = SpinBox(0,0, 1500, 1, 130)
        
        '''
        Park table
        '''
        table.attach(style.wrap_with_align(mac_address, width=self.LEFT_PADDING), 0, 1, 0, 1)
        table.attach(style.wrap_with_align(self.mac_entry), 1, 2, 0, 1)
        table.attach(style.wrap_with_align(clone_addr, width=self.LEFT_PADDING), 0, 1, 1, 2)
        table.attach(style.wrap_with_align(self.clone_entry), 1,2, 1, 2)
        table.attach(style.wrap_with_align(mtu, width=self.LEFT_PADDING), 0,1,2,3)
        table.attach(style.wrap_with_align(self.mtu_spin), 1,2,2,3)

        # TODO UI change
        style.draw_background_color(self)
        #align = style.set_box_with_align(table, "text")
        #self.add(align)
        style.set_table(table)
        table_align = gtk.Alignment(0, 0, 0, 0)
        default_button = DefaultToggle(_("Default Setting"))
        default_button.toggle_off = self.use_default_setting
        default_button.toggle_on = self.use_user_setting
        default_button.load([table])
        table_align.add(default_button)
        self.pack_start(table_align, False, False)

        self.mac_entry.set_size_request(130, 22)
        self.clone_entry.set_size_request(130, 22)
        ## retrieve wired info
        self._init = True
        self.mac_entry.connect("changed", self.save_settings, "mac_address")
        self.clone_entry.connect("changed", self.save_settings, "cloned_mac_address")
        self.mtu_spin.connect("value_changed", self.save_settings, "mtu")
        self.mtu_spin.value_entry.connect("changed", self.spin_user_set)

        setting_list = (mac, clone_mac, mtu) = self.ethernet_setting.mac_address, self.ethernet_setting.cloned_mac_address, self.ethernet_setting.mtu
        #print mac, clone_mac, mtu
        if mac != None:
            self.mac_entry.set_address(mac)
        if clone_mac !=None:
            self.clone_entry.set_address(clone_mac)
        if mtu != None:
            self.mtu_spin.set_value(int(mtu))
        
        if any(setting_list):
            default_button.set_active(False)
        self._init = False
コード例 #15
0
class Colorbar(object):
    ''' Colorbar window '''
    def __init__(self, parent=None, screenshot=None):
        '''
        init colorbar
        @param parent: the transient parent for this window
        @param screenshot: a Screenshot object
        '''
        self.screenshot = screenshot
        self.win = self.screenshot.window
        
        self.height = 36
        self.width = 279
        
        self.window = Window(window_type=gtk.WINDOW_POPUP, shadow_visible=False)
        self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG)
        self.window.set_keep_above(True)
        self.window.set_transient_for(parent)
        self.window.set_decorated(False)

        #vbox = gtk.VBox(False, 0)
        self.box = gtk.HBox(False, 5)
        self.size_box = gtk.HBox(False, 5)
        self.dynamic_box = gtk.HBox()
        
        colorbox_align = gtk.Alignment()
        #colorbox_align.set(0.5, 0.5, 0, 0)
        colorbox_align.set(0, 0.5, 1, 0)
        colorbox_align.set_padding(2, 2, 11, 11)
        colorbox_align.add(self.box)
        self.window.window_frame.pack_start(colorbox_align, True, True)
        self.window.set_size_request(self.width, self.height)
        #self.window.set_size_request(-1, self.height)

        self.__size_button_dict = {}
        self.create_size_button("small", ACTION_SIZE_SMALL)
        self.create_size_button("normal", ACTION_SIZE_NORMAL)
        self.create_size_button("big", ACTION_SIZE_BIG)
        self.create_size_button("ellipse_fill", ACTION_SIZE_RECTANGLE_ELLIPSE_FILL)
        self.create_size_button("rect_fill", ACTION_SIZE_RECTANGLE_ELLIPSE_FILL)
        self._set_size_button_state("small", True)

        self.size_align = gtk.Alignment()
        #self.size_align.set(0.5,0.5,0,0)
        self.size_align.set(0, 0.5, 1, 0)
        self.size_align.add(self.size_box)
        #self.dynamic_box.pack_start(self.size_align)
        self.box.pack_start(self.dynamic_box)
        
        # font select
        self.font_box = gtk.HBox(False, 5)
        font_img = gtk.image_new_from_pixbuf(app_theme.get_pixbuf("action/text_normal.png").get_pixbuf())
        self.font_spin = SpinBox(self.screenshot.font_size, 8, 72, 1)
        self.font_spin.connect("value-changed", self._font_size_changed)
        self.font_spin.value_entry.set_can_focus(False)
        self.font_box.pack_start(font_img)
        self.font_box.pack_start(self.font_spin)
        self.font_align = gtk.Alignment()
        self.font_align.set(0.5,0.5,0,0)
        self.font_align.add(self.font_box)

        # color select
        #self.color_select = gtk.EventBox()
        self.color_select = gtk.Image()
        pix = app_theme.get_pixbuf("color_big/red.png").get_pixbuf()
        self.color_select.set_from_pixbuf(pix)

        self.box.pack_start(self.color_select, False, False)
        
        # color button
        self.vbox = gtk.VBox(False, 2)
        self.above_hbox = gtk.HBox(False, 2)
        self.below_hbox = gtk.HBox(False, 2)
        self.color_map = {
            'black'       : "#000000",  # 1-1
            'gray_dark'   : "#808080",  # 1-2
            'red'         : "#FF0000",  # 1-3
            'yellow_dark' : "#FF9B00",  # 1-4
            'yellow'      : "#FFFF00",  # 1-5
            'green'       : "#B2E700",  # 1-6
            'green_dark'  : "#008000",  # 1-7
            'wathet_dark' : "#008080",  # 1-8
            'white'       : "#FFFFFF",  # 2-1
            'gray'        : "#C0C0C0",  # 2-2
            'red_dark'    : "#E2004E",  # 2-3
            'pink'        : "#E2007A",  # 2-4
            'pink_dark'   : "#800080",  # 2-5
            'blue_dark'   : "#000080",  # 2-6
            'blue'        : "#0085E1",  # 2-7
            'wathet'      : "#009DE0"}  # 2-8

        self.create_color_button(self.above_hbox, "black")
        self.create_color_button(self.above_hbox, "gray_dark")
        self.create_color_button(self.above_hbox, "red")
        self.create_color_button(self.above_hbox, "yellow_dark")
        self.create_color_button(self.above_hbox, "yellow")
        self.create_color_button(self.above_hbox, "green")
        self.create_color_button(self.above_hbox, "green_dark")
        self.create_color_button(self.above_hbox, "wathet_dark")

        self.create_color_button(self.below_hbox, "white")
        self.create_color_button(self.below_hbox, "gray")
        self.create_color_button(self.below_hbox, "red_dark")
        self.create_color_button(self.below_hbox, "pink")
        self.create_color_button(self.below_hbox, "pink_dark")
        self.create_color_button(self.below_hbox, "blue_dark")
        self.create_color_button(self.below_hbox, "blue")
        self.create_color_button(self.below_hbox, "wathet")

        self.vbox.pack_start(self.above_hbox)
        self.vbox.pack_start(self.below_hbox)
        self.box.pack_start(self.vbox)

    def create_color_button(self, box, name):
        '''
        create color button
        @param box: a gtk.HBox
        @param name: the button's name
        '''
        button = ImageButton(
            app_theme.get_pixbuf("color/" + name + ".png"),
            app_theme.get_pixbuf("color/" + name + "_hover.png"),
            app_theme.get_pixbuf("color/" + name + "_hover.png"))
        button.connect('pressed', lambda w:self._color_button_pressed(name))
        box.pack_start(button)

    def create_toggle_button(self, name):
        '''
        create a togglebutton
        @param name: the button's name
        @return: a dtk.ui.ToggleButton
        '''
        button = ToggleButton(
            app_theme.get_pixbuf("size/" + name + ".png"),
            app_theme.get_pixbuf("size/" + name + "_press.png"),
            app_theme.get_pixbuf("size/" + name + "_hover.png"),
            app_theme.get_pixbuf("size/" + name + "_press.png"))
        button.set_name(name)
        return button

    def create_size_button(self, name, index):
        '''
        create size button
        @param name: the button's name
        @param index: the button's index in button list
        @return: a dtk.ui.ToggleButton
        '''
        button = self.create_toggle_button(name)
        button.connect("pressed", self._size_button_pressed, index)
        #button.connect("toggled", self._size_button_toggled, name)
        button.connect("released", self._size_button_released)
        self.size_box.pack_start(button)
        self.__size_button_dict[name] = button
        return button

    def _font_size_changed(self, widget, value):
        '''font size changed, SpinBox changed callback'''
        self.screenshot.font_size = value
        if self.screenshot.show_text_window_flag:
            if not self.screenshot.text_window.set_font_size(value):
                #print value, self.screenshot.text_window.get_font_size()
                widget.set_value(self.screenshot.text_window.get_font_size())
            self.win.refresh()

    def _color_button_pressed(self, name):
        ''' color button pressed callback'''
        pix = app_theme.get_pixbuf("color_big/" + name + ".png").get_pixbuf()
        self.color_select.set_from_pixbuf(pix)
        if self.screenshot is None:
            return
        self.screenshot.action_color = self.color_map[name]
        if self.screenshot.show_text_window_flag:
            self.screenshot.text_window.set_text_color(self.screenshot.action_color)
            self.win.refresh()

    def _size_button_pressed(self, widget, index):
        ''' size button pressed callback'''
        if self.screenshot is None:
            return
        self.screenshot.action_size = index
        for each in self.__size_button_dict:
            if self.__size_button_dict[each] == widget:
                continue
            else:
                self.__size_button_dict[each].set_active(False)

    def _size_button_released(self, widget):
        ''' size button release callback'''
        if not widget.get_active():
            widget.set_active(True)

    def _set_size_button_state(self, name, state):
        '''
        set size button state
        @param name: the button's name which will set
        @param state: the state to set, True or False
        '''
        for each in self.__size_button_dict.keys():
            if each == name:
                self.__size_button_dict[name].set_active(state)
        
    def show(self):
        ''' show the colorbar'''
        # action is text, show font size set
        if self.screenshot.action == ACTION_TEXT:
            self.window.set_size_request(self.width, self.height)
            self.window.resize(self.width, self.height)
            if self.size_align in self.dynamic_box.get_children():
                self.dynamic_box.remove(self.size_align)
            if self.font_align not in self.dynamic_box.get_children():
                self.dynamic_box.add(self.font_align)
            self.dynamic_box.show_all()
        # show draw size
        else:
            if self.font_align in self.dynamic_box.get_children():
                self.dynamic_box.remove(self.font_align)
            if self.size_align not in self.dynamic_box.get_children():
                self.dynamic_box.add(self.size_align)
            self.dynamic_box.show_all()
            # actin is rectangle or ellispe, show fill button
            # show rect fill button
            if self.screenshot.action == ACTION_RECTANGLE:
                self.window.set_size_request(self.width, self.height)
                self.window.resize(self.width, self.height)
                if self.__size_button_dict['rect_fill'] not in self.size_box.get_children():
                    self.size_box.pack_start(self.__size_button_dict['rect_fill'])
                if self.__size_button_dict['ellipse_fill'] in self.size_box.get_children():
                    self.size_box.remove(self.__size_button_dict['ellipse_fill'])
                if self.__size_button_dict['ellipse_fill'].get_active():
                    self.__size_button_dict['rect_fill'].pressed()
                    self.__size_button_dict['rect_fill'].released()
            
            # show ellipse fill button
            elif self.screenshot.action == ACTION_ELLIPSE:
                self.window.set_size_request(self.width, self.height)
                self.window.resize(self.width, self.height)
                if self.__size_button_dict['ellipse_fill'] not in self.size_box.get_children():
                    self.size_box.pack_start(self.__size_button_dict['ellipse_fill'])
                if self.__size_button_dict['rect_fill'] in self.size_box.get_children():
                    self.size_box.remove(self.__size_button_dict['rect_fill'])
                if self.__size_button_dict['rect_fill'].get_active():
                    self.__size_button_dict['ellipse_fill'].pressed()
                    self.__size_button_dict['ellipse_fill'].released()

            # don't show fill button
            else:
                self.window.set_size_request(self.width, self.height)
                self.window.resize(self.width, self.height)
                if self.__size_button_dict['rect_fill'] in self.size_box.get_children():
                    if self.__size_button_dict['rect_fill'].get_active():
                        self.__size_button_dict['small'].pressed()
                        self.__size_button_dict['small'].released()
                    self.size_box.remove(self.__size_button_dict['rect_fill'])
                if self.__size_button_dict['ellipse_fill'] in self.size_box.get_children():
                    if self.__size_button_dict['ellipse_fill'].get_active():
                        self.__size_button_dict['small'].pressed()
                        self.__size_button_dict['small'].released()
                    self.size_box.remove(self.__size_button_dict['ellipse_fill'])
            self.size_box.show_all()
        if not self.window.get_visible():
            self.window.show_window()
        #print "colorbox:", self.box.allocation, self.window.allocation

    def hide(self):
        '''hide the toolbar'''
        if self.window.get_visible():
            self.window.hide_all()
コード例 #16
0
class Wireless(gtk.VBox):
    ENTRY_WIDTH = 222

    def __init__(self, connection, set_button_cb, settings_obj=None):
        gtk.VBox.__init__(self)
        self.tab_name = _("Wireless")
        self.connection = connection 
        self.set_button = set_button_cb
        # 新增settings_obj变量,用于访问shared_methods.Settings对象
        self.settings_obj = settings_obj

        self.wireless = self.connection.get_setting("802-11-wireless")
        ### UI
        self.ssid_label = Label(_("SSID:"),
                                enable_select=False,
                                enable_double_click=False)
        self.ssid_entry = InputEntry()
        self.ssid_entry.set_size(self.ENTRY_WIDTH, 22)

        self.mode_label = Label(_("Mode:"),
                               enable_select=False,
                               enable_double_click=False)
        self.mode_combo = ComboBox([(_("Infrastructure"),"infrastructure"),(_("Ad-hoc"), "adhoc")], fixed_width=130)
        
        # TODO need to put this section to personal wifi
        self.band_label = Label(_("Band:"),
                               enable_select=False,
                               enable_double_click=False)
                                
        self.band_combo = ComboBox([(_("Automatic"), None),
                                    ("a (5 GHZ)", "a"),
                                    ("b/g (2.4)", "bg")],
                                    fixed_width=self.ENTRY_WIDTH)
        self.channel_label = Label(_("Channel:"),
                                   enable_select=False,
                                   enable_double_click=False)
        self.channel_spin = SpinBox(0, 0, 1500, 1, self.ENTRY_WIDTH)
        # BSSID
        self.bssid_label = Label(_("BSSID:"),
                                 enable_select=False,
                                 enable_double_click=False)
        self.bssid_entry = MACEntry()
        self.mac_address_label = Label(_("Device Mac Address:"),
                                 enable_select=False,
                                 enable_double_click=False)
        self.mac_entry = MACEntry()
        self.clone_addr_label = Label(_("Cloned Mac Address:"),
                                 enable_select=False,
                                 enable_double_click=False)
        self.clone_entry = MACEntry()

        self.mtu_label = Label(_("MTU:"),
                           enable_select=False,
                           enable_double_click=False)
        self.mtu_spin = SpinBox(0, 0, 1500, 1, 130)

        self.table = gtk.Table(8, 2, False)

        """
        wrap with alignment
        """
        widget_list = ["ssid_label", "ssid_entry", "mode_label", "mode_combo",
                       "band_label", "band_combo", "channel_label", "channel_spin",
                       "bssid_label", "bssid_entry", "mac_address_label", "mac_entry",
                       "clone_addr_label", "clone_entry", "mtu_label", "mtu_spin"]

        for widget in widget_list:
            item = getattr(self, widget)
            if widget.endswith("label"):
                item.set_can_focus(False)
                align = style.wrap_with_align(item, width=210)
            else:
                align = style.wrap_with_align(item, align="left")
            setattr(self, widget + "_align", align)

        #TODO UI change
        style.draw_background_color(self)
        #align = style.set_box_with_align(self.table, 'text')
        style.set_table(self.table)

        self.section = SettingSection(_("Default Settings"), always_show= False, revert=True, label_right=True, has_seperator=False)
        self.pack_start(self.section, False, False)
        self.section.toggle_off = self.use_default_setting
        self.section.toggle_on = self.use_user_setting
        self.section.load([self.table])
        #self.pack_start(self.table, False, False)
        #self.table.set_size_request(340, 227)

        #self.ssid_entry.set_size_request(130, 22)
        self.bssid_entry.set_size_request(130, 22)
        self.mac_entry.set_size_request(130, 22)
        self.clone_entry.set_size_request(130, 22)

        self.reset()
        #self.mode_combo.connect("item-selected", self.mode_combo_selected)
        self.band_combo.connect("item-selected", self.band_combo_selected)
        self.mtu_spin.connect("value-changed", self.spin_value_changed, "mtu")
        self.mtu_spin.value_entry.connect("changed", self.spin_user_set)
        self.channel_spin.connect("value-changed", self.spin_value_changed, "channel")
        self.ssid_entry.entry.connect("changed", self.entry_changed, "ssid")
        self.bssid_entry.connect("changed", self.entry_changed, "bssid")
        self.mac_entry.connect("changed", self.entry_changed, "mac_address")
        self.clone_entry.connect("changed", self.entry_changed, "cloned_mac_address")

    def use_default_setting(self):
        log.debug()
        self.bssid_entry.set_address("")
        self.mac_entry.set_address("")
        self.clone_entry.set_address("")
        self.mtu_spin.set_value(0)

    def use_user_setting(self):
        pass

    def spin_user_set(self, widget, value):
        if value == "":
            return
        value = int(value)
        if self.mtu_spin.lower_value <= value <= self.mtu_spin.upper_value:
            self.mtu_spin.update_and_emit(value)
        elif value < self.mtu_spin.lower_value:
            self.mtu_spin.update_and_emit(self.mtu_spin.lower_value)
        else:
            self.mtu_spin.update_and_emit(self.mtu_spin.upper_value)
            

    def spin_value_changed(self, widget, value, types):
        setattr(self.wireless, types, value)
        is_valid = self.connection.check_setting_finish()
        self.settings_obj.set_button("save", is_valid)

    def entry_changed(self, widget, content, types):
        is_valid = True
        if types == "ssid":
            setattr(self.wireless, types, content)
        else:
            from nmlib.nm_utils import TypeConvert
            if (content == "") or TypeConvert.is_valid_mac_address(content):
                setattr(self.wireless, types, content)
                #check_settings(self.connection, self.set_button)
                is_valid = self.connection.check_setting_finish()
            else:
                is_valid = False
                #Dispatcher.set_button("save", False)
        self.settings_obj.mac_is_valid = is_valid
        self.settings_obj.set_button("save", is_valid)

    def band_combo_selected(self, widget, content, value, index):
        self.wirless.band = value

    def mode_combo_selected(self, widget, content, value, index):
        self.wireless.mode = value
        self.wireless.adapt_wireless_commit()
        self.reset_table()

    def reset_table(self):
        container_remove_all(self.table)
        mode = self.mode_combo.get_current_item()[1]

        #self.table.attach(self.ssid_label_align, 0, 1, 0, 1)
        #self.table.attach(self.ssid_entry_align, 1, 2, 0, 1)
        # Mode
        self.table.attach(self.mode_label_align, 0, 1, 1, 2)
        self.table.attach(self.mode_combo_align, 1, 2, 1, 2)
        if mode == "adhoc":
            self.table.attach(self.band_label_align, 0, 1, 2, 3)
            self.table.attach(self.band_combo_align, 1, 2, 2, 3)
            self.table.attach(self.channel_label_align, 0, 1, 3, 4)
            self.table.attach(self.channel_spin_align, 1, 2, 3, 4)

        # Bssid
        self.table.attach(self.bssid_label_align, 0, 1, 4, 5)
        self.table.attach(self.bssid_entry_align, 1, 2, 4, 5)

        # MAC
        self.table.attach(self.mac_address_label_align, 0, 1, 5, 6)
        self.table.attach(self.mac_entry_align, 1, 2, 5, 6)
        # MAC_CLONE
        self.table.attach(self.clone_addr_label_align, 0, 1, 6, 7)
        self.table.attach(self.clone_entry_align, 1,2, 6, 7)
        # MTU
        self.table.attach(self.mtu_spin_align, 1, 2, 7, 8)
        self.table.attach(self.mtu_label_align, 0, 1, 7, 8)

    def reset(self):
        wireless = self.wireless
        ## retrieve wireless info
        setting_list = ['bssid','mac_address', 'cloned_mac_address', 'mtu']
        if wireless.ssid != None:
            self.ssid_entry.set_text(wireless.ssid)

        if wireless.bssid != None:
            self.bssid_entry.set_address(wireless.bssid)

        if wireless.mode == 'infrastructure':
            #self.mode_combo.set_select_index(0)
            self.mode_combo.set_select_index(0)
        else:
            #self.mode_combo.set_select_index(1)
            self.mode_combo.set_select_index(1)

        if wireless.mac_address != None:
            self.mac_entry.set_address(wireless.mac_address)

        if wireless.cloned_mac_address !=None:
            self.clone_entry.set_address(wireless.cloned_mac_address)

        if wireless.mtu != None:
            self.mtu_spin.set_value(int(wireless.mtu))

        if any(map(lambda i: getattr(wireless, i), setting_list)):
            self.section.set_active(False)
        
        self.reset_table()
    
    def save_change(self):
        
        self.wireless.ssid = self.ssid_entry.get_text()
        self.wireless.mode = self.mode_combo.get_current_item()[0]

        if self.bssid_entry.get_address() != "":
            self.wireless.bssid = self.bssid_entry.get_address()
        if self.mac_entry.get_address() != "":
            self.wireless.mac_address = self.mac_entry.get_address()
        if self.clone_entry.get_address() != "":
            self.wireless.cloned_mac_address = self.clone_entry.get_address()

        self.wireless.mtu = self.mtu_spin.get_value()
        self.wireless.adapt_wireless_commit()
コード例 #17
0
    def __init__(self, connection, set_button_cb, need_ssid=False, settings_obj=None):
        gtk.VBox.__init__(self)
        self.tab_name = _("Security")
        self.connection = connection
        self.set_button = set_button_cb
        # 新增settings_obj变量,用于访问shared_methods.Settings对象
        self.settings_obj = settings_obj
        self.settings_obj.initial_lock = True

        self.need_ssid = need_ssid
        self.presave_index = None

        if self.need_ssid:
            log.info("enter hidden network settings")
            self.add_ssid_entry()
        
        if self.connection.get_setting("802-11-wireless").security == "802-11-wireless-security":
            self.has_security = True
            self.setting = self.connection.get_setting("802-11-wireless-security")
        else:
            self.has_security = False
        self.security_label = Label(_("Security:"),
                                    enable_select=False,
                                    enable_double_click=False)
        self.key_label = Label(_("Key:"),
                               enable_select=False,
                               enable_double_click=False)
        self.wep_index_label = Label(_("Wep index:"),
                                     enable_select=False,
                                     enable_double_click=False)

        self.auth_label = Label(_("Authentication:"),
                                enable_select=False,
                                enable_double_click=False)
        self.password_label = Label(_("Password:"******"None"), None),
                      (_("WEP (Hex or ASCII)"), "none"),
                      (_("WEP 104/128-bit Passphrase"), "none"),
                      (_("WPA WPA2 Personal"), "wpa-psk")]
        #entry_item = map(lambda l: (l[1],l[0]), enumerate(self.encry_list))
        self.security_combo = ComboBox(self.encry_list, fixed_width=self.ENTRY_WIDTH)
        #self.security_combo.set_size_request(self.ENTRY_WIDTH, 22)

        self.key_entry = PasswordEntry()
        self.password_entry = PasswordEntry()
        self.show_key_check = CheckButton(_("Show password"), padding_x=0)
        self.show_key_check.connect("toggled", self.show_key_check_button_cb)
        self.wep_index_spin = SpinBox(0, 1, 4, 1, self.ENTRY_WIDTH)
        self.auth_combo = ComboBox([
                                    (_("Shared Key"), "shared"),
                                    (_("Open System"), "open")],fixed_width=self.ENTRY_WIDTH)

        ## advance button
        self.align = gtk.Alignment(0, 1.0, 0, 0)
        self.align.set_padding(0, 0, 376, 0)
        self.align.set_size_request(-1 ,30)
        self.button = Button(_("Advanced"))
        self.align.add(self.button)

        ## Create table
        self.table = gtk.Table(5, 4)
        #TODO UI change
        label_list = ["security_label", "key_label", "wep_index_label", "auth_label", "password_label"]
        widget_list = ["password_entry", "key_entry", "wep_index_spin", "auth_combo", "security_combo"]
        for label in label_list:
            l = getattr(self, label)
            l.set_can_focus(False)
            align = style.wrap_with_align(l, width=210)
            setattr(self, label+"_align", align)

        for w in widget_list:
            l = getattr(self, w)
            align = style.wrap_with_align(l, align="left")
            setattr(self, w+"_align", align)

        self.show_key_check_align = style.wrap_with_align(self.show_key_check, align="left")

        self.reset(self.has_security)
        self.security_combo.connect("item-selected", self.change_encry_type)
        self.key_entry.entry.connect("changed", self.save_wep_pwd)
        self.password_entry.entry.connect("changed", self.save_wpa_pwd)
        self.wep_index_spin.connect("value-changed", self.wep_index_spin_cb)
        self.auth_combo.connect("item-selected", self.save_auth_cb)
        
        style.set_table(self.table)
        table_align = gtk.Alignment(0, 0, 0, 0)
        table_align.add(self.table)
        style.draw_background_color(self)
        width, height = self.ENTRY_WIDTH, 22
        self.key_entry.set_size(width, height)
        self.password_entry.set_size(width, height)
        self.wep_index_spin.set_size_request(width, height)
        self.auth_combo.set_size_request(width, height)
        self.security_combo.set_size_request(width, height)
        self.pack_start(table_align, False, False)
        self.pack_start(self.align, False, False, 0)
        self.settings_obj.initial_lock = False
コード例 #18
0
class Security(gtk.VBox):
    ENTRY_WIDTH = 222

    def __init__(self, connection, set_button_cb, need_ssid=False, settings_obj=None):
        gtk.VBox.__init__(self)
        self.tab_name = _("Security")
        self.connection = connection
        self.set_button = set_button_cb
        # 新增settings_obj变量,用于访问shared_methods.Settings对象
        self.settings_obj = settings_obj
        self.settings_obj.initial_lock = True

        self.need_ssid = need_ssid
        self.presave_index = None

        if self.need_ssid:
            log.info("enter hidden network settings")
            self.add_ssid_entry()
        
        if self.connection.get_setting("802-11-wireless").security == "802-11-wireless-security":
            self.has_security = True
            self.setting = self.connection.get_setting("802-11-wireless-security")
        else:
            self.has_security = False
        self.security_label = Label(_("Security:"),
                                    enable_select=False,
                                    enable_double_click=False)
        self.key_label = Label(_("Key:"),
                               enable_select=False,
                               enable_double_click=False)
        self.wep_index_label = Label(_("Wep index:"),
                                     enable_select=False,
                                     enable_double_click=False)

        self.auth_label = Label(_("Authentication:"),
                                enable_select=False,
                                enable_double_click=False)
        self.password_label = Label(_("Password:"******"None"), None),
                      (_("WEP (Hex or ASCII)"), "none"),
                      (_("WEP 104/128-bit Passphrase"), "none"),
                      (_("WPA WPA2 Personal"), "wpa-psk")]
        #entry_item = map(lambda l: (l[1],l[0]), enumerate(self.encry_list))
        self.security_combo = ComboBox(self.encry_list, fixed_width=self.ENTRY_WIDTH)
        #self.security_combo.set_size_request(self.ENTRY_WIDTH, 22)

        self.key_entry = PasswordEntry()
        self.password_entry = PasswordEntry()
        self.show_key_check = CheckButton(_("Show password"), padding_x=0)
        self.show_key_check.connect("toggled", self.show_key_check_button_cb)
        self.wep_index_spin = SpinBox(0, 1, 4, 1, self.ENTRY_WIDTH)
        self.auth_combo = ComboBox([
                                    (_("Shared Key"), "shared"),
                                    (_("Open System"), "open")],fixed_width=self.ENTRY_WIDTH)

        ## advance button
        self.align = gtk.Alignment(0, 1.0, 0, 0)
        self.align.set_padding(0, 0, 376, 0)
        self.align.set_size_request(-1 ,30)
        self.button = Button(_("Advanced"))
        self.align.add(self.button)

        ## Create table
        self.table = gtk.Table(5, 4)
        #TODO UI change
        label_list = ["security_label", "key_label", "wep_index_label", "auth_label", "password_label"]
        widget_list = ["password_entry", "key_entry", "wep_index_spin", "auth_combo", "security_combo"]
        for label in label_list:
            l = getattr(self, label)
            l.set_can_focus(False)
            align = style.wrap_with_align(l, width=210)
            setattr(self, label+"_align", align)

        for w in widget_list:
            l = getattr(self, w)
            align = style.wrap_with_align(l, align="left")
            setattr(self, w+"_align", align)

        self.show_key_check_align = style.wrap_with_align(self.show_key_check, align="left")

        self.reset(self.has_security)
        self.security_combo.connect("item-selected", self.change_encry_type)
        self.key_entry.entry.connect("changed", self.save_wep_pwd)
        self.password_entry.entry.connect("changed", self.save_wpa_pwd)
        self.wep_index_spin.connect("value-changed", self.wep_index_spin_cb)
        self.auth_combo.connect("item-selected", self.save_auth_cb)
        
        style.set_table(self.table)
        table_align = gtk.Alignment(0, 0, 0, 0)
        table_align.add(self.table)
        style.draw_background_color(self)
        width, height = self.ENTRY_WIDTH, 22
        self.key_entry.set_size(width, height)
        self.password_entry.set_size(width, height)
        self.wep_index_spin.set_size_request(width, height)
        self.auth_combo.set_size_request(width, height)
        self.security_combo.set_size_request(width, height)
        self.pack_start(table_align, False, False)
        self.pack_start(self.align, False, False, 0)
        self.settings_obj.initial_lock = False

    def add_ssid_entry(self):
        self.wireless = self.connection.get_setting("802-11-wireless")
        self.ssid_label = Label(_("SSID:"),
                                enable_select=False,
                                enable_double_click=False)
        self.ssid_label_align = style.wrap_with_align(self.ssid_label, width=210)
        self.ssid_entry = InputEntry()
        self.ssid_entry.set_size(self.ENTRY_WIDTH, 22)
        self.ssid_entry_align = style.wrap_with_align(self.ssid_entry, align="left")
        self.ssid_entry.entry.connect("changed", self.set_ssid)
        self.ssid_entry.set_text(self.wireless.ssid)

        #self.add(align)

    def set_ssid(self, widget, content):
        self.wireless.ssid = content
        check_settings(self.connection, None)

    def advand_cb(self, widget):
        pass

    def reset(self, security=True):
        ## Add security
        container_remove_all(self.table)
        if self.need_ssid:
            self.table.attach(self.ssid_label_align, 0, 1, 0, 1)
            self.table.attach(self.ssid_entry_align, 1, 4, 0, 1)
        
        self.table.resize(2, 4)
        self.table.attach(self.security_label_align, 0, 1, 1, 2)
        self.table.attach(self.security_combo_align, 1, 4, 1, 2)

        if not security:
            self.presave_index = self.security_combo.get_select_index()
            return 
        
        keys = [None, "none", "none","wpa-psk"]
        
        self.key_mgmt = self.setting.key_mgmt
        if self.key_mgmt == "none":
            key_type = self.setting.wep_key_type
            self.security_combo.set_select_index(key_type)
        else:
            self.security_combo.set_select_index(keys.index(self.key_mgmt))

        if not self.security_combo.get_current_item()[1] == None: 
            try:
                (setting_name, method) = self.connection.guess_secret_info() 
                secret = nm_module.secret_agent.agent_get_secrets(self.connection.object_path,
                                                        setting_name,
                                                        method)
                if secret == None:
                    secret = ''
                log.debug("get secret", setting_name, method, "secret")
            except Exception, e:
                log.error("get secret error", e)
                secret = ""

            if self.security_combo.get_current_item()[1] == "wpa-psk":
                self.table.resize(4, 4)
                self.table.attach(self.password_label_align, 0, 1, 2, 3)
                self.table.attach(self.password_entry_align, 1, 4, 2, 3)
                self.table.attach(self.show_key_check_align, 1, 4, 3, 4)
                
                self.password_entry.entry.set_text(secret)
                if secret:
                    #Dispatcher.set_button("save", True)
                    ###########
                    self.settings_obj.wlan_encry_is_valid = True
                    self.settings_obj.set_button("save", True)
                self.setting.psk = secret

            elif self.security_combo.get_current_item()[1] == "none":
                self.table.resize(6, 4)
                # Add Key
                self.table.attach(self.key_label_align, 0, 1, 2, 3)
                self.table.attach(self.key_entry_align, 1, 4, 2, 3)
                self.table.attach(self.show_key_check_align, 1, 4, 3, 4)
                # Add wep index
                self.table.attach(self.wep_index_label_align, 0, 1, 4, 5)
                self.table.attach(self.wep_index_spin_align, 1, 4, 4, 5)
                # Add Auth
                self.table.attach(self.auth_label_align, 0, 1, 5, 6)
                self.table.attach(self.auth_combo_align, 1, 4, 5, 6)

                # Retrieve wep properties
                try:
                    index = self.setting.wep_tx_keyidx
                    auth = self.setting.auth_alg
                    log.debug(auth, index)
                    self.auth_combo.set_select_index(["shared", "open"].index(auth))
                except Exception, e:
                    log.error(e)
                    index = 0
                    auth = "shared"
                # must convert long int to int 
                index = int(index)
                
                #init_key = True
                #if isinstance(self.connection, NMRemoteConnection):
                    #init_setting = self.connection.get_setting("802-11-wireless-security")
                    #if init_setting.wep_key_type != self.setting.wep_key_type:
                        #init_key = False

                #if init_key:
                self.key_entry.entry.set_text(secret)
                self.setting.set_wep_key(index, secret)
                self.wep_index_spin.set_value(index + 1)
                self.auth_combo.set_select_index(["shared", "open"].index(auth))
コード例 #19
0
ファイル: toolbar.py プロジェクト: xbot/deepin-screenshot
    def __init__(self, parent=None, screenshot=None):
        '''
        init colorbar
        @param parent: the transient parent for this window
        @param screenshot: a Screenshot object
        '''
        self.screenshot = screenshot
        self.win = self.screenshot.window

        #padding_x = 5
        #padding_y = 3
        #icon_width = icon_height = 28
        #self.width = 280
        #color_num = 9
        #self.height = icon_height + padding_y * 2
        self.height = 36
        self.width = 279
        self.width_no_fill = 254
        self.width_text = 259

        self.window = Window(window_type=gtk.WINDOW_POPUP,
                             shadow_visible=False)
        self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG)
        self.window.set_keep_above(True)
        self.window.set_transient_for(parent)
        self.window.set_decorated(False)

        #vbox = gtk.VBox(False, 0)
        self.box = gtk.HBox(False, 5)
        self.size_box = gtk.HBox(False, 5)
        self.dynamic_box = gtk.HBox()

        colorbox_align = gtk.Alignment()
        #colorbox_align.set(0.5, 0.5, 0, 0)
        colorbox_align.set(0, 0.5, 1, 0)
        colorbox_align.set_padding(2, 2, 11, 11)
        colorbox_align.add(self.box)
        self.window.window_frame.pack_start(colorbox_align, True, True)
        self.window.set_size_request(self.width, self.height)
        #self.window.set_size_request(-1, self.height)

        self.__size_button_dict = {}
        self.create_size_button("small", ACTION_SIZE_SMALL)
        self.create_size_button("normal", ACTION_SIZE_NORMAL)
        self.create_size_button("big", ACTION_SIZE_BIG)
        self.create_size_button("ellipse_fill",
                                ACTION_SIZE_RECTANGLE_ELLIPSE_FILL)
        self.create_size_button("rect_fill",
                                ACTION_SIZE_RECTANGLE_ELLIPSE_FILL)
        self._set_size_button_state("small", True)

        self.size_align = gtk.Alignment()
        #self.size_align.set(0.5,0.5,0,0)
        self.size_align.set(0, 0.5, 1, 0)
        self.size_align.add(self.size_box)
        #self.dynamic_box.pack_start(self.size_align)
        self.box.pack_start(self.dynamic_box)

        # font select
        self.font_box = gtk.HBox(False, 5)
        font_img = gtk.image_new_from_pixbuf(
            app_theme.get_pixbuf("action/text_normal.png").get_pixbuf())
        self.font_spin = SpinBox(self.screenshot.font_size, 8, 72, 1)
        self.font_spin.connect("value-changed", self._font_size_changed)
        self.font_spin.value_entry.set_can_focus(False)
        self.font_box.pack_start(font_img)
        self.font_box.pack_start(self.font_spin)
        self.font_align = gtk.Alignment()
        self.font_align.set(0.5, 0.5, 0, 0)
        self.font_align.add(self.font_box)

        # color select
        #self.color_select = gtk.EventBox()
        self.color_select = gtk.Image()
        pix = app_theme.get_pixbuf("color_big/red.png").get_pixbuf()
        self.color_select.set_from_pixbuf(pix)

        self.box.pack_start(self.color_select, False, False)

        # color button
        self.vbox = gtk.VBox(False, 2)
        self.above_hbox = gtk.HBox(False, 2)
        self.below_hbox = gtk.HBox(False, 2)
        self.color_map = {
            'black': "#000000",  # 1-1
            'gray_dark': "#808080",  # 1-2
            'red': "#FF0000",  # 1-3
            'yellow_dark': "#FF9B00",  # 1-4
            'yellow': "#FFFF00",  # 1-5
            'green': "#B2E700",  # 1-6
            'green_dark': "#008000",  # 1-7
            'wathet_dark': "#008080",  # 1-8
            'white': "#FFFFFF",  # 2-1
            'gray': "#C0C0C0",  # 2-2
            'red_dark': "#E2004E",  # 2-3
            'pink': "#E2007A",  # 2-4
            'pink_dark': "#800080",  # 2-5
            'blue_dark': "#000080",  # 2-6
            'blue': "#0085E1",  # 2-7
            'wathet': "#009DE0"
        }  # 2-8

        self.create_color_button(self.above_hbox, "black")
        self.create_color_button(self.above_hbox, "gray_dark")
        self.create_color_button(self.above_hbox, "red")
        self.create_color_button(self.above_hbox, "yellow_dark")
        self.create_color_button(self.above_hbox, "yellow")
        self.create_color_button(self.above_hbox, "green")
        self.create_color_button(self.above_hbox, "green_dark")
        self.create_color_button(self.above_hbox, "wathet_dark")

        self.create_color_button(self.below_hbox, "white")
        self.create_color_button(self.below_hbox, "gray")
        self.create_color_button(self.below_hbox, "red_dark")
        self.create_color_button(self.below_hbox, "pink")
        self.create_color_button(self.below_hbox, "pink_dark")
        self.create_color_button(self.below_hbox, "blue_dark")
        self.create_color_button(self.below_hbox, "blue")
        self.create_color_button(self.below_hbox, "wathet")

        self.vbox.pack_start(self.above_hbox)
        self.vbox.pack_start(self.below_hbox)
        self.box.pack_start(self.vbox)
コード例 #20
0
ファイル: toolbar.py プロジェクト: xbot/deepin-screenshot
class Colorbar():
    ''' Colorbar window '''
    def __init__(self, parent=None, screenshot=None):
        '''
        init colorbar
        @param parent: the transient parent for this window
        @param screenshot: a Screenshot object
        '''
        self.screenshot = screenshot
        self.win = self.screenshot.window

        #padding_x = 5
        #padding_y = 3
        #icon_width = icon_height = 28
        #self.width = 280
        #color_num = 9
        #self.height = icon_height + padding_y * 2
        self.height = 36
        self.width = 279
        self.width_no_fill = 254
        self.width_text = 259

        self.window = Window(window_type=gtk.WINDOW_POPUP,
                             shadow_visible=False)
        self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG)
        self.window.set_keep_above(True)
        self.window.set_transient_for(parent)
        self.window.set_decorated(False)

        #vbox = gtk.VBox(False, 0)
        self.box = gtk.HBox(False, 5)
        self.size_box = gtk.HBox(False, 5)
        self.dynamic_box = gtk.HBox()

        colorbox_align = gtk.Alignment()
        #colorbox_align.set(0.5, 0.5, 0, 0)
        colorbox_align.set(0, 0.5, 1, 0)
        colorbox_align.set_padding(2, 2, 11, 11)
        colorbox_align.add(self.box)
        self.window.window_frame.pack_start(colorbox_align, True, True)
        self.window.set_size_request(self.width, self.height)
        #self.window.set_size_request(-1, self.height)

        self.__size_button_dict = {}
        self.create_size_button("small", ACTION_SIZE_SMALL)
        self.create_size_button("normal", ACTION_SIZE_NORMAL)
        self.create_size_button("big", ACTION_SIZE_BIG)
        self.create_size_button("ellipse_fill",
                                ACTION_SIZE_RECTANGLE_ELLIPSE_FILL)
        self.create_size_button("rect_fill",
                                ACTION_SIZE_RECTANGLE_ELLIPSE_FILL)
        self._set_size_button_state("small", True)

        self.size_align = gtk.Alignment()
        #self.size_align.set(0.5,0.5,0,0)
        self.size_align.set(0, 0.5, 1, 0)
        self.size_align.add(self.size_box)
        #self.dynamic_box.pack_start(self.size_align)
        self.box.pack_start(self.dynamic_box)

        # font select
        self.font_box = gtk.HBox(False, 5)
        font_img = gtk.image_new_from_pixbuf(
            app_theme.get_pixbuf("action/text_normal.png").get_pixbuf())
        self.font_spin = SpinBox(self.screenshot.font_size, 8, 72, 1)
        self.font_spin.connect("value-changed", self._font_size_changed)
        self.font_spin.value_entry.set_can_focus(False)
        self.font_box.pack_start(font_img)
        self.font_box.pack_start(self.font_spin)
        self.font_align = gtk.Alignment()
        self.font_align.set(0.5, 0.5, 0, 0)
        self.font_align.add(self.font_box)

        # color select
        #self.color_select = gtk.EventBox()
        self.color_select = gtk.Image()
        pix = app_theme.get_pixbuf("color_big/red.png").get_pixbuf()
        self.color_select.set_from_pixbuf(pix)

        self.box.pack_start(self.color_select, False, False)

        # color button
        self.vbox = gtk.VBox(False, 2)
        self.above_hbox = gtk.HBox(False, 2)
        self.below_hbox = gtk.HBox(False, 2)
        self.color_map = {
            'black': "#000000",  # 1-1
            'gray_dark': "#808080",  # 1-2
            'red': "#FF0000",  # 1-3
            'yellow_dark': "#FF9B00",  # 1-4
            'yellow': "#FFFF00",  # 1-5
            'green': "#B2E700",  # 1-6
            'green_dark': "#008000",  # 1-7
            'wathet_dark': "#008080",  # 1-8
            'white': "#FFFFFF",  # 2-1
            'gray': "#C0C0C0",  # 2-2
            'red_dark': "#E2004E",  # 2-3
            'pink': "#E2007A",  # 2-4
            'pink_dark': "#800080",  # 2-5
            'blue_dark': "#000080",  # 2-6
            'blue': "#0085E1",  # 2-7
            'wathet': "#009DE0"
        }  # 2-8

        self.create_color_button(self.above_hbox, "black")
        self.create_color_button(self.above_hbox, "gray_dark")
        self.create_color_button(self.above_hbox, "red")
        self.create_color_button(self.above_hbox, "yellow_dark")
        self.create_color_button(self.above_hbox, "yellow")
        self.create_color_button(self.above_hbox, "green")
        self.create_color_button(self.above_hbox, "green_dark")
        self.create_color_button(self.above_hbox, "wathet_dark")

        self.create_color_button(self.below_hbox, "white")
        self.create_color_button(self.below_hbox, "gray")
        self.create_color_button(self.below_hbox, "red_dark")
        self.create_color_button(self.below_hbox, "pink")
        self.create_color_button(self.below_hbox, "pink_dark")
        self.create_color_button(self.below_hbox, "blue_dark")
        self.create_color_button(self.below_hbox, "blue")
        self.create_color_button(self.below_hbox, "wathet")

        self.vbox.pack_start(self.above_hbox)
        self.vbox.pack_start(self.below_hbox)
        self.box.pack_start(self.vbox)

    def create_color_button(self, box, name):
        '''
        create color button
        @param box: a gtk.HBox
        @param name: the button's name
        '''
        button = ImageButton(
            app_theme.get_pixbuf("color/" + name + ".png"),
            app_theme.get_pixbuf("color/" + name + "_hover.png"),
            app_theme.get_pixbuf("color/" + name + "_hover.png"))
        button.connect('pressed', lambda w: self._color_button_pressed(name))
        box.pack_start(button)

    def create_toggle_button(self, name):
        '''
        create a togglebutton
        @param name: the button's name
        @return: a dtk.ui.ToggleButton
        '''
        button = ToggleButton(
            app_theme.get_pixbuf("size/" + name + ".png"),
            app_theme.get_pixbuf("size/" + name + "_press.png"),
            app_theme.get_pixbuf("size/" + name + "_hover.png"),
            app_theme.get_pixbuf("size/" + name + "_press.png"))
        button.set_name(name)
        return button

    def create_size_button(self, name, index):
        '''
        create size button
        @param name: the button's name
        @param index: the button's index in button list
        @return: a dtk.ui.ToggleButton
        '''
        button = self.create_toggle_button(name)
        button.connect("pressed", self._size_button_pressed, index)
        #button.connect("toggled", self._size_button_toggled, name)
        button.connect("released", self._size_button_released)
        self.size_box.pack_start(button)
        self.__size_button_dict[name] = button
        return button

    def _font_size_changed(self, widget, value):
        '''font size changed, SpinBox changed callback'''
        self.screenshot.font_size = value
        if self.screenshot.show_text_window_flag:
            if not self.screenshot.text_window.set_font_size(value):
                #print value, self.screenshot.text_window.get_font_size()
                widget.set_value(self.screenshot.text_window.get_font_size())
            self.win.refresh()

    def _color_button_pressed(self, name):
        ''' color button pressed callback'''
        pix = app_theme.get_pixbuf("color_big/" + name + ".png").get_pixbuf()
        self.color_select.set_from_pixbuf(pix)
        if self.screenshot is None:
            return
        self.screenshot.action_color = self.color_map[name]
        if self.screenshot.show_text_window_flag:
            self.screenshot.text_window.set_text_color(
                self.screenshot.action_color)
            self.win.refresh()

    def _size_button_pressed(self, widget, index):
        ''' size button pressed callback'''
        if self.screenshot is None:
            return
        self.screenshot.action_size = index
        for each in self.__size_button_dict:
            if self.__size_button_dict[each] == widget:
                continue
            else:
                self.__size_button_dict[each].set_active(False)

    def _size_button_released(self, widget):
        ''' size button release callback'''
        if not widget.get_active():
            widget.set_active(True)

    def _set_size_button_state(self, name, state):
        '''
        set size button state
        @param name: the button's name which will set
        @param state: the state to set, True or False
        '''
        for each in self.__size_button_dict.keys():
            if each == name:
                self.__size_button_dict[name].set_active(state)

    def show(self):
        ''' show the colorbar'''
        # action is text, show font size set
        if self.screenshot.action == ACTION_TEXT:
            self.window.set_size_request(self.width_text, self.height)
            self.window.resize(self.width_text, self.height)
            if self.size_align in self.dynamic_box.get_children():
                self.dynamic_box.remove(self.size_align)
            if self.font_align not in self.dynamic_box.get_children():
                self.dynamic_box.add(self.font_align)
        # show draw size
        else:
            if self.font_align in self.dynamic_box.get_children():
                self.dynamic_box.remove(self.font_align)
            if self.size_align not in self.dynamic_box.get_children():
                self.dynamic_box.add(self.size_align)
            # actin is rectangle or ellispe, show fill button
            # show rect fill button
            if self.screenshot.action == ACTION_RECTANGLE:
                self.window.set_size_request(self.width, self.height)
                self.window.resize(self.width, self.height)
                if self.__size_button_dict[
                        'rect_fill'] not in self.size_box.get_children():
                    self.size_box.pack_start(
                        self.__size_button_dict['rect_fill'])
                if self.__size_button_dict[
                        'ellipse_fill'] in self.size_box.get_children():
                    self.size_box.remove(
                        self.__size_button_dict['ellipse_fill'])
                if self.__size_button_dict['ellipse_fill'].get_active():
                    self.__size_button_dict['rect_fill'].pressed()
                    self.__size_button_dict['rect_fill'].released()

            # show ellipse fill button
            elif self.screenshot.action == ACTION_ELLIPSE:
                self.window.set_size_request(self.width, self.height)
                self.window.resize(self.width, self.height)
                if self.__size_button_dict[
                        'ellipse_fill'] not in self.size_box.get_children():
                    self.size_box.pack_start(
                        self.__size_button_dict['ellipse_fill'])
                if self.__size_button_dict[
                        'rect_fill'] in self.size_box.get_children():
                    self.size_box.remove(self.__size_button_dict['rect_fill'])
                if self.__size_button_dict['rect_fill'].get_active():
                    self.__size_button_dict['ellipse_fill'].pressed()
                    self.__size_button_dict['ellipse_fill'].released()

            # don't show fill button
            else:
                self.window.set_size_request(self.width_no_fill, self.height)
                self.window.resize(self.width_no_fill, self.height)
                if self.__size_button_dict[
                        'rect_fill'] in self.size_box.get_children():
                    if self.__size_button_dict['rect_fill'].get_active():
                        self.__size_button_dict['small'].pressed()
                        self.__size_button_dict['small'].released()
                    self.size_box.remove(self.__size_button_dict['rect_fill'])
                if self.__size_button_dict[
                        'ellipse_fill'] in self.size_box.get_children():
                    if self.__size_button_dict['ellipse_fill'].get_active():
                        self.__size_button_dict['small'].pressed()
                        self.__size_button_dict['small'].released()
                    self.size_box.remove(
                        self.__size_button_dict['ellipse_fill'])
        if not self.window.get_visible():
            self.window.show_window()
        #print "colorbox:", self.box.allocation, self.window.allocation

    def hide(self):
        '''hide the toolbar'''
        if self.window.get_visible():
            self.window.hide_all()
コード例 #21
0
    text_entry = dtk.ui.entry.TextEntry()

    text_entry.set_size(100, 22)
    input_entry = InputEntry()
    input_entry.entry.place_holder = "哈哈中"
    input_entry.set_size(100, 22)
    shortcust_entry = ShortcutKeyEntry()
    shortcust_entry.set_size(100, 22)
    password_entry = PasswordEntry()
    password_entry.set_size(100, 22)

    combo_box = ComboBox([("测试测试测试%d" % i, i) for i in range(10)],
                         fixed_width=100)

    spin_box = SpinBox(3000, 0, 5000, 100)

    # mac_entry = MACEntry()
    mac_entry = IPV4Entry()
    mac_entry.connect("changed", print_address)
    # mac_entry = IPV4Entry()
    # mac_entry.set_ip("255.255.255.andy")
    # mac_entry.set_ip("192.168..12")
    # mac_entry.set_ip("192.168..12")
    # mac_entry.set_ip("...")

    # entry_box.pack_start(text_entry, False, False)
    # entry_box.pack_start(input_entry, False, False)
    entry_box.pack_start(mac_entry, False, False)
    # entry_box.pack_start(shortcust_entry, False, False)
    # entry_box.pack_start(password_entry, False, False)
コード例 #22
0
class Security(gtk.VBox):
    ENTRY_WIDTH = 222

    def __init__(self,
                 connection,
                 set_button_cb,
                 need_ssid=False,
                 settings_obj=None):
        gtk.VBox.__init__(self)
        self.tab_name = _("Security")
        self.connection = connection
        self.set_button = set_button_cb
        # 新增settings_obj变量,用于访问shared_methods.Settings对象
        self.settings_obj = settings_obj
        self.settings_obj.initial_lock = True

        self.need_ssid = need_ssid
        self.presave_index = None

        if self.need_ssid:
            log.info("enter hidden network settings")
            self.add_ssid_entry()

        if self.connection.get_setting(
                "802-11-wireless").security == "802-11-wireless-security":
            self.has_security = True
            self.setting = self.connection.get_setting(
                "802-11-wireless-security")
        else:
            self.has_security = False
        self.security_label = Label(_("Security:"),
                                    enable_select=False,
                                    enable_double_click=False)
        self.key_label = Label(_("Key:"),
                               enable_select=False,
                               enable_double_click=False)
        self.wep_index_label = Label(_("Wep index:"),
                                     enable_select=False,
                                     enable_double_click=False)

        self.auth_label = Label(_("Authentication:"),
                                enable_select=False,
                                enable_double_click=False)
        self.password_label = Label(_("Password:"******"None"), None),
                           (_("WEP (Hex or ASCII)"), "none"),
                           (_("WEP 104/128-bit Passphrase"), "none"),
                           (_("WPA WPA2 Personal"), "wpa-psk")]
        #entry_item = map(lambda l: (l[1],l[0]), enumerate(self.encry_list))
        self.security_combo = ComboBox(self.encry_list,
                                       fixed_width=self.ENTRY_WIDTH)
        #self.security_combo.set_size_request(self.ENTRY_WIDTH, 22)

        self.key_entry = PasswordEntry()
        self.password_entry = PasswordEntry()
        self.show_key_check = CheckButton(_("Show password"), padding_x=0)
        self.show_key_check.connect("toggled", self.show_key_check_button_cb)
        self.wep_index_spin = SpinBox(0, 1, 4, 1, self.ENTRY_WIDTH)
        self.auth_combo = ComboBox([(_("Shared Key"), "shared"),
                                    (_("Open System"), "open")],
                                   fixed_width=self.ENTRY_WIDTH)

        ## advance button
        self.align = gtk.Alignment(0, 1.0, 0, 0)
        self.align.set_padding(0, 0, 376, 0)
        self.align.set_size_request(-1, 30)
        self.button = Button(_("Advanced"))
        self.align.add(self.button)

        ## Create table
        self.table = gtk.Table(5, 4)
        #TODO UI change
        label_list = [
            "security_label", "key_label", "wep_index_label", "auth_label",
            "password_label"
        ]
        widget_list = [
            "password_entry", "key_entry", "wep_index_spin", "auth_combo",
            "security_combo"
        ]
        for label in label_list:
            l = getattr(self, label)
            l.set_can_focus(False)
            align = style.wrap_with_align(l, width=210)
            setattr(self, label + "_align", align)

        for w in widget_list:
            l = getattr(self, w)
            align = style.wrap_with_align(l, align="left")
            setattr(self, w + "_align", align)

        self.show_key_check_align = style.wrap_with_align(self.show_key_check,
                                                          align="left")

        self.reset(self.has_security)
        self.security_combo.connect("item-selected", self.change_encry_type)
        self.key_entry.entry.connect("changed", self.save_wep_pwd)
        self.password_entry.entry.connect("changed", self.save_wpa_pwd)
        self.wep_index_spin.connect("value-changed", self.wep_index_spin_cb)
        self.auth_combo.connect("item-selected", self.save_auth_cb)

        style.set_table(self.table)
        table_align = gtk.Alignment(0, 0, 0, 0)
        table_align.add(self.table)
        style.draw_background_color(self)
        width, height = self.ENTRY_WIDTH, 22
        self.key_entry.set_size(width, height)
        self.password_entry.set_size(width, height)
        self.wep_index_spin.set_size_request(width, height)
        self.auth_combo.set_size_request(width, height)
        self.security_combo.set_size_request(width, height)
        self.pack_start(table_align, False, False)
        self.pack_start(self.align, False, False, 0)
        self.settings_obj.initial_lock = False

    def add_ssid_entry(self):
        self.wireless = self.connection.get_setting("802-11-wireless")
        self.ssid_label = Label(_("SSID:"),
                                enable_select=False,
                                enable_double_click=False)
        self.ssid_label_align = style.wrap_with_align(self.ssid_label,
                                                      width=210)
        self.ssid_entry = InputEntry()
        self.ssid_entry.set_size(self.ENTRY_WIDTH, 22)
        self.ssid_entry_align = style.wrap_with_align(self.ssid_entry,
                                                      align="left")
        self.ssid_entry.entry.connect("changed", self.set_ssid)
        self.ssid_entry.set_text(self.wireless.ssid)

        #self.add(align)

    def set_ssid(self, widget, content):
        self.wireless.ssid = content
        check_settings(self.connection, None)

    def advand_cb(self, widget):
        pass

    def reset(self, security=True):
        ## Add security
        container_remove_all(self.table)
        if self.need_ssid:
            self.table.attach(self.ssid_label_align, 0, 1, 0, 1)
            self.table.attach(self.ssid_entry_align, 1, 4, 0, 1)

        self.table.resize(2, 4)
        self.table.attach(self.security_label_align, 0, 1, 1, 2)
        self.table.attach(self.security_combo_align, 1, 4, 1, 2)

        if not security:
            self.presave_index = self.security_combo.get_select_index()
            return

        keys = [None, "none", "none", "wpa-psk"]

        self.key_mgmt = self.setting.key_mgmt
        if self.key_mgmt == "none":
            key_type = self.setting.wep_key_type
            self.security_combo.set_select_index(key_type)
        else:
            self.security_combo.set_select_index(keys.index(self.key_mgmt))

        if not self.security_combo.get_current_item()[1] == None:
            try:
                (setting_name, method) = self.connection.guess_secret_info()
                secret = nm_module.secret_agent.agent_get_secrets(
                    self.connection.object_path, setting_name, method)
                if secret == None:
                    secret = ''
                log.debug("get secret", setting_name, method, "secret")
            except Exception, e:
                log.error("get secret error", e)
                secret = ""

            if self.security_combo.get_current_item()[1] == "wpa-psk":
                self.table.resize(4, 4)
                self.table.attach(self.password_label_align, 0, 1, 2, 3)
                self.table.attach(self.password_entry_align, 1, 4, 2, 3)
                self.table.attach(self.show_key_check_align, 1, 4, 3, 4)

                self.password_entry.entry.set_text(secret)
                if secret:
                    #Dispatcher.set_button("save", True)
                    ###########
                    self.settings_obj.wlan_encry_is_valid = True
                    self.settings_obj.set_button("save", True)
                self.setting.psk = secret

            elif self.security_combo.get_current_item()[1] == "none":
                self.table.resize(6, 4)
                # Add Key
                self.table.attach(self.key_label_align, 0, 1, 2, 3)
                self.table.attach(self.key_entry_align, 1, 4, 2, 3)
                self.table.attach(self.show_key_check_align, 1, 4, 3, 4)
                # Add wep index
                self.table.attach(self.wep_index_label_align, 0, 1, 4, 5)
                self.table.attach(self.wep_index_spin_align, 1, 4, 4, 5)
                # Add Auth
                self.table.attach(self.auth_label_align, 0, 1, 5, 6)
                self.table.attach(self.auth_combo_align, 1, 4, 5, 6)

                # Retrieve wep properties
                try:
                    index = self.setting.wep_tx_keyidx
                    auth = self.setting.auth_alg
                    log.debug(auth, index)
                    self.auth_combo.set_select_index(["shared",
                                                      "open"].index(auth))
                except Exception, e:
                    log.error(e)
                    index = 0
                    auth = "shared"
                # must convert long int to int
                index = int(index)

                #init_key = True
                #if isinstance(self.connection, NMRemoteConnection):
                #init_setting = self.connection.get_setting("802-11-wireless-security")
                #if init_setting.wep_key_type != self.setting.wep_key_type:
                #init_key = False

                #if init_key:
                self.key_entry.entry.set_text(secret)
                self.setting.set_wep_key(index, secret)
                self.wep_index_spin.set_value(index + 1)
                self.auth_combo.set_select_index(["shared",
                                                  "open"].index(auth))
コード例 #23
0
    def __init__(self, parent=None, screenshot=None):
        '''
        init colorbar
        @param parent: the transient parent for this window
        @param screenshot: a Screenshot object
        '''
        self.screenshot = screenshot
        self.win = self.screenshot.window
        
        self.height = 36
        self.width = 279
        
        self.window = Window(window_type=gtk.WINDOW_POPUP, shadow_visible=False)
        self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG)
        self.window.set_keep_above(True)
        self.window.set_transient_for(parent)
        self.window.set_decorated(False)

        #vbox = gtk.VBox(False, 0)
        self.box = gtk.HBox(False, 5)
        self.size_box = gtk.HBox(False, 5)
        self.dynamic_box = gtk.HBox()
        
        colorbox_align = gtk.Alignment()
        #colorbox_align.set(0.5, 0.5, 0, 0)
        colorbox_align.set(0, 0.5, 1, 0)
        colorbox_align.set_padding(2, 2, 11, 11)
        colorbox_align.add(self.box)
        self.window.window_frame.pack_start(colorbox_align, True, True)
        self.window.set_size_request(self.width, self.height)
        #self.window.set_size_request(-1, self.height)

        self.__size_button_dict = {}
        self.create_size_button("small", ACTION_SIZE_SMALL)
        self.create_size_button("normal", ACTION_SIZE_NORMAL)
        self.create_size_button("big", ACTION_SIZE_BIG)
        self.create_size_button("ellipse_fill", ACTION_SIZE_RECTANGLE_ELLIPSE_FILL)
        self.create_size_button("rect_fill", ACTION_SIZE_RECTANGLE_ELLIPSE_FILL)
        self._set_size_button_state("small", True)

        self.size_align = gtk.Alignment()
        #self.size_align.set(0.5,0.5,0,0)
        self.size_align.set(0, 0.5, 1, 0)
        self.size_align.add(self.size_box)
        #self.dynamic_box.pack_start(self.size_align)
        self.box.pack_start(self.dynamic_box)
        
        # font select
        self.font_box = gtk.HBox(False, 5)
        font_img = gtk.image_new_from_pixbuf(app_theme.get_pixbuf("action/text_normal.png").get_pixbuf())
        self.font_spin = SpinBox(self.screenshot.font_size, 8, 72, 1)
        self.font_spin.connect("value-changed", self._font_size_changed)
        self.font_spin.value_entry.set_can_focus(False)
        self.font_box.pack_start(font_img)
        self.font_box.pack_start(self.font_spin)
        self.font_align = gtk.Alignment()
        self.font_align.set(0.5,0.5,0,0)
        self.font_align.add(self.font_box)

        # color select
        #self.color_select = gtk.EventBox()
        self.color_select = gtk.Image()
        pix = app_theme.get_pixbuf("color_big/red.png").get_pixbuf()
        self.color_select.set_from_pixbuf(pix)

        self.box.pack_start(self.color_select, False, False)
        
        # color button
        self.vbox = gtk.VBox(False, 2)
        self.above_hbox = gtk.HBox(False, 2)
        self.below_hbox = gtk.HBox(False, 2)
        self.color_map = {
            'black'       : "#000000",  # 1-1
            'gray_dark'   : "#808080",  # 1-2
            'red'         : "#FF0000",  # 1-3
            'yellow_dark' : "#FF9B00",  # 1-4
            'yellow'      : "#FFFF00",  # 1-5
            'green'       : "#B2E700",  # 1-6
            'green_dark'  : "#008000",  # 1-7
            'wathet_dark' : "#008080",  # 1-8
            'white'       : "#FFFFFF",  # 2-1
            'gray'        : "#C0C0C0",  # 2-2
            'red_dark'    : "#E2004E",  # 2-3
            'pink'        : "#E2007A",  # 2-4
            'pink_dark'   : "#800080",  # 2-5
            'blue_dark'   : "#000080",  # 2-6
            'blue'        : "#0085E1",  # 2-7
            'wathet'      : "#009DE0"}  # 2-8

        self.create_color_button(self.above_hbox, "black")
        self.create_color_button(self.above_hbox, "gray_dark")
        self.create_color_button(self.above_hbox, "red")
        self.create_color_button(self.above_hbox, "yellow_dark")
        self.create_color_button(self.above_hbox, "yellow")
        self.create_color_button(self.above_hbox, "green")
        self.create_color_button(self.above_hbox, "green_dark")
        self.create_color_button(self.above_hbox, "wathet_dark")

        self.create_color_button(self.below_hbox, "white")
        self.create_color_button(self.below_hbox, "gray")
        self.create_color_button(self.below_hbox, "red_dark")
        self.create_color_button(self.below_hbox, "pink")
        self.create_color_button(self.below_hbox, "pink_dark")
        self.create_color_button(self.below_hbox, "blue_dark")
        self.create_color_button(self.below_hbox, "blue")
        self.create_color_button(self.below_hbox, "wathet")

        self.vbox.pack_start(self.above_hbox)
        self.vbox.pack_start(self.below_hbox)
        self.box.pack_start(self.vbox)
コード例 #24
0
class MirrorsBox(BaseBox):
    def __init__(self):
        BaseBox.__init__(self)

        self.current_mirror_item = None

        self.select_best_mirror_button_texts = {
                "normal": _("Select the best mirror"),
                "wait": _("Waiting"),
                "success": _("Successfully")
                }

        self.main_box.pack_start(self.create_mirror_select_table(), True, True)
        self.main_box.pack_start(self.create_source_update_frequency_table(), False, True)
        self.mirror_test_obj = None

        global_event.register_event("mirror-test-finished", self.finish_mirror_test)
        global_event.register_event("cancel-mirror-test", self.cancel_mirror_test)
        global_event.register_event("mirror-backend-changed", self.mirror_changed_handler)

    def create_source_update_frequency_table(self):
        main_table = gtk.Table(3, 2)
        main_table.set_row_spacings(CONTENT_ROW_SPACING)

        dir_title_label = Label(_("Refresh package lists"))

        # auto update check button
        self.is_auto_update_button = CheckButton(label_text=_('Upgrade automatically'))
        self.is_auto_update_button.connect('released', self.change_auto_update)
        self.is_auto_update_button.set_active(utils.is_auto_update())

        self.update_label = Label(_("Time interval: "))
        self.update_spin = SpinBox(int(get_update_interval()), 0, 168, 1)
        self.update_spin.connect("value-changed", lambda w, v: set_update_interval(v))
        self.hour_lablel = Label(_(" hour"))
        self.hour_lablel.set_size_request(50, 12)
        spin_hbox = gtk.HBox(spacing=3)
        spin_hbox.pack_start(self.update_label, False, False)
        spin_hbox.pack_start(self.update_spin, False, False)
        spin_hbox.pack_start(self.hour_lablel, False, False)

        main_table.attach(dir_title_label, 0, 2, 0, 1, yoptions=gtk.FILL)
        main_table.attach(create_separator_box(), 0, 2, 1, 2, yoptions=gtk.FILL)
        main_table.attach(self.is_auto_update_button, 0, 1, 2, 3, xoptions=gtk.FILL)
        main_table.attach(spin_hbox, 1, 2, 2, 3, xpadding=10, xoptions=gtk.FILL)
        return main_table

    def change_auto_update(self, widget, data=None):
        widget_active = widget.get_active()
        self.update_spin.set_sensitive(widget_active)
        self.update_label.set_sensitive(widget_active)
        self.hour_lablel.set_sensitive(widget_active)

        utils.set_auto_update(widget_active)

        daemon_running = is_dbus_name_exists(DSC_UPDATE_DAEMON_NAME)
        if widget_active and not daemon_running:
            dsc_daemon_path = os.path.join(get_parent_dir(__file__, 2), 'update_data/apt/dsc-daemon.py')
            subprocess.Popen(['python', dsc_daemon_path], stderr=subprocess.STDOUT, shell=False)
        elif not widget_active and daemon_running:
            session = dbus.SessionBus()
            dbus_obj = session.get_object(DSC_UPDATE_DAEMON_NAME, DSC_UPDATE_DAEMON_PATH)
            iface = dbus.Interface(dbus_obj, DSC_UPDATE_DAEMON_NAME)
            iface.quit()

    def select_best_mirror(self, widget):
        widget.set_label(self.select_best_mirror_button_texts["wait"])
        widget.set_sensitive(False)
        global_event.emit("toggle-waiting-dialog", True)
        utils.ThreadMethod(self.change_to_nearest_mirror_thread, (widget, )).start()

    def cancel_mirror_test(self):
        if self.mirror_test_obj:
            self.mirror_test_obj.cancel()
            self.mirror_test_obj = None
            self.finish_mirror_test("")

    def change_to_nearest_mirror_thread(self, widget):
        best_mirror = get_best_mirror()
        global_event.emit("mirror-test-finished", best_mirror)

    def finish_mirror_test(self, mirror):
        for item in self.mirror_view.visible_items:
            if item.mirror == mirror:
                self.mirror_view.visible_item(item)
        self.select_best_mirror_button.set_sensitive(True)
        self.select_best_mirror_button.set_label(self.select_best_mirror_button_texts["normal"])

    def create_mirror_select_table(self):
        main_table = gtk.Table(3, 2)
        main_table.set_row_spacings(CONTENT_ROW_SPACING)

        mirror_select_title = Label(_("Select mirror"))
        self.select_best_mirror_button = Button(self.select_best_mirror_button_texts["normal"])
        self.select_best_mirror_button.connect("clicked", self.select_best_mirror)

        self.mirrors_dir = os.path.join(get_parent_dir(__file__, 2), 'mirrors')
        self.current_mirror_hostname = utils.get_current_mirror_hostname()
        self.mirror_items = self.get_mirror_items()
        self.mirror_view = TreeView(self.mirror_items,
                                enable_drag_drop=False,
                                enable_multiple_select=False,
                                mask_bound_height=0,
                             )
        self.mirror_view.set_expand_column(1)
        self.mirror_view.set_size_request(-1, 280)
        self.mirror_view.draw_mask = self.mirror_treeview_draw_mask

        main_table.attach(mirror_select_title, 0, 1, 0, 1, yoptions=gtk.FILL)
        main_table.attach(self.select_best_mirror_button, 1, 2, 0, 1, xoptions=gtk.FILL)
        main_table.attach(create_separator_box(), 0, 2, 1, 2, xoptions=gtk.FILL)
        main_table.attach(self.mirror_view, 0, 2, 2, 3, xoptions=gtk.FILL)


        return main_table

    def mirror_changed_handler(self, mirror):
        item = None
        for i in self.mirror_view.visible_items:
            if i.mirror == mirror:
                item = i
                break
        if item:
            self.current_mirror_item = item
            for i in self.mirror_items:
                if i != item and i.radio_button.active == True:
                    i.radio_button.active = False
                elif i == item:
                    i.radio_button.active = True
            self.mirror_view.queue_draw()
            self.mirror_view.visible_item(item)

    def mirror_treeview_draw_mask(self, cr, x, y, w, h):
        cr.set_source_rgba(1, 1, 1, 0.5)
        cr.rectangle(x, y, w, h)
        cr.fill()

    def get_mirror_items(self):
        items = []
        for m in all_mirrors:
            item = MirrorItem(m, self.mirror_clicked_callback)
            if m.hostname == self.current_mirror_hostname:
                item.radio_button.active = True
                self.current_mirror_item = item
            items.append(item)
        return items

    def mirror_clicked_callback(self, item):
        if item != self.current_mirror_item:
            global_event.emit('start-change-mirror', item.mirror)