def __setup_combo(self, items=[], width=HSCALEBAR_WIDTH):
        if len(items) == 0:
            return None

        combo = ComboBox(items = items, select_index = 0, max_width = width, fixed_width = width)
        combo.set_size_request(width, WIDGET_HEIGHT)
        return combo
 def __init__(self, fixed_width, droplist_height=80):  # fixed_width=
     ComboBox.__init__(self,
                       droplist_height=droplist_height,
                       fixed_width=fixed_width)
     self.connect("item-selected", self.emit_connect_function)
     self.fixed_width = fixed_width
     self._items = []
     self.set_items = self.add_items
def get_combo_group(name, items, callback=None):
    box = gtk.HBox(spacing = 8)
    label = Label(name)
    combo_box = ComboBox(items)
    box.pack_start(label, False, False)
    box.pack_start(combo_box, False, False)
    
    if callback:
        combo_box.connect("item-selected", callback)
    return box, combo_box
def get_combo_group(name, items, callback=None):
    box = gtk.HBox(spacing=8)
    label = Label(name)
    combo_box = ComboBox(items)
    box.pack_start(label, False, False)
    box.pack_start(combo_box, False, False)

    if callback:
        combo_box.connect("item-selected", callback)
    return box, combo_box
    def __setup_combo(self, items=[], width=HSCALEBAR_WIDTH):
        if len(items) == 0:
            return None

        combo = ComboBox(items=items,
                         select_index=0,
                         max_width=width,
                         fixed_width=width)
        combo.set_size_request(width, WIDGET_HEIGHT)
        return combo
Example #6
0
 def create_combo_widget(self, label_content, items, select_index=0):
     label = Label(label_content)
     combo_box = ComboBox(items, select_index=select_index)
     hbox = gtk.HBox(spacing=5)
     hbox.pack_start(label, False, False)
     hbox.pack_start(combo_box, False, False)
     return hbox, combo_box
Example #7
0
    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(_('Maximum number of download tasks: '))
        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)
        main_table.attach(create_separator_box(), 0, 2, 1, 2, yoptions=gtk.FILL)
        main_table.attach(download_number_hbox, 0, 2, 2, 3, xoptions=gtk.FILL)
        main_table.attach(download_dir_hbox, 0, 2, 3, 4, xoptions=gtk.FILL)
        return main_table
Example #8
0
    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(_('Maximum number of download tasks: '))
        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)
        main_table.attach(create_separator_box(), 0, 2, 1, 2, yoptions=gtk.FILL)
        main_table.attach(download_number_hbox, 0, 2, 2, 3, xoptions=gtk.FILL)
        main_table.attach(download_dir_hbox, 0, 2, 3, 4, xoptions=gtk.FILL)
        return main_table
Example #9
0
class GeneralBox(BaseBox):
    def __init__(self):
        BaseBox.__init__(self)

        self.main_box.pack_start(self.create_uninstall_box(), False, True)
        self.main_box.pack_start(self.create_download_dir_table(), False, True)

    def create_uninstall_box(self):
        main_table = gtk.Table(2, 2)
        main_table.set_row_spacings(CONTENT_ROW_SPACING)
        uninstall_title_label = Label(_("On uninstalling the software"))

        # 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)
        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 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(_('Maximum number of download tasks: '))
        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)
        main_table.attach(create_separator_box(), 0, 2, 1, 2, yoptions=gtk.FILL)
        main_table.attach(download_number_hbox, 0, 2, 2, 3, xoptions=gtk.FILL)
        main_table.attach(download_dir_hbox, 0, 2, 3, 4, xoptions=gtk.FILL)
        return main_table

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

    def change_download_save_dir(self, widget):
        local_dir = FolderChooseDialog(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')
Example #10
0
 def __setup_combo(self, items=[]):
     combo = ComboBox(items, None, 0, max_width = 285, fixed_width = 285)
     combo.set_size_request(-1, WIDGET_HEIGHT)
     return combo
class DetailWindow(Window):
    '''
    class docs
    '''

    def __init__(self):
        '''
        init docs
        '''
        Window.__init__(self, enable_resize=True)
        self.set_size_request(WINDOW_WIDTH, WINDOW_HEIGHT)
        self.set_position(gtk.WIN_POS_CENTER)
        self.set_skip_taskbar_hint(True)
        self.set_skip_pager_hint(True)
        self.resizable = True

        self.classified_items = None
        self.__init_pixbuf()

        self.main_box = gtk.VBox()
        self.titlebar_box = gtk.HBox()
        self.toolbar_box = gtk.HBox()
        self.toolbar_box.set_size_request(-1, TOOLBAR_HEIGHT)

        self.main_view_box = gtk.HBox()
        self.main_view_box.set_size_request(WINDOW_WIDTH,
                                            WINDOW_HEIGHT - TITLEBAR_HEIGHT - TOOLBAR_HEIGHT - 23)

        self.add_titlebar()
        self.treeview_box = gtk.VBox()
        self.main_view_box.pack_start(self.treeview_box, False, False)
        self.listview_box = gtk.VBox()
        self.main_view_box.pack_start(self.listview_box, True, True)
        self.refresh_view() #add treeview and listview

        self.main_box.pack_start(self.toolbar_box, False, False)
        # self.main_box.pack_start(self.main_view_box, False, False)
        self.main_box.pack_start(self.main_view_box, True, True)
        # self.main_box.connect("expose-event", self.on_main_box_expose_event)

        main_box_align = gtk.Alignment(0.5, 0.5, 1, 1)
        main_box_align.set_padding(2, 2, 2, 2)
        main_box_align.add(self.main_box)

        self.window_frame.pack_start(self.titlebar_box, False, False)
        self.window_frame.pack_start(main_box_align)
        
    @property
    def is_empty(self):
        return not bool(len(self.classified_items))

    def __init_pixbuf(self):
        self.import_btn_pixbuf = gtk.gdk.pixbuf_new_from_file(app_theme.get_theme_file_path("image/toolbar_import.png"))
        self.export_btn_pixbuf = gtk.gdk.pixbuf_new_from_file(app_theme.get_theme_file_path("image/toolbar_export.png"))
        self.delete_btn_pixbuf = gtk.gdk.pixbuf_new_from_file(app_theme.get_theme_file_path("image/toolbar_delete.png"))
        self.refresh_btn_pixbuf = gtk.gdk.pixbuf_new_from_file(app_theme.get_theme_file_path("image/toolbar_refresh.png"))

        self.skin_preview_pixbuf = app_theme.get_pixbuf("frame.png")

    def _init_data(self):
        self.__init_data()
        
    def __init_data(self):
        self.classified_items = {}
        rows = db.get_all()

        for row in rows:
            app_name = row[MESSAGE].app_name
            self.classified_items.setdefault(app_name, []).append(row)
            
    def add_to_view(self):
        row = db.get_last()
        
        # add to data
        app_name = row[MESSAGE].app_name
        if app_name in self.classified_items.keys():
            self.classified_items[app_name].insert(0, row)
        else:
            self.classified_items.setdefault(app_name, []).insert(0, row)
            self.treeview_add_item(app_name)

        # add to view
        if app_name == self.treeview.get_highlight_item().get_title():
            self.factory.prepend_item(row)
            
    def refresh_view(self):
        self.__init_data()
        if len(self.classified_items):
            self.add_treeview()
            self.current_showed_items = self.get_items_from_treeview_highlight()
            self.add_listview(self.current_showed_items)
        else:
            align = gtk.Alignment(0.5, 0.5, 0, 0)
            align.add(Label(_("(Empty)")))
            container_remove_all(self.treeview_box)
            container_remove_all(self.listview_box)
            self.listview_box.pack_start(align, True, True)
        self.main_view_box.show_all()

        container_remove_all(self.toolbar_box)
        self.add_toolbar()
        self.toolbar_box.show_all()

    def on_main_box_expose_event(self, widget, event):
        cr = widget.window.cairo_create()
        rect = widget.allocation

        cr.rectangle(*rect)
        cr.set_source_rgb(*STROKE_LINE_COLOR)
        cr.stroke_preserve()
        cr.set_source_rgb(1, 1, 1)
        cr.fill()


    def on_treeview_draw_mask(self, cr, x, y, w, h):
        cr.set_source_rgb(1, 1, 1)
        cr.rectangle(x, y, w, h)
        cr.fill()

        cr.move_to(x, y)
        cr.line_to(x + w, y)
        cr.set_source_rgb(*STROKE_LINE_COLOR)
        cr.stroke()
        draw_line(cr, (x+w-1, y), (x+w-1, y+h), "#b2b2b2")

    def on_treeview_click_item(self, widget, item, column, x, y):
        if not item.is_parent:
            widget.set_highlight_item(item)

            self.current_showed_items = self.get_items_from_treeview_highlight()
            self.add_listview(self.current_showed_items)

            for comb_item in self.category_comb.items:
                if comb_item.title == item.title:
                    self.category_comb.set_select_index(comb_item_value_to_index(comb_item.item_value))

    def on_treeview_double_click_item(self, widget, item, column, x, y):
        if item.is_parent:
            if item.is_expand:
                item.unexpand()
            else:
                item.expand()

    def on_treeview_right_press_items(self, widget, root_x, root_y, current_item, select_items):
        '''
        docs
        '''
        self.treeview.set_highlight_item(current_item)
        if not current_item.is_parent:
            def on_add_to_bl():
                blacklist.add(current_item.title)
                current_item.is_in_blacklist = True
                current_item.emit_redraw_request()
            def on_remove_from_bl():
                blacklist.remove(current_item.title)
                current_item.is_in_blacklist = False
                current_item.emit_redraw_request()

            menu_items = []
            if current_item.title in blacklist.bl:
                menu_items.append((None, _("Remove from Blacklist"), on_remove_from_bl))
            else:
                menu_items.append((None, _("Add to Blacklist"), on_add_to_bl))

            Menu(menu_items, True).show((int(root_x), int(root_y)))

    def add_treeview(self):
        categories = self.classified_items.keys()
        # root eles
        self.root_ele_software = TreeViewItem(_("Software Messages"), True)
        self.root_ele_system = TreeViewItem(_("System Messages"), True)
        self.treeview = TreeView([self.root_ele_software, self.root_ele_system], expand_column=0)

        # add child items , CAN'T add_child_items before treeview constructed
        software_children = []
        system_children = []
        for category in categories:
            treeview_item = TreeViewItem(category)
            if category in blacklist.bl:
                treeview_item.is_in_blacklist = True

            if category in SYSTEM_SOFTWARE_LIST:
                system_children.append(treeview_item)
            else:
                software_children.append(treeview_item)

        self.root_ele_software.add_child_items(software_children)
        self.root_ele_system.add_child_items(system_children)
        self.treeview.draw_mask = self.on_treeview_draw_mask

        if len(software_children):
            self.treeview.set_highlight_item(software_children[0])
        elif len(system_children):
            self.treeview.set_highlight_item(system_children[0])
            
        self.treeview.set_size_request(220, -1)
        self.treeview.connect("single-click-item", self.on_treeview_click_item)
        self.treeview.connect("right-press-items", self.on_treeview_right_press_items)
        self.treeview.connect("double-click-item", self.on_treeview_double_click_item)

        container_remove_all(self.treeview_box)
        self.treeview_box.pack_start(self.treeview, True, True)
        self.treeview_box.show_all()
        
    def treeview_add_item(self, item):
        if item in SYSTEM_SOFTWARE_LIST:
            self.root_ele_system.add_child_items([TreeViewItem(item)])
        else:
            self.root_ele_software.add_child_items([TreeViewItem(item)])
        self.treeview_box.show_all()

    def add_listview(self, items):
        container_remove_all(self.listview_box)

        if len(items) != 0:
            self.factory = ListviewFactory(items, "detail")
            self.listview = self.factory.listview

            self.listview_box.pack_start(self.listview)
        else:
            empty_box_align = gtk.Alignment(0.5, 0.5, 0, 0)
            empty_box_align.add(Label("(Empty)"))
            self.listview_box.pack_start(empty_box_align)

        self.listview_box.show_all()

    def get_items_from_treeview_highlight(self):
        '''
        docs
        '''
        app_name = self.treeview.get_highlight_item().get_title()
        return self.classified_items[app_name]

    def add_titlebar(self,
                     button_mask=["min", "max", "close"],
                     icon_path=app_theme.get_theme_file_path("image/icon_little.png"),
                     app_name=_("Message Manager"),
                     title=None,
                     add_separator=False,
                     show_title=True,
                     enable_gaussian=True,
                     ):

        # Init titlebar.
        self.titlebar = Titlebar(button_mask,
                                 icon_path,
                                 app_name,
                                 title,
                                 add_separator,
                                 show_title=show_title,
                                 enable_gaussian=enable_gaussian,
                                 )

        self.titlebar.max_button.connect("clicked", lambda w: self.toggle_max_window())
        self.titlebar.min_button.connect("clicked", self.close_callback)
        self.titlebar.close_button.connect("clicked", self.close_callback)

        if self.resizable:
            self.add_toggle_event(self.titlebar)
        self.add_move_event(self.titlebar)

        self.titlebar_box.add(self.titlebar)


    def add_toolbar(self):

        toolbar_btn_box = gtk.HBox()
        toolbar_btn_box_align = gtk.Alignment(0.5, 0.5, 0, 0)

        import_btn = ToolbarItem(self.import_btn_pixbuf, _("Import"))
        import_btn.connect("clicked", self.on_toolbar_import_clicked)
        export_btn = ToolbarItem(self.export_btn_pixbuf, _("Export"))
        export_btn.connect("clicked", self.on_toolbar_export_clicked)
        delete_btn = ToolbarItem(self.delete_btn_pixbuf, _("Delete"))
        delete_btn.connect("clicked", self.on_toolbar_delete_clicked)
        refresh_btn = ToolbarItem(self.refresh_btn_pixbuf, _("Refresh"))
        refresh_btn.connect("clicked", self.on_toolbar_refresh_clicked)

        toolbar_btn_box.pack_start(import_btn, False, False, 2)
        toolbar_btn_box.pack_start(export_btn, False, False, 2)
        toolbar_btn_box.pack_start(delete_btn, False, False, 2)
        toolbar_btn_box.pack_start(refresh_btn, False, False, 2)
        toolbar_btn_box_align.add(toolbar_btn_box)

        look_in_Label = Label(
            _("Look up in"),
            text_color=ui_theme.get_color("title_text"),
            )

        self.category_comb = ComboBox([(_("All"), 0)])
        self.category_comb.add_items([(item, index) for index, item in enumerate(self.classified_items)], clear_first=False)
        self.time_comb = ComboBox([(_("Today"), 0),
                                   (_("Last week"), 1),
                                   (_("Last month"), 2),
                                   (_("Last three months"), 3),
                                   (_("Last year"), 4),
                                   (_("All"), 5)
                                   ])

        self.category_comb.set_size_request(-1, TOOLBAR_ENTRY_HEIGHT)
        self.category_comb.connect("item-selected", self.on_category_comb_item_selected)
        self.time_comb.set_size_request(-1, TOOLBAR_ENTRY_HEIGHT)
        self.time_comb.connect("item-selected", self.on_time_comb_item_selected)
        combos_box = gtk.HBox()
        combos_box.pack_start(self.category_comb, False, False, 5)
        combos_box.pack_start(self.time_comb, False, False)

        combos_box_align = gtk.Alignment(0.5, 0.5, 1, 1)
        padding_height = (TOOLBAR_HEIGHT - TOOLBAR_ENTRY_HEIGHT) / 2
        combos_box_align.set_padding(padding_height, padding_height, 5, 5)
        combos_box_align.add(combos_box)


        find_content_Label = Label(
            _("Find in content"),
            text_color=ui_theme.get_color("title_text"),
            )


        search_entry = SearchEntry()
        search_entry.connect("action-active", self.on_search_entry_action_active)
        search_entry_align = gtk.Alignment(0.5, 0.5, 1, 1)
        search_entry_align.set_padding(padding_height, padding_height, 5, 5)
        search_entry_align.add(search_entry)

        #Align left
        self.toolbar_box.pack_start(toolbar_btn_box_align, False, False, 5)

        #Align right
        self.toolbar_box.pack_end(search_entry_align, False, True, 5)
        self.toolbar_box.pack_end(find_content_Label, False, False, 5)
        self.toolbar_box.pack_end(combos_box_align, False, False, 0)
        self.toolbar_box.pack_end(look_in_Label, False, False, 5)
        self.toolbar_box.pack_end(ToolbarSep(), False, False, 5)


    def on_category_comb_item_selected(self, widget, item_title, item_value, item_index):
        if item_title != "All":
            for item in self.treeview.get_items():
                if item.title == item_title:
                    self.treeview.set_highlight_item(item)
                    self.current_showed_items = self.get_items_from_treeview_highlight()
                    self.add_listview(self.current_showed_items)
                    break


    def on_time_comb_item_selected(self, widget, item_title, item_value, item_index):
        if item_value != 5:
            filtrated_result = []
            for item in self.current_showed_items:
                item_datetime = datetime.strptime(item[TIME], "%Y/%m/%d-%H:%M:%S")
                if datetime.today() - item_datetime < timedelta_dict[item_value]:
                    filtrated_result.append(item)
            self.current_showed_items = filtrated_result
            self.add_listview(filtrated_result)


    def get_search_result_iter(self, search_str):
        filter_keywords = search_str.split()

        for item in self.current_showed_items:
            item_message = item[MESSAGE]
            for keyword in filter_keywords:
                # print "from %s search %s result %s:" % (item_message.body, keyword, item_message.body.find(keyword) != -1)
                if item_message.body.find(keyword) != -1:
                    yield item
                    continue

    def on_search_entry_action_active(self, widget, text):
        search_result_iter = self.get_search_result_iter(text)

        self.add_listview(list(search_result_iter))

    def on_toolbar_import_clicked(self, widget):
        self.filename_to_import = ""

        def ok_clicked(filename):
            self.filename_to_import = filename

        OpenFileDialog(_("Select File to Import"), self, ok_clicked, None)

        if len(self.filename_to_import) != 0:
            try:
                def import_db_func():
                    db.import_db(self.filename_to_import)
                    self.refresh_view()
                threading.Thread(target=import_db_func).start()
            except Exception, e:
                pass
Example #12
0
class EqualizerWindow(DialogBox):
    def __init__(self):
        super(EqualizerWindow, self).__init__(_("Equalizer"),
                                              372,
                                              168,
                                              DIALOG_MASK_SINGLE_PAGE,
                                              close_callback=self.hide_all,
                                              modal=False,
                                              window_hint=None,
                                              skip_taskbar_hint=False)

        self.manual_flag = False

        try:
            pre_value = float(config.get("equalizer", "preamp"))
        except:
            pre_value = 0.6

        pre_adjust = gtk.Adjustment(value=pre_value,
                                    lower=-10,
                                    upper=10,
                                    step_incr=0.1,
                                    page_incr=1,
                                    page_size=0)
        self.preamp_scale = PreampScalebar()
        self.preamp_scale.scalebar.set_adjustment(pre_adjust)
        pre_adjust.connect("value-changed", self.preamp_change)

        self.connect("configure-event", self.equalizer_configure_event)
        control_box = gtk.HBox(spacing=10)
        control_box.pack_start(self.preamp_scale, False, False)
        self.__scales = {}

        for i, label in enumerate(
            ["32", "64", "125", "250", "500", "1k", "2k", "4k", "8k", "16k"]):
            slipper_scale = SlipperScalebar(label)
            try:
                value = float(
                    config.get("equalizer", "equalizer-band%s" % str(i)))
            except:
                value = 0.0

            adjust = gtk.Adjustment(value=value,
                                    lower=-12,
                                    upper=12,
                                    step_incr=0.1,
                                    page_incr=1,
                                    page_size=0)
            adjust.changed_id = adjust.connect("value-changed",
                                               self.__on_adjust_change, i)
            slipper_scale.scalebar.set_adjustment(adjust)
            self.__scales[i] = slipper_scale.scalebar
            control_box.pack_start(slipper_scale, False, False)

        try:
            self.__equalizer = gst.element_factory_make("equalizer-10bands")
        except gst.PluginNotFoundError:
            self.__equalizer = None
            self.logerror(
                "Equalizer support requires gstreamer-plugins-bad (>= 0.10.5)")
        else:
            Player.bin.xfade_add_filter(self.__equalizer)
            for i in range(0, 10):
                try:
                    value = float(
                        config.get("equalizer", "equalizer-band%s" % str(i)))
                except:
                    value = 0

                self.__equalizer.set_property("band" + str(i), float(value))

            Player.bin.connect("tee-removed", self.__on_remove)
            config.connect("config-changed", self.__on_config_change)

        self.active_button = Button(_("Close"))
        self.active_button.connect("clicked", self.hide_win)
        self.reset_button = Button(_("Reset"))
        self.reset_button.connect("clicked", self.set_default_value)
        self.predefine_button = Button(_("Predefined"))
        self.predefine_button.connect("clicked", self.show_predefine)

        self.predefine_combo_box = ComboBox(
            [(value, key) for key, value in mandatory_i18n.items()],
            250,
            select_index=self.get_selected_index())
        self.predefine_combo_box.connect("item-selected",
                                         self.set_predefine_value)

        control_box_align = gtk.Alignment()
        control_box_align.set(0.0, 0.0, 1.0, 1.0)
        control_box_align.set_padding(10, 20, 15, 15)
        control_box_align.add(control_box)

        main_align = gtk.Alignment()
        main_align.set(0.0, 0.0, 1.0, 1.0)
        main_align.set_padding(0, 5, 2, 2)
        main_box = gtk.VBox(spacing=5)
        main_align.add(main_box)

        main_box.add(control_box_align)

        self.body_box.pack_start(main_align, True, True)
        self.left_button_box.set_buttons([self.predefine_combo_box])
        self.right_button_box.set_buttons(
            [self.reset_button, self.active_button])

    def set_default_value(self, widget):
        self.predefine_combo_box.set_select_index(1)
        self.__change("Default")
        self.preamp_scale.scalebar.set_value(0.6)

    def db_to_percent(self, dB):
        return 10**(dB / 10)

    def preamp_change(self, adjust):

        config.set("equalizer", "preamp", str(adjust.get_value()))
        Player.volume = self.db_to_percent(adjust.get_value())

    def __on_remove(self, bin, tee, element):
        if element != self.__equalizer:
            return
        self.__equalizer.set_state(gst.STATE_NULL)
        self.__equalizer = None

    def __on_config_change(self, dispacher, section, option, value):
        if section == "equalizer" and option.find("equalizer-band") == 0:
            band_name = option.replace("equalizer-", "")
            self.__equalizer.set_property(band_name, float(value))

    def equalizer_configure_event(self, widget, event):
        if widget.get_property("visible"):
            if widget.get_resizable():
                config.set("equalizer", "width", "%d" % event.width)
                config.set("equalizer", "height", "%d" % event.height)
            config.set("equalizer", "x", "%d" % event.x)
            config.set("equalizer", "y", "%d" % event.y)

    def hide_win(self, widget):
        self.hide_all()

    def __select_name(self):
        self.menu_dict = OrderedDict()
        for name in MANDATORY.keys():
            self.menu_dict[name] = [None, name, self.__change, name]

        values = []
        for i in range(0, 10):
            try:
                value = int(
                    float(config.get("equalizer",
                                     "equalizer-band%s" % str(i))))
            except:
                value = 0
            values.append(str(value))
        values = ":".join(values)

        self.has_tick = False
        for name, value in MANDATORY.iteritems():
            value = value.split(":")
            value = ":".join([str(int(float(v))) for v in value])

            if value == values:
                self.menu_dict[name][0] = (
                    app_theme.get_pixbuf("menu/tick.png"),
                    app_theme.get_pixbuf("menu/tick_press.png"))
                self.has_tick = True
        if not self.has_tick:
            self.menu_dict[MANDATORY_CUSTOM][0] = (
                app_theme.get_pixbuf("menu/tick.png"),
                app_theme.get_pixbuf("menu/tick_press.png"))

    def get_selected_index(self):
        values = []
        for i in range(0, 10):
            try:
                value = int(
                    float(config.get("equalizer",
                                     "equalizer-band%s" % str(i))))
            except:
                value = 0
            values.append(str(value))
        values = ":".join(values)

        for index, value in enumerate(MANDATORY.values()):
            value = value.split(":")
            value = ":".join([str(int(float(v))) for v in value])

            if value == values:
                return index
        return 0

    def set_predefine_value(self, widget, label, allocated_data, index):
        self.__change(allocated_data)

    def show_predefine(self, widget):
        self.__select_name()
        menu_items = self.menu_dict.values()
        menu_items.insert(2, None)
        Menu(menu_items, True).show(get_widget_root_coordinate(widget))

    def __on_adjust_change(self, adjust, i):
        if not self.manual_flag:
            self.predefine_combo_box.set_select_index(0)
        config.set("equalizer", "equalizer-band%s" % str(i),
                   str(adjust.get_value()))
        self.manual_flag = False

    def __save(self, *args):
        text = self.predefine_button.get_label()

        if text in MANDATORY.keys():
            return
        values = []
        for i in range(0, 10):
            try:
                value = float(
                    config.get("equalizer", "equalizer-band%s" % str(i)))
            except:
                value = 0.0
            values.append(str(value))

    def __change(self, name):
        if name == MANDATORY_CUSTOM:
            self.predefine_combo_box.set_select_index(0)
            return True

        self.manual_flag = True
        if name in MANDATORY.keys():
            values = MANDATORY[name].split(":")

            for i, value in enumerate(values):
                adj = self.__scales[i].get_adjustment()
                adj.handler_block(adj.changed_id)
                self.__scales[i].set_value(float(value))
                config.set("equalizer", "equalizer-band%s" % str(i),
                           str(float(value)))
                adj.handler_unblock(adj.changed_id)
        return True

    def run(self):
        if config.get("equalizer", "x") == "-1":
            self.set_position(gtk.WIN_POS_CENTER)
        else:
            self.move(int(config.get("equalizer", "x")),
                      int(config.get("equalizer", "y")))
        self.show_all()
class DatetimeView(gtk.HBox):
    '''
    class docs
    '''
	
    def __init__(self):
        '''
        init docs
        '''
        gtk.HBox.__init__(self)

        self.__toggle_id = None
        self.__time_id = None

        self.datetime_settings = deepin_gsettings.new("com.deepin.dde.datetime")

        self.__deepin_dt = DeepinDateTime()
        self.current_tz_gmtoff = self.__deepin_dt.get_gmtoff()

        self.timezone_items = []
        self.timezone_items.append((_("(UTC-11:00)Samoa"), -11))
        self.timezone_items.append((_("(UTC-10:00)Hawaii"), -10))
        self.timezone_items.append((_("(UTC-09:00)Alaska"), -9))
        self.timezone_items.append((_("(UTC-08:00)Lower California"), -8))
        self.timezone_items.append((_("(UTC-07:00)Arizona, Llamas, Mazatlan, Chihuahua"), -7))
        self.timezone_items.append((_("(UTC-06:00)Saskatchewan, Mexico City, Monterrey"), -6))
        self.timezone_items.append((_("(UTC-05:00)Indiana, Bogota, Lima, Quito"), -5))
        self.timezone_items.append((_("(UTC-04:00)San Diego, Georgetown, San Juan"), -4))
        self.timezone_items.append((_("(UTC-03:00)Greenland, Brasilia, Fortaleza"), -3))
        self.timezone_items.append((_("(UTC-02:00)Mid-Atlantic"), -2))
        self.timezone_items.append((_("(UTC-01:00)Cape Verde Islands, Azores"), -1))
        self.timezone_items.append((_("(UTC)London, Dublin, Edinburgh, Lisbon, Casablanca"), 0))
        self.timezone_items.append((_("(UTC+01:00)Paris, Amsterdam, Berlin, Rome, Vienna"), 1))
        self.timezone_items.append((_("(UTC+02:00)Cairo, Athens, Istanbul, Jerusalem"), 2))
        self.timezone_items.append((_("(UTC+03:00)Moscow, St. Petersburg, Baghdad"), 3))
        self.timezone_items.append((_("(UTC+04:00)Port Louis, Abu Dhabi, Muscat, Yerevan"), 4))
        self.timezone_items.append((_("(UTC+05:00)Islamabad, Karachi, Tashkent"), 5))
        self.timezone_items.append((_("(UTC+06:00)Dhaka, Novosibirsk"), 6))
        self.timezone_items.append((_("(UTC+07:00)Bangkok, Hanoi, Jakarta"), 7))
        self.timezone_items.append((_("(UTC+08:00)Beijing, Chongqing, HongKong, Taipei, Urumqi"), 8))
        self.timezone_items.append((_("(UTC+09:00)Osaka, Sapporo, Tokyo, Seoul"), 9))
        self.timezone_items.append((_("(UTC+10:00)Guam, Canberra, Melbourne, Sydney"), 10))
        self.timezone_items.append((_("(UTC+11:00)Magadan, Solomon Islands"), 11))
        self.timezone_items.append((_("(UTC+12:00)New Zealand, Kiribati"), 12))
        self.is_24hour = self.datetime_settings.get_boolean("is-24hour")
        '''
        left align
        '''
        self.left_align = self.__setup_align(
            padding_top = TEXT_WINDOW_TOP_PADDING, 
            padding_left = TEXT_WINDOW_LEFT_PADDING)
        '''
        left box
        '''
        self.left_box = gtk.VBox()
        '''
        calendar title
        '''
        self.calendar_title_align = self.__setup_title_align(
            app_theme.get_pixbuf("datetime/calendar.png"), _("Calendar"))
        '''
        current date
        '''
        self.cur_date_align = self.__setup_align()
        self.cur_date_label = self.__setup_label(
            _("Current Date: %d-%d-%d") % (time.localtime().tm_year, 
                                           time.localtime().tm_mon, 
                                           time.localtime().tm_mday), 
            190)
        self.cur_date_align.add(self.cur_date_label)
        '''
        calendar widget
        '''
        self.calendar_align = self.__setup_align(padding_top = BETWEEN_SPACING, 
            padding_bottom = 10)
        self.calendar = deepin_lunar.new()
        if MAIN_LANG == "en_US":
            self.calendar = dltk_calendar.new()
        self.calendar.mark_day(time.localtime().tm_mday)
        self.calendar.get_handle().set_size_request(300, 280)
        self.calendar.get_handle().connect("day-selected", self.__on_day_selected, self.calendar)
        self.calendar_align.add(self.calendar.get_handle())
        self.change_date_box = gtk.HBox(spacing = 5)
        self.change_date_box.set_size_request(300, -1)
        self.change_date_align = self.__setup_align()
        self.change_date_button = Button(_("Change Date"))
        self.change_date_button.connect("button-press-event", self.__on_change_date)
        self.change_date_align.add(self.change_date_button)
        self.edit_date_align = self.__setup_align()
        self.edit_date_box = gtk.HBox(spacing = 5)
        self.cancel_date_button = Button(_("Cancel"))
        self.cancel_date_button.connect("button-press-event", self.__on_cancel_change_date)
        self.confirm_date_button = Button(_("Confirm"))
        self.confirm_date_button.connect("button-press-event", self.__on_confirm_change_date)
        self.__widget_pack_start(self.edit_date_box, 
            [self.cancel_date_button, self.confirm_date_button])
        self.edit_date_align.add(self.edit_date_box)

        self.change_date_box.pack_end(self.change_date_align, False, False)
        '''
        left box && align
        '''
        self.__widget_pack_start(self.left_box, 
            [self.calendar_title_align, 
             self.cur_date_align, 
             self.calendar_align, 
             self.change_date_box])
        self.left_align.add(self.left_box)
        '''
        right align
        '''
        self.right_align = self.__setup_align(
            padding_top = TEXT_WINDOW_TOP_PADDING, padding_left = TEXT_WINDOW_LEFT_PADDING)
        '''
        right box
        '''
        self.right_box = gtk.VBox()
        '''
        time title
        '''
        self.time_title_align = self.__setup_title_align(
            app_theme.get_pixbuf("datetime/time.png"), _("Time"))
        '''
        current time
        '''
        self.cur_time_align = self.__setup_align()
        if self.is_24hour:
            self.cur_time_label = self.__setup_label(
                _("Current Time: %s %02d:%02d:%02d (%d Hour)") % 
                  (time.strftime('%p'), 
                   time.localtime().tm_hour, 
                   time.localtime().tm_min, 
                   time.localtime().tm_sec, 
                   24), 
                260)
        else:
            self.cur_time_label = self.__setup_label(                           
                _("Current Time: %s %02d:%02d:%02d (%d Hour)") %                
                  (time.strftime('%p'),                                         
                   time.localtime().tm_hour,                                    
                   time.localtime().tm_min,                                     
                   time.localtime().tm_sec,                                     
                   12),                                                         
                260)     

        self.cur_time_align.add(self.cur_time_label)
        '''
        DateTime widget
        '''
        self.datetime_widget_align = self.__setup_align(padding_top = BETWEEN_SPACING)
        self.datetime_widget = DateTimeHTCStyle(is_24hour = self.is_24hour)
        self.datetime_widget_align.add(self.datetime_widget)
        self.set_time_align = self.__setup_align()
        '''
        auto time get && set
        '''
        self.auto_time_align = self.__setup_align(padding_top = TEXT_WINDOW_TOP_PADDING)
        self.auto_time_box = gtk.HBox(spacing = BETWEEN_SPACING)
        self.auto_time_label = self.__setup_label(_("NTP"))
        self.auto_time_toggle = self.__setup_toggle()
        is_auto_set_time = self.datetime_settings.get_boolean("is-auto-set")
        if is_auto_set_time:
            #AutoSetTimeThread(self).start()
            self.__deepin_dt.set_using_ntp(True)
        else:
            self.__deepin_dt.set_using_ntp(False)
        self.auto_time_toggle_align = self.__setup_align(padding_top = 4)
        self.auto_time_toggle.set_active(is_auto_set_time)
        self.auto_time_toggle.connect("toggled", self.__toggled, "auto_time_toggle")
        self.auto_time_toggle_align.add(self.auto_time_toggle)
        '''
        set time
        '''
        self.set_time_spin_align = self.__setup_align(padding_left = 10, padding_top = 1)
        self.set_time_box = gtk.HBox(spacing = BETWEEN_SPACING)
        self.set_time_label = self.__setup_label(_("Set Time"), 60)
        self.set_time_spin = TimeSpinBox(is_24hour = self.is_24hour)                 
        self.set_time_spin.set_size_request(85, WIDGET_HEIGHT)                               
        self.set_time_spin.connect("value-changed", self.__time_changed)
        self.__widget_pack_start(self.set_time_box, 
            [self.set_time_label, self.set_time_spin])
        self.set_time_spin_align.add(self.set_time_box)
        self.__widget_pack_start(self.auto_time_box, 
                                 [
                                  self.auto_time_label, 
                                  self.auto_time_toggle_align, 
                                  self.set_time_spin_align]) 
        if is_auto_set_time:
            self.set_time_spin_align.set_child_visible(False)
        self.auto_time_align.add(self.auto_time_box)
        '''
        24hour display
        '''
        self.time_display_align = self.__setup_align(padding_top = BETWEEN_SPACING)
        self.time_display_box = gtk.HBox(spacing = BETWEEN_SPACING)
        self.time_display_label = self.__setup_label("24 %s" % _("Hour"))
        self.time_display_toggle_align = self.__setup_align()
        self.time_display_toggle = self.__setup_toggle()                        
        self.time_display_toggle.set_active(self.is_24hour)                          
        self.time_display_toggle.connect("toggled", self.__toggled, "time_display_toggle")
        self.time_display_toggle_align.add(self.time_display_toggle)
        self.__widget_pack_start(self.time_display_box, 
            [self.time_display_label, self.time_display_toggle_align])
        self.time_display_align.add(self.time_display_box)
        '''
        timezone
        '''
        self.timezone_title_align = self.__setup_title_align(
            app_theme.get_pixbuf("datetime/globe-green.png"), 
            _("Time Zone"), 
            TEXT_WINDOW_TOP_PADDING)
        self.timezone_combo_align = self.__setup_align(padding_top = 6)
        self.timezone_combo = ComboBox(self.timezone_items, max_width = 340, fixed_width = 340)
        self.timezone_combo.set_select_index(self.__deepin_dt.get_gmtoff() + 11)
        self.timezone_combo.connect("item-selected", self.__combo_item_selected)
        self.timezone_combo_align.add(self.timezone_combo)

        self.__widget_pack_start(self.right_box, 
                                 [self.time_title_align, 
                                  self.cur_time_align, 
                                  self.datetime_widget_align, 
                                  self.auto_time_align, 
                                  self.time_display_align, 
                                  self.timezone_title_align, 
                                  self.timezone_combo_align])
        self.right_align.add(self.right_box)
       
        self.__widget_pack_start(self, [self.left_align, self.right_align])

        self.connect("expose-event", self.__expose)

        self.__send_message("status", ("date_time", ""))

        SecondThread(self).start()
        DateThread(self).start()

    def show_again(self):                                                       
        self.__send_message("status", ("date_time", ""))

    def reset(self):
        self.__send_message("status", ("date_time", _("Reset to default value")))
        
        self.datetime_settings.reset("is-24hour")
        #self.datetime_settings.reset("is-auto-set")
        
        self.is_24hour = self.datetime_settings.get_boolean("is-24hour")
        self.time_display_toggle.set_active(self.is_24hour)
        self.datetime_widget.set_is_24hour(self.is_24hour)                  
        self.set_time_spin.set_24hour(self.is_24hour)
        
        is_auto_set_time = self.datetime_settings.get_boolean("is-auto-set")
        self.auto_time_toggle.set_active(is_auto_set_time)
        if is_auto_set_time:
            self.set_time_spin_align.set_child_visible(False)               
            self.__deepin_dt.set_using_ntp(True)
        else:
            self.set_time_spin_align.set_child_visible(True)
            self.__deepin_dt.set_using_ntp(False)

    def __handle_dbus_replay(self, *reply):                                     
        pass                                                                    
                                                                                
    def __handle_dbus_error(self, *error):                                      
        pass                                                                    
                                                                                
    def __send_message(self, message_type, message_content):                    
        if is_dbus_name_exists(APP_DBUS_NAME):                                  
            bus_object = dbus.SessionBus().get_object(APP_DBUS_NAME, APP_OBJECT_NAME)
            method = bus_object.get_dbus_method("message_receiver")             
            method(message_type,                                                
                   message_content,                                             
                   reply_handler=self.__handle_dbus_replay,                     
                   error_handler=self.__handle_dbus_error)      

    def set_cur_date(self):
        year = time.localtime().tm_year
        month = time.localtime().tm_mon
        day = time.localtime().tm_mday
        self.cur_date_label.set_text(_("Current Date: %d-%d-%d") % (year, month, day))
        self.calendar.clear_marks()
        self.calendar.select_day(day)

    def set_cur_time_label(self):
        is_24hour = 24
        hour_value = time.localtime().tm_hour
        am_pm = ""

        if not self.is_24hour: 
            am_pm = time.strftime('%p')
            is_24hour = 12
            if hour_value > 12:
                hour_value -= 12
        
        self.cur_time_label.set_text(                           
             _("Current Time: %s %02d:%02d:%02d (%d Hour)") %                
               (am_pm,                                         
                hour_value,                                    
                time.localtime().tm_min,                                     
                time.localtime().tm_sec,                                     
                is_24hour))     
  
    def __on_day_selected(self, object, widget):
        pass

    def __on_change_date(self, widget, event):
        #self.edit_date_align.set_padding(0, 0 , 195, 0)
        #self.change_date_align.set_padding(0, 0, -100, 0)
        #self.edit_date_align.set_child_visible(True)
        #self.change_date_align.set_child_visible(False)
        self.change_date_box.remove(self.change_date_align)
        self.change_date_box.pack_end(self.edit_date_align, False, False)
        self.calendar.clear_marks()
        self.show_all()

    def __hide_edit_date(self):
        #self.edit_date_align.set_padding(0, 0, 110, 0)                          
        #self.change_date_align.set_padding(0, 0, 0, 0)                          
        #self.edit_date_align.set_child_visible(False)                           
        #self.change_date_align.set_child_visible(True) 
        self.change_date_box.remove(self.edit_date_align)
        self.change_date_box.pack_end(self.change_date_align, False, False)
        self.show_all()

    def __on_cancel_change_date(self, widget, event):
        self.__hide_edit_date()

    def __on_confirm_change_date(self, widget, event):
        year, month, day = self.calendar.get_date()
        self.__send_message("status", ("date_time", _("Changed date to %d-%d-%d") % (year, month, day)))
        self.__hide_edit_date()
        self.cur_date_label.set_text(_("Current Date: %d-%d-%d") % (year, month, day))
        self.calendar.mark_day(day)
        self.auto_time_toggle.set_active(False)
        self.__set_using_ntp(False)
        SetDateThread(self.__deepin_dt, day, month, year).start()

    def __setup_separator(self):                                                
        hseparator = HSeparator(app_theme.get_shadow_color("hSeparator").get_color_info(), 0, 0)
        hseparator.set_size_request(300, HSEPARATOR_HEIGHT)                                    
        return hseparator                                                       
                                                                                
    def __setup_title_label(self,                                               
                            text="",                                            
                            text_color=app_theme.get_color("globalTitleForeground"),
                            text_size=TITLE_FONT_SIZE,                          
                            text_x_align=ALIGN_START,                           
                            label_width=180):                                   
        return Label(text = text,                                               
                     text_color = text_color,                                   
                     text_size = text_size,                                     
                     text_x_align = text_x_align,                               
                     label_width = label_width, 
                     enable_select = False, 
                     enable_double_click = False)     
    
    def __setup_title_align(self,                                                  
                            pixbuf,                                                
                            text,                                                  
                            padding_top=0,                         
                            padding_left=0):                
        align = self.__setup_align(padding_top = padding_top, padding_left = padding_left)            
        align_box = gtk.VBox(spacing = WIDGET_SPACING)                             
        title_box = gtk.HBox(spacing = WIDGET_SPACING)                             
        image = ImageBox(pixbuf)                                                   
        label = self.__setup_title_label(text)                                     
        separator = self.__setup_separator()                                       
        self.__widget_pack_start(title_box, [image, label])                        
        self.__widget_pack_start(align_box, [title_box, separator])                
        align.add(align_box)                                                    
        return align    
    
    def __set_using_ntp(self, data=True):
        self.__deepin_dt.set_using_ntp(data)

    def __toggled(self, widget, argv):
        if argv == "auto_time_toggle":
            is_auto_set_time = widget.get_active()
            self.datetime_settings.set_boolean("is-auto-set", is_auto_set_time)
            if is_auto_set_time:
                self.__send_message("status", ("date_time", _("Time will be synchronized with an Internet time server")))
                self.set_time_spin_align.set_child_visible(False)
                gobject.timeout_add_seconds(3, self.__set_using_ntp, True)
            else:
                self.__send_message("status", ("date_time", _("Time will not be synchronized with an Internet time server")))
                self.set_time_spin_align.set_child_visible(True)
                if self.__toggle_id:
                    gobject.source_remove(self.__toggle_id)
                self.__toggle_id = gobject.timeout_add_seconds(3, self.__set_using_ntp, False)
            return

        if argv == "time_display_toggle":
            self.is_24hour = widget.get_active()
            if self.is_24hour:
                self.__send_message("status", ("date_time", _("Time will be shown in 24 hour format")))
            else:
                self.__send_message("status", ("date_time", _("Time will be shown in 12 hour format")))
            self.datetime_settings.set_boolean("is-24hour", self.is_24hour)
            self.datetime_widget.set_is_24hour(self.is_24hour)
            self.set_time_spin.set_24hour(self.is_24hour)

    def auto_set_time(self):
        self.__deepin_dt.set_using_ntp(True)

    def __set_time(self, hour, min, sec):
        self.__deepin_dt.set_time_by_hms(hour, min, sec)
    
    def __time_changed(self, widget, hour, min, sec):
        self.__send_message("status", ("date_time", _("Changed time to %02d:%02d:%02d") % (hour, min, sec)))
   
        if self.__time_id:
            gobject.source_remove(self.__time_id)
        self.__time_id = gobject.timeout_add_seconds(1, self.__set_time, hour, min, sec)

    def __expose(self, widget, event):
        cr = widget.window.cairo_create()                                       
        rect = widget.allocation                                                
                                                                                
        cr.set_source_rgb(*color_hex_to_cairo(MODULE_BG_COLOR))                     
        cr.rectangle(rect.x, rect.y, rect.width, rect.height)                       
        cr.fill()        

    def __draw_title_background(self, cr, widget):                                           
        rect = widget.allocation                                    
        
        cr.set_source_rgb(*color_hex_to_cairo(MODULE_BG_COLOR))                 
        cr.rectangle(rect.x, 
                     rect.y - FRAME_TOP_PADDING, 
                     rect.width, 
                     rect.height - 1)                        
        cr.fill()
    
    def __combo_item_selected(self, widget, item_text=None, item_value=None, item_index=None):
        self.__send_message("status", ("date_time", _("Changed time zone to %s") % item_text))
        self.__deepin_dt.set_timezone_by_gmtoff(item_value)

    def __setup_label(self, text="", width=90, align=ALIGN_START):
        label = Label(text, None, CONTENT_FONT_SIZE, align, width, False, False, False)
        return label

    def __setup_toggle(self):
        toggle = ToggleButton(app_theme.get_pixbuf("toggle_button/inactive_normal.png"), 
            app_theme.get_pixbuf("toggle_button/active_normal.png"))
        return toggle

    def __setup_align(self, 
                      xalign=0, 
                      yalign=0, 
                      xscale=0, 
                      yscale=0, 
                      padding_top=0, 
                      padding_bottom=0, 
                      padding_left=0, 
                      padding_right=0):
        align = gtk.Alignment()
        align.set(xalign, yalign, xscale, yscale)
        align.set_padding(padding_top, padding_bottom, padding_left, padding_right)
        return align

    def __widget_pack_start(self, parent_widget, widgets=[], expand=False, fill=False):
        if parent_widget == None:
            return
        for item in widgets:
            parent_widget.pack_start(item, expand, fill)
Example #14
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))
Example #15
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()
    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 __init__(self, fixed_width, droplist_height=80):        # fixed_width=
     ComboBox.__init__(self, droplist_height=droplist_height, fixed_width=fixed_width)
     self.connect("item-selected", self.emit_connect_function)
     self.fixed_width = fixed_width
     self._items = []
     self.set_items = self.add_items
    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
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()
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))
    def __init__(self):
        '''
        init docs
        '''
        gtk.HBox.__init__(self)

        self.__toggle_id = None
        self.__time_id = None

        self.datetime_settings = deepin_gsettings.new(
            "com.deepin.dde.datetime")

        self.__deepin_dt = DeepinDateTime()
        self.current_tz_gmtoff = self.__deepin_dt.get_gmtoff()

        self.timezone_items = []
        self.timezone_items.append((_("(UTC-11:00)Samoa"), -11))
        self.timezone_items.append((_("(UTC-10:00)Hawaii"), -10))
        self.timezone_items.append((_("(UTC-09:00)Alaska"), -9))
        self.timezone_items.append((_("(UTC-08:00)Lower California"), -8))
        self.timezone_items.append(
            (_("(UTC-07:00)Arizona, Llamas, Mazatlan, Chihuahua"), -7))
        self.timezone_items.append(
            (_("(UTC-06:00)Saskatchewan, Mexico City, Monterrey"), -6))
        self.timezone_items.append(
            (_("(UTC-05:00)Indiana, Bogota, Lima, Quito"), -5))
        self.timezone_items.append(
            (_("(UTC-04:00)San Diego, Georgetown, San Juan"), -4))
        self.timezone_items.append(
            (_("(UTC-03:00)Greenland, Brasilia, Fortaleza"), -3))
        self.timezone_items.append((_("(UTC-02:00)Mid-Atlantic"), -2))
        self.timezone_items.append(
            (_("(UTC-01:00)Cape Verde Islands, Azores"), -1))
        self.timezone_items.append(
            (_("(UTC)London, Dublin, Edinburgh, Lisbon, Casablanca"), 0))
        self.timezone_items.append(
            (_("(UTC+01:00)Paris, Amsterdam, Berlin, Rome, Vienna"), 1))
        self.timezone_items.append(
            (_("(UTC+02:00)Cairo, Athens, Istanbul, Jerusalem"), 2))
        self.timezone_items.append(
            (_("(UTC+03:00)Moscow, St. Petersburg, Baghdad"), 3))
        self.timezone_items.append(
            (_("(UTC+04:00)Port Louis, Abu Dhabi, Muscat, Yerevan"), 4))
        self.timezone_items.append(
            (_("(UTC+05:00)Islamabad, Karachi, Tashkent"), 5))
        self.timezone_items.append((_("(UTC+06:00)Dhaka, Novosibirsk"), 6))
        self.timezone_items.append(
            (_("(UTC+07:00)Bangkok, Hanoi, Jakarta"), 7))
        self.timezone_items.append(
            (_("(UTC+08:00)Beijing, Chongqing, HongKong, Taipei, Urumqi"), 8))
        self.timezone_items.append(
            (_("(UTC+09:00)Osaka, Sapporo, Tokyo, Seoul"), 9))
        self.timezone_items.append(
            (_("(UTC+10:00)Guam, Canberra, Melbourne, Sydney"), 10))
        self.timezone_items.append(
            (_("(UTC+11:00)Magadan, Solomon Islands"), 11))
        self.timezone_items.append((_("(UTC+12:00)New Zealand, Kiribati"), 12))
        self.is_24hour = self.datetime_settings.get_boolean("is-24hour")
        '''
        left align
        '''
        self.left_align = self.__setup_align(
            padding_top=TEXT_WINDOW_TOP_PADDING,
            padding_left=TEXT_WINDOW_LEFT_PADDING)
        '''
        left box
        '''
        self.left_box = gtk.VBox()
        '''
        calendar title
        '''
        self.calendar_title_align = self.__setup_title_align(
            app_theme.get_pixbuf("datetime/calendar.png"), _("Calendar"))
        '''
        current date
        '''
        self.cur_date_align = self.__setup_align()
        self.cur_date_label = self.__setup_label(
            _("Current Date: %d-%d-%d") %
            (time.localtime().tm_year, time.localtime().tm_mon,
             time.localtime().tm_mday), 190)
        self.cur_date_align.add(self.cur_date_label)
        '''
        calendar widget
        '''
        self.calendar_align = self.__setup_align(padding_top=BETWEEN_SPACING,
                                                 padding_bottom=10)
        self.calendar = deepin_lunar.new()
        if MAIN_LANG == "en_US":
            self.calendar = dltk_calendar.new()
        self.calendar.mark_day(time.localtime().tm_mday)
        self.calendar.get_handle().set_size_request(300, 280)
        self.calendar.get_handle().connect("day-selected",
                                           self.__on_day_selected,
                                           self.calendar)
        self.calendar_align.add(self.calendar.get_handle())
        self.change_date_box = gtk.HBox(spacing=5)
        self.change_date_box.set_size_request(300, -1)
        self.change_date_align = self.__setup_align()
        self.change_date_button = Button(_("Change Date"))
        self.change_date_button.connect("button-press-event",
                                        self.__on_change_date)
        self.change_date_align.add(self.change_date_button)
        self.edit_date_align = self.__setup_align()
        self.edit_date_box = gtk.HBox(spacing=5)
        self.cancel_date_button = Button(_("Cancel"))
        self.cancel_date_button.connect("button-press-event",
                                        self.__on_cancel_change_date)
        self.confirm_date_button = Button(_("Confirm"))
        self.confirm_date_button.connect("button-press-event",
                                         self.__on_confirm_change_date)
        self.__widget_pack_start(
            self.edit_date_box,
            [self.cancel_date_button, self.confirm_date_button])
        self.edit_date_align.add(self.edit_date_box)

        self.change_date_box.pack_end(self.change_date_align, False, False)
        '''
        left box && align
        '''
        self.__widget_pack_start(self.left_box, [
            self.calendar_title_align, self.cur_date_align,
            self.calendar_align, self.change_date_box
        ])
        self.left_align.add(self.left_box)
        '''
        right align
        '''
        self.right_align = self.__setup_align(
            padding_top=TEXT_WINDOW_TOP_PADDING,
            padding_left=TEXT_WINDOW_LEFT_PADDING)
        '''
        right box
        '''
        self.right_box = gtk.VBox()
        '''
        time title
        '''
        self.time_title_align = self.__setup_title_align(
            app_theme.get_pixbuf("datetime/time.png"), _("Time"))
        '''
        current time
        '''
        self.cur_time_align = self.__setup_align()
        if self.is_24hour:
            self.cur_time_label = self.__setup_label(
                _("Current Time: %s %02d:%02d:%02d (%d Hour)") %
                (time.strftime('%p'), time.localtime().tm_hour,
                 time.localtime().tm_min, time.localtime().tm_sec, 24), 260)
        else:
            self.cur_time_label = self.__setup_label(
                _("Current Time: %s %02d:%02d:%02d (%d Hour)") %
                (time.strftime('%p'), time.localtime().tm_hour,
                 time.localtime().tm_min, time.localtime().tm_sec, 12), 260)

        self.cur_time_align.add(self.cur_time_label)
        '''
        DateTime widget
        '''
        self.datetime_widget_align = self.__setup_align(
            padding_top=BETWEEN_SPACING)
        self.datetime_widget = DateTimeHTCStyle(is_24hour=self.is_24hour)
        self.datetime_widget_align.add(self.datetime_widget)
        self.set_time_align = self.__setup_align()
        '''
        auto time get && set
        '''
        self.auto_time_align = self.__setup_align(
            padding_top=TEXT_WINDOW_TOP_PADDING)
        self.auto_time_box = gtk.HBox(spacing=BETWEEN_SPACING)
        self.auto_time_label = self.__setup_label(_("NTP"))
        self.auto_time_toggle = self.__setup_toggle()
        is_auto_set_time = self.datetime_settings.get_boolean("is-auto-set")
        if is_auto_set_time:
            #AutoSetTimeThread(self).start()
            self.__deepin_dt.set_using_ntp(True)
        else:
            self.__deepin_dt.set_using_ntp(False)
        self.auto_time_toggle_align = self.__setup_align(padding_top=4)
        self.auto_time_toggle.set_active(is_auto_set_time)
        self.auto_time_toggle.connect("toggled", self.__toggled,
                                      "auto_time_toggle")
        self.auto_time_toggle_align.add(self.auto_time_toggle)
        '''
        set time
        '''
        self.set_time_spin_align = self.__setup_align(padding_left=10,
                                                      padding_top=1)
        self.set_time_box = gtk.HBox(spacing=BETWEEN_SPACING)
        self.set_time_label = self.__setup_label(_("Set Time"), 60)
        self.set_time_spin = TimeSpinBox(is_24hour=self.is_24hour)
        self.set_time_spin.set_size_request(85, WIDGET_HEIGHT)
        self.set_time_spin.connect("value-changed", self.__time_changed)
        self.__widget_pack_start(self.set_time_box,
                                 [self.set_time_label, self.set_time_spin])
        self.set_time_spin_align.add(self.set_time_box)
        self.__widget_pack_start(self.auto_time_box, [
            self.auto_time_label, self.auto_time_toggle_align,
            self.set_time_spin_align
        ])
        if is_auto_set_time:
            self.set_time_spin_align.set_child_visible(False)
        self.auto_time_align.add(self.auto_time_box)
        '''
        24hour display
        '''
        self.time_display_align = self.__setup_align(
            padding_top=BETWEEN_SPACING)
        self.time_display_box = gtk.HBox(spacing=BETWEEN_SPACING)
        self.time_display_label = self.__setup_label("24 %s" % _("Hour"))
        self.time_display_toggle_align = self.__setup_align()
        self.time_display_toggle = self.__setup_toggle()
        self.time_display_toggle.set_active(self.is_24hour)
        self.time_display_toggle.connect("toggled", self.__toggled,
                                         "time_display_toggle")
        self.time_display_toggle_align.add(self.time_display_toggle)
        self.__widget_pack_start(
            self.time_display_box,
            [self.time_display_label, self.time_display_toggle_align])
        self.time_display_align.add(self.time_display_box)
        '''
        timezone
        '''
        self.timezone_title_align = self.__setup_title_align(
            app_theme.get_pixbuf("datetime/globe-green.png"), _("Time Zone"),
            TEXT_WINDOW_TOP_PADDING)
        self.timezone_combo_align = self.__setup_align(padding_top=6)
        self.timezone_combo = ComboBox(self.timezone_items,
                                       max_width=340,
                                       fixed_width=340)
        self.timezone_combo.set_select_index(self.__deepin_dt.get_gmtoff() +
                                             11)
        self.timezone_combo.connect("item-selected",
                                    self.__combo_item_selected)
        self.timezone_combo_align.add(self.timezone_combo)

        self.__widget_pack_start(self.right_box, [
            self.time_title_align, self.cur_time_align,
            self.datetime_widget_align, self.auto_time_align,
            self.time_display_align, self.timezone_title_align,
            self.timezone_combo_align
        ])
        self.right_align.add(self.right_box)

        self.__widget_pack_start(self, [self.left_align, self.right_align])

        self.connect("expose-event", self.__expose)

        self.__send_message("status", ("date_time", ""))

        SecondThread(self).start()
        DateThread(self).start()
class DatetimeView(gtk.HBox):
    '''
    class docs
    '''
    def __init__(self):
        '''
        init docs
        '''
        gtk.HBox.__init__(self)

        self.__toggle_id = None
        self.__time_id = None

        self.datetime_settings = deepin_gsettings.new(
            "com.deepin.dde.datetime")

        self.__deepin_dt = DeepinDateTime()
        self.current_tz_gmtoff = self.__deepin_dt.get_gmtoff()

        self.timezone_items = []
        self.timezone_items.append((_("(UTC-11:00)Samoa"), -11))
        self.timezone_items.append((_("(UTC-10:00)Hawaii"), -10))
        self.timezone_items.append((_("(UTC-09:00)Alaska"), -9))
        self.timezone_items.append((_("(UTC-08:00)Lower California"), -8))
        self.timezone_items.append(
            (_("(UTC-07:00)Arizona, Llamas, Mazatlan, Chihuahua"), -7))
        self.timezone_items.append(
            (_("(UTC-06:00)Saskatchewan, Mexico City, Monterrey"), -6))
        self.timezone_items.append(
            (_("(UTC-05:00)Indiana, Bogota, Lima, Quito"), -5))
        self.timezone_items.append(
            (_("(UTC-04:00)San Diego, Georgetown, San Juan"), -4))
        self.timezone_items.append(
            (_("(UTC-03:00)Greenland, Brasilia, Fortaleza"), -3))
        self.timezone_items.append((_("(UTC-02:00)Mid-Atlantic"), -2))
        self.timezone_items.append(
            (_("(UTC-01:00)Cape Verde Islands, Azores"), -1))
        self.timezone_items.append(
            (_("(UTC)London, Dublin, Edinburgh, Lisbon, Casablanca"), 0))
        self.timezone_items.append(
            (_("(UTC+01:00)Paris, Amsterdam, Berlin, Rome, Vienna"), 1))
        self.timezone_items.append(
            (_("(UTC+02:00)Cairo, Athens, Istanbul, Jerusalem"), 2))
        self.timezone_items.append(
            (_("(UTC+03:00)Moscow, St. Petersburg, Baghdad"), 3))
        self.timezone_items.append(
            (_("(UTC+04:00)Port Louis, Abu Dhabi, Muscat, Yerevan"), 4))
        self.timezone_items.append(
            (_("(UTC+05:00)Islamabad, Karachi, Tashkent"), 5))
        self.timezone_items.append((_("(UTC+06:00)Dhaka, Novosibirsk"), 6))
        self.timezone_items.append(
            (_("(UTC+07:00)Bangkok, Hanoi, Jakarta"), 7))
        self.timezone_items.append(
            (_("(UTC+08:00)Beijing, Chongqing, HongKong, Taipei, Urumqi"), 8))
        self.timezone_items.append(
            (_("(UTC+09:00)Osaka, Sapporo, Tokyo, Seoul"), 9))
        self.timezone_items.append(
            (_("(UTC+10:00)Guam, Canberra, Melbourne, Sydney"), 10))
        self.timezone_items.append(
            (_("(UTC+11:00)Magadan, Solomon Islands"), 11))
        self.timezone_items.append((_("(UTC+12:00)New Zealand, Kiribati"), 12))
        self.is_24hour = self.datetime_settings.get_boolean("is-24hour")
        '''
        left align
        '''
        self.left_align = self.__setup_align(
            padding_top=TEXT_WINDOW_TOP_PADDING,
            padding_left=TEXT_WINDOW_LEFT_PADDING)
        '''
        left box
        '''
        self.left_box = gtk.VBox()
        '''
        calendar title
        '''
        self.calendar_title_align = self.__setup_title_align(
            app_theme.get_pixbuf("datetime/calendar.png"), _("Calendar"))
        '''
        current date
        '''
        self.cur_date_align = self.__setup_align()
        self.cur_date_label = self.__setup_label(
            _("Current Date: %d-%d-%d") %
            (time.localtime().tm_year, time.localtime().tm_mon,
             time.localtime().tm_mday), 190)
        self.cur_date_align.add(self.cur_date_label)
        '''
        calendar widget
        '''
        self.calendar_align = self.__setup_align(padding_top=BETWEEN_SPACING,
                                                 padding_bottom=10)
        self.calendar = deepin_lunar.new()
        if MAIN_LANG == "en_US":
            self.calendar = dltk_calendar.new()
        self.calendar.mark_day(time.localtime().tm_mday)
        self.calendar.get_handle().set_size_request(300, 280)
        self.calendar.get_handle().connect("day-selected",
                                           self.__on_day_selected,
                                           self.calendar)
        self.calendar_align.add(self.calendar.get_handle())
        self.change_date_box = gtk.HBox(spacing=5)
        self.change_date_box.set_size_request(300, -1)
        self.change_date_align = self.__setup_align()
        self.change_date_button = Button(_("Change Date"))
        self.change_date_button.connect("button-press-event",
                                        self.__on_change_date)
        self.change_date_align.add(self.change_date_button)
        self.edit_date_align = self.__setup_align()
        self.edit_date_box = gtk.HBox(spacing=5)
        self.cancel_date_button = Button(_("Cancel"))
        self.cancel_date_button.connect("button-press-event",
                                        self.__on_cancel_change_date)
        self.confirm_date_button = Button(_("Confirm"))
        self.confirm_date_button.connect("button-press-event",
                                         self.__on_confirm_change_date)
        self.__widget_pack_start(
            self.edit_date_box,
            [self.cancel_date_button, self.confirm_date_button])
        self.edit_date_align.add(self.edit_date_box)

        self.change_date_box.pack_end(self.change_date_align, False, False)
        '''
        left box && align
        '''
        self.__widget_pack_start(self.left_box, [
            self.calendar_title_align, self.cur_date_align,
            self.calendar_align, self.change_date_box
        ])
        self.left_align.add(self.left_box)
        '''
        right align
        '''
        self.right_align = self.__setup_align(
            padding_top=TEXT_WINDOW_TOP_PADDING,
            padding_left=TEXT_WINDOW_LEFT_PADDING)
        '''
        right box
        '''
        self.right_box = gtk.VBox()
        '''
        time title
        '''
        self.time_title_align = self.__setup_title_align(
            app_theme.get_pixbuf("datetime/time.png"), _("Time"))
        '''
        current time
        '''
        self.cur_time_align = self.__setup_align()
        if self.is_24hour:
            self.cur_time_label = self.__setup_label(
                _("Current Time: %s %02d:%02d:%02d (%d Hour)") %
                (time.strftime('%p'), time.localtime().tm_hour,
                 time.localtime().tm_min, time.localtime().tm_sec, 24), 260)
        else:
            self.cur_time_label = self.__setup_label(
                _("Current Time: %s %02d:%02d:%02d (%d Hour)") %
                (time.strftime('%p'), time.localtime().tm_hour,
                 time.localtime().tm_min, time.localtime().tm_sec, 12), 260)

        self.cur_time_align.add(self.cur_time_label)
        '''
        DateTime widget
        '''
        self.datetime_widget_align = self.__setup_align(
            padding_top=BETWEEN_SPACING)
        self.datetime_widget = DateTimeHTCStyle(is_24hour=self.is_24hour)
        self.datetime_widget_align.add(self.datetime_widget)
        self.set_time_align = self.__setup_align()
        '''
        auto time get && set
        '''
        self.auto_time_align = self.__setup_align(
            padding_top=TEXT_WINDOW_TOP_PADDING)
        self.auto_time_box = gtk.HBox(spacing=BETWEEN_SPACING)
        self.auto_time_label = self.__setup_label(_("NTP"))
        self.auto_time_toggle = self.__setup_toggle()
        is_auto_set_time = self.datetime_settings.get_boolean("is-auto-set")
        if is_auto_set_time:
            #AutoSetTimeThread(self).start()
            self.__deepin_dt.set_using_ntp(True)
        else:
            self.__deepin_dt.set_using_ntp(False)
        self.auto_time_toggle_align = self.__setup_align(padding_top=4)
        self.auto_time_toggle.set_active(is_auto_set_time)
        self.auto_time_toggle.connect("toggled", self.__toggled,
                                      "auto_time_toggle")
        self.auto_time_toggle_align.add(self.auto_time_toggle)
        '''
        set time
        '''
        self.set_time_spin_align = self.__setup_align(padding_left=10,
                                                      padding_top=1)
        self.set_time_box = gtk.HBox(spacing=BETWEEN_SPACING)
        self.set_time_label = self.__setup_label(_("Set Time"), 60)
        self.set_time_spin = TimeSpinBox(is_24hour=self.is_24hour)
        self.set_time_spin.set_size_request(85, WIDGET_HEIGHT)
        self.set_time_spin.connect("value-changed", self.__time_changed)
        self.__widget_pack_start(self.set_time_box,
                                 [self.set_time_label, self.set_time_spin])
        self.set_time_spin_align.add(self.set_time_box)
        self.__widget_pack_start(self.auto_time_box, [
            self.auto_time_label, self.auto_time_toggle_align,
            self.set_time_spin_align
        ])
        if is_auto_set_time:
            self.set_time_spin_align.set_child_visible(False)
        self.auto_time_align.add(self.auto_time_box)
        '''
        24hour display
        '''
        self.time_display_align = self.__setup_align(
            padding_top=BETWEEN_SPACING)
        self.time_display_box = gtk.HBox(spacing=BETWEEN_SPACING)
        self.time_display_label = self.__setup_label("24 %s" % _("Hour"))
        self.time_display_toggle_align = self.__setup_align()
        self.time_display_toggle = self.__setup_toggle()
        self.time_display_toggle.set_active(self.is_24hour)
        self.time_display_toggle.connect("toggled", self.__toggled,
                                         "time_display_toggle")
        self.time_display_toggle_align.add(self.time_display_toggle)
        self.__widget_pack_start(
            self.time_display_box,
            [self.time_display_label, self.time_display_toggle_align])
        self.time_display_align.add(self.time_display_box)
        '''
        timezone
        '''
        self.timezone_title_align = self.__setup_title_align(
            app_theme.get_pixbuf("datetime/globe-green.png"), _("Time Zone"),
            TEXT_WINDOW_TOP_PADDING)
        self.timezone_combo_align = self.__setup_align(padding_top=6)
        self.timezone_combo = ComboBox(self.timezone_items,
                                       max_width=340,
                                       fixed_width=340)
        self.timezone_combo.set_select_index(self.__deepin_dt.get_gmtoff() +
                                             11)
        self.timezone_combo.connect("item-selected",
                                    self.__combo_item_selected)
        self.timezone_combo_align.add(self.timezone_combo)

        self.__widget_pack_start(self.right_box, [
            self.time_title_align, self.cur_time_align,
            self.datetime_widget_align, self.auto_time_align,
            self.time_display_align, self.timezone_title_align,
            self.timezone_combo_align
        ])
        self.right_align.add(self.right_box)

        self.__widget_pack_start(self, [self.left_align, self.right_align])

        self.connect("expose-event", self.__expose)

        self.__send_message("status", ("date_time", ""))

        SecondThread(self).start()
        DateThread(self).start()

    def show_again(self):
        self.__send_message("status", ("date_time", ""))

    def reset(self):
        self.__send_message("status",
                            ("date_time", _("Reset to default value")))

        self.datetime_settings.reset("is-24hour")
        #self.datetime_settings.reset("is-auto-set")

        self.is_24hour = self.datetime_settings.get_boolean("is-24hour")
        self.time_display_toggle.set_active(self.is_24hour)
        self.datetime_widget.set_is_24hour(self.is_24hour)
        self.set_time_spin.set_24hour(self.is_24hour)

        is_auto_set_time = self.datetime_settings.get_boolean("is-auto-set")
        self.auto_time_toggle.set_active(is_auto_set_time)
        if is_auto_set_time:
            self.set_time_spin_align.set_child_visible(False)
            self.__deepin_dt.set_using_ntp(True)
        else:
            self.set_time_spin_align.set_child_visible(True)
            self.__deepin_dt.set_using_ntp(False)

    def __handle_dbus_replay(self, *reply):
        pass

    def __handle_dbus_error(self, *error):
        pass

    def __send_message(self, message_type, message_content):
        if is_dbus_name_exists(APP_DBUS_NAME):
            bus_object = dbus.SessionBus().get_object(APP_DBUS_NAME,
                                                      APP_OBJECT_NAME)
            method = bus_object.get_dbus_method("message_receiver")
            method(message_type,
                   message_content,
                   reply_handler=self.__handle_dbus_replay,
                   error_handler=self.__handle_dbus_error)

    def set_cur_date(self):
        year = time.localtime().tm_year
        month = time.localtime().tm_mon
        day = time.localtime().tm_mday
        self.cur_date_label.set_text(
            _("Current Date: %d-%d-%d") % (year, month, day))
        self.calendar.clear_marks()
        self.calendar.select_day(day)

    def set_cur_time_label(self):
        is_24hour = 24
        hour_value = time.localtime().tm_hour
        am_pm = ""

        if not self.is_24hour:
            am_pm = time.strftime('%p')
            is_24hour = 12
            if hour_value > 12:
                hour_value -= 12

        self.cur_time_label.set_text(
            _("Current Time: %s %02d:%02d:%02d (%d Hour)") %
            (am_pm, hour_value, time.localtime().tm_min,
             time.localtime().tm_sec, is_24hour))

    def __on_day_selected(self, object, widget):
        pass

    def __on_change_date(self, widget, event):
        #self.edit_date_align.set_padding(0, 0 , 195, 0)
        #self.change_date_align.set_padding(0, 0, -100, 0)
        #self.edit_date_align.set_child_visible(True)
        #self.change_date_align.set_child_visible(False)
        self.change_date_box.remove(self.change_date_align)
        self.change_date_box.pack_end(self.edit_date_align, False, False)
        self.calendar.clear_marks()
        self.show_all()

    def __hide_edit_date(self):
        #self.edit_date_align.set_padding(0, 0, 110, 0)
        #self.change_date_align.set_padding(0, 0, 0, 0)
        #self.edit_date_align.set_child_visible(False)
        #self.change_date_align.set_child_visible(True)
        self.change_date_box.remove(self.edit_date_align)
        self.change_date_box.pack_end(self.change_date_align, False, False)
        self.show_all()

    def __on_cancel_change_date(self, widget, event):
        self.__hide_edit_date()

    def __on_confirm_change_date(self, widget, event):
        year, month, day = self.calendar.get_date()
        self.__send_message("status",
                            ("date_time", _("Changed date to %d-%d-%d") %
                             (year, month, day)))
        self.__hide_edit_date()
        self.cur_date_label.set_text(
            _("Current Date: %d-%d-%d") % (year, month, day))
        self.calendar.mark_day(day)
        self.auto_time_toggle.set_active(False)
        self.__set_using_ntp(False)
        SetDateThread(self.__deepin_dt, day, month, year).start()

    def __setup_separator(self):
        hseparator = HSeparator(
            app_theme.get_shadow_color("hSeparator").get_color_info(), 0, 0)
        hseparator.set_size_request(300, HSEPARATOR_HEIGHT)
        return hseparator

    def __setup_title_label(
            self,
            text="",
            text_color=app_theme.get_color("globalTitleForeground"),
            text_size=TITLE_FONT_SIZE,
            text_x_align=ALIGN_START,
            label_width=180):
        return Label(text=text,
                     text_color=text_color,
                     text_size=text_size,
                     text_x_align=text_x_align,
                     label_width=label_width,
                     enable_select=False,
                     enable_double_click=False)

    def __setup_title_align(self, pixbuf, text, padding_top=0, padding_left=0):
        align = self.__setup_align(padding_top=padding_top,
                                   padding_left=padding_left)
        align_box = gtk.VBox(spacing=WIDGET_SPACING)
        title_box = gtk.HBox(spacing=WIDGET_SPACING)
        image = ImageBox(pixbuf)
        label = self.__setup_title_label(text)
        separator = self.__setup_separator()
        self.__widget_pack_start(title_box, [image, label])
        self.__widget_pack_start(align_box, [title_box, separator])
        align.add(align_box)
        return align

    def __set_using_ntp(self, data=True):
        self.__deepin_dt.set_using_ntp(data)

    def __toggled(self, widget, argv):
        if argv == "auto_time_toggle":
            is_auto_set_time = widget.get_active()
            self.datetime_settings.set_boolean("is-auto-set", is_auto_set_time)
            if is_auto_set_time:
                self.__send_message(
                    "status",
                    ("date_time",
                     _("Time will be synchronized with an Internet time server"
                       )))
                self.set_time_spin_align.set_child_visible(False)
                gobject.timeout_add_seconds(3, self.__set_using_ntp, True)
            else:
                self.__send_message("status", (
                    "date_time",
                    _("Time will not be synchronized with an Internet time server"
                      )))
                self.set_time_spin_align.set_child_visible(True)
                if self.__toggle_id:
                    gobject.source_remove(self.__toggle_id)
                self.__toggle_id = gobject.timeout_add_seconds(
                    3, self.__set_using_ntp, False)
            return

        if argv == "time_display_toggle":
            self.is_24hour = widget.get_active()
            if self.is_24hour:
                self.__send_message(
                    "status",
                    ("date_time", _("Time will be shown in 24 hour format")))
            else:
                self.__send_message(
                    "status",
                    ("date_time", _("Time will be shown in 12 hour format")))
            self.datetime_settings.set_boolean("is-24hour", self.is_24hour)
            self.datetime_widget.set_is_24hour(self.is_24hour)
            self.set_time_spin.set_24hour(self.is_24hour)

    def auto_set_time(self):
        self.__deepin_dt.set_using_ntp(True)

    def __set_time(self, hour, min, sec):
        self.__deepin_dt.set_time_by_hms(hour, min, sec)

    def __time_changed(self, widget, hour, min, sec):
        self.__send_message("status",
                            ("date_time", _("Changed time to %02d:%02d:%02d") %
                             (hour, min, sec)))

        if self.__time_id:
            gobject.source_remove(self.__time_id)
        self.__time_id = gobject.timeout_add_seconds(1, self.__set_time, hour,
                                                     min, sec)

    def __expose(self, widget, event):
        cr = widget.window.cairo_create()
        rect = widget.allocation

        cr.set_source_rgb(*color_hex_to_cairo(MODULE_BG_COLOR))
        cr.rectangle(rect.x, rect.y, rect.width, rect.height)
        cr.fill()

    def __draw_title_background(self, cr, widget):
        rect = widget.allocation

        cr.set_source_rgb(*color_hex_to_cairo(MODULE_BG_COLOR))
        cr.rectangle(rect.x, rect.y - FRAME_TOP_PADDING, rect.width,
                     rect.height - 1)
        cr.fill()

    def __combo_item_selected(self,
                              widget,
                              item_text=None,
                              item_value=None,
                              item_index=None):
        self.__send_message(
            "status", ("date_time", _("Changed time zone to %s") % item_text))
        self.__deepin_dt.set_timezone_by_gmtoff(item_value)

    def __setup_label(self, text="", width=90, align=ALIGN_START):
        label = Label(text, None, CONTENT_FONT_SIZE, align, width, False,
                      False, False)
        return label

    def __setup_toggle(self):
        toggle = ToggleButton(
            app_theme.get_pixbuf("toggle_button/inactive_normal.png"),
            app_theme.get_pixbuf("toggle_button/active_normal.png"))
        return toggle

    def __setup_align(self,
                      xalign=0,
                      yalign=0,
                      xscale=0,
                      yscale=0,
                      padding_top=0,
                      padding_bottom=0,
                      padding_left=0,
                      padding_right=0):
        align = gtk.Alignment()
        align.set(xalign, yalign, xscale, yscale)
        align.set_padding(padding_top, padding_bottom, padding_left,
                          padding_right)
        return align

    def __widget_pack_start(self,
                            parent_widget,
                            widgets=[],
                            expand=False,
                            fill=False):
        if parent_widget == None:
            return
        for item in widgets:
            parent_widget.pack_start(item, expand, fill)
 def __setup_combo(self, items=[]):
     combo = ComboBox(items, None, 0, 120)
     return combo
class AppView(gtk.VBox):
    ENTRY_WIDTH = 200
    LEFT_WIDTH = STANDARD_LINE - TEXT_WINDOW_LEFT_PADDING

    def __init__(self):
        '''docstring for __'''
        gtk.VBox.__init__(self)
        style.draw_background_color(self)

        self.app = AppManager()
        self.content_type_list = [
            self.app.http_content_type, self.app.mail_content_type,
            self.app.editor_content_type, self.app.audio_content_type,
            self.app.video_content_type, self.app.photo_content_type
        ]

        self.app_table()
        self.web.connect("item-selected", self.item_select, 0)
        self.mail.connect("item-selected", self.item_select, 1)
        self.editor.connect("item-selected", self.item_select, 2)
        self.music.connect("item-selected", self.item_select, 3)
        self.movie.connect("item-selected", self.item_select, 4)
        self.pic.connect("item-selected", self.item_select, 5)

    def app_table(self):
        # Labels
        #info_label = Label("您可以根据自己需要对深度系统在默认情况下使用的程序进行设置")
        web_label = Label(_("Web"))
        mail_label = Label(_("Mail"))
        editor_label = Label(_("Editor"))
        music_label = Label(_("Music"))
        movie_label = Label(_("Video"))
        pic_label = Label(_("Photo"))
        terminal_label = Label(_("Terminal"))

        self.web = ComboBox([("None", 0)], fixed_width=self.ENTRY_WIDTH)
        self.mail = ComboBox([("None", 0)], fixed_width=self.ENTRY_WIDTH)
        self.editor = ComboBox([("None", 0)], fixed_width=self.ENTRY_WIDTH)
        self.music = ComboBox([("None", 0)], fixed_width=self.ENTRY_WIDTH)
        self.movie = ComboBox([("None", 0)], fixed_width=self.ENTRY_WIDTH)
        self.pic = ComboBox([("None", 0)], fixed_width=self.ENTRY_WIDTH)
        self.terminal = self.get_terminal_combo()

        table = gtk.Table(8, 2, False)
        #table.attach(style.wrap_with_align(info_label), 0, 2, 0, 1)
        table.attach(style.wrap_with_align(web_label, width=self.LEFT_WIDTH),
                     0, 1, 1, 2)
        table.attach(style.wrap_with_align(mail_label, width=self.LEFT_WIDTH),
                     0, 1, 2, 3)
        table.attach(
            style.wrap_with_align(editor_label, width=self.LEFT_WIDTH), 0, 1,
            3, 4)
        table.attach(style.wrap_with_align(music_label, width=self.LEFT_WIDTH),
                     0, 1, 4, 5)
        table.attach(style.wrap_with_align(movie_label, width=self.LEFT_WIDTH),
                     0, 1, 5, 6)
        table.attach(style.wrap_with_align(pic_label, width=self.LEFT_WIDTH),
                     0, 1, 6, 7)
        table.attach(
            style.wrap_with_align(terminal_label, width=self.LEFT_WIDTH), 0, 1,
            7, 8)

        table.attach(style.wrap_with_align(self.web), 1, 2, 1, 2, 0)
        table.attach(style.wrap_with_align(self.mail), 1, 2, 2, 3, 0)
        table.attach(style.wrap_with_align(self.editor), 1, 2, 3, 4)
        table.attach(style.wrap_with_align(self.music), 1, 2, 4, 5)
        table.attach(style.wrap_with_align(self.movie), 1, 2, 5, 6)
        table.attach(style.wrap_with_align(self.pic), 1, 2, 6, 7)
        table.attach(style.wrap_with_align(self.terminal), 1, 2, 7, 8)
        align = style.set_box_with_align(table, "text")
        style.set_table(table)

        self.pack_start(align, False, False)

        all_app_dict = self.get_all_app()
        #print all_app_dict
        apps = [
            self.web, self.mail, self.editor, self.music, self.movie, self.pic
        ]
        for app in apps:
            app.set_size_request(self.ENTRY_WIDTH, 22)
        for key in all_app_dict.iterkeys():
            if self.get_default_app:
                apps[key].add_items(all_app_dict[key])
            else:
                apps[key].add_items(all_app_dict[key], clear_first=False)

    def attach_to(self, table, widget_list, row, width):
        for index, widget in enumerate(widget_list):
            align = style.wrap_with_align(widget, width=width[index])
            table.attach(align, index, index + 1, row, row + 1)

    def get_default_app(self):
        dic = {}
        for index, value in enumerate(self.content_type_list):
            default_app = self.app.get_default_for_type(value)
            if default_app:
                dic[index] = default_app

        return dic

    def get_terminal_combo(self):
        default_terminal = dmenu.get_default_terminal()
        terminal_apps = dmenu.get_terminal_apps()
        try:
            index = terminal_apps.index(default_terminal)
        except Exception, e:
            print e
            index = 0

        combo_box = ComboBox([(exec_.capitalize(), exec_)
                              for exec_ in terminal_apps],
                             select_index=index,
                             fixed_width=self.ENTRY_WIDTH)
        combo_box.connect("item-selected", self.on_terminal_item_selected)
        return combo_box
Example #25
0
 def __setup_combo(self, items=[], width=120):
     combo = ComboBox(items, None, 0, width)
     return combo
    def app_table(self):
        # Labels
        #info_label = Label("您可以根据自己需要对深度系统在默认情况下使用的程序进行设置")
        web_label = Label(_("Web"))
        mail_label = Label(_("Mail"))
        editor_label = Label(_("Editor"))
        music_label = Label(_("Music"))
        movie_label = Label(_("Video"))
        pic_label = Label(_("Photo"))
        terminal_label = Label(_("Terminal"))

        self.web = ComboBox([("None", 0)], fixed_width=self.ENTRY_WIDTH)
        self.mail = ComboBox([("None", 0)], fixed_width=self.ENTRY_WIDTH)
        self.editor = ComboBox([("None", 0)], fixed_width=self.ENTRY_WIDTH)
        self.music = ComboBox([("None", 0)], fixed_width=self.ENTRY_WIDTH)
        self.movie = ComboBox([("None", 0)], fixed_width=self.ENTRY_WIDTH)
        self.pic = ComboBox([("None", 0)], fixed_width=self.ENTRY_WIDTH)
        self.terminal = self.get_terminal_combo()

        table = gtk.Table(8, 2, False)
        #table.attach(style.wrap_with_align(info_label), 0, 2, 0, 1)
        table.attach(style.wrap_with_align(web_label, width=self.LEFT_WIDTH),
                     0, 1, 1, 2)
        table.attach(style.wrap_with_align(mail_label, width=self.LEFT_WIDTH),
                     0, 1, 2, 3)
        table.attach(
            style.wrap_with_align(editor_label, width=self.LEFT_WIDTH), 0, 1,
            3, 4)
        table.attach(style.wrap_with_align(music_label, width=self.LEFT_WIDTH),
                     0, 1, 4, 5)
        table.attach(style.wrap_with_align(movie_label, width=self.LEFT_WIDTH),
                     0, 1, 5, 6)
        table.attach(style.wrap_with_align(pic_label, width=self.LEFT_WIDTH),
                     0, 1, 6, 7)
        table.attach(
            style.wrap_with_align(terminal_label, width=self.LEFT_WIDTH), 0, 1,
            7, 8)

        table.attach(style.wrap_with_align(self.web), 1, 2, 1, 2, 0)
        table.attach(style.wrap_with_align(self.mail), 1, 2, 2, 3, 0)
        table.attach(style.wrap_with_align(self.editor), 1, 2, 3, 4)
        table.attach(style.wrap_with_align(self.music), 1, 2, 4, 5)
        table.attach(style.wrap_with_align(self.movie), 1, 2, 5, 6)
        table.attach(style.wrap_with_align(self.pic), 1, 2, 6, 7)
        table.attach(style.wrap_with_align(self.terminal), 1, 2, 7, 8)
        align = style.set_box_with_align(table, "text")
        style.set_table(table)

        self.pack_start(align, False, False)

        all_app_dict = self.get_all_app()
        #print all_app_dict
        apps = [
            self.web, self.mail, self.editor, self.music, self.movie, self.pic
        ]
        for app in apps:
            app.set_size_request(self.ENTRY_WIDTH, 22)
        for key in all_app_dict.iterkeys():
            if self.get_default_app:
                apps[key].add_items(all_app_dict[key])
            else:
                apps[key].add_items(all_app_dict[key], clear_first=False)
Example #27
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
 def __setup_combo(self, items=[], width=HSCALEBAR_WIDTH):
     combo = ComboBox(items, None, 0, width, width)
     combo.set_size_request(width, WIDGET_HEIGHT)
     return combo
Example #29
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")
Example #30
0
class Broadband(gtk.VBox):
    ENTRY_WIDTH = 222
    LEFT_PADDING = 210
    def __init__(self, connection, set_button_callback, settings_obj=None):
        gtk.VBox.__init__(self)
        self.tab_name = _("Broadband")
        self.connection = connection        
        self.set_button = set_button_callback
        # 新增settings_obj变量,用于访问shared_methods.Settings对象
        self.settings_obj = settings_obj

        # Init widgets
        self.table = gtk.Table(12, 4, False)
        
        #self.label_basic = Label(_("Basic"), text_size = TITLE_FONT_SIZE)
        self.label_basic = TitleBar(None, _("Basic"))
        self.label_number = Label(_("Code:"), text_size=CONTENT_FONT_SIZE,
                               enable_select=False,
                               enable_double_click=False)
        self.label_username = Label(_("Username:"******"Password:"******"Show password"), padding_x=0)
        self.button_to_region = Button(_("Regions setting"))


        #self.table = gtk.Table(6, 4, False)
        self.label_advanced = TitleBar(None,_("Advanced"))
        self.label_apn = Label(_("APN:"), text_size=CONTENT_FONT_SIZE,
                               enable_select=False,
                               enable_double_click=False)
        self.label_network = Label(_("Network ID:"), text_size=CONTENT_FONT_SIZE,
                               enable_select=False,
                               enable_double_click=False)
        self.label_type = Label(_("Type:"), text_size=CONTENT_FONT_SIZE,
                               enable_select=False,
                               enable_double_click=False)
        self.label_pin = Label(_("PIN:"), text_size=CONTENT_FONT_SIZE,
                               enable_select=False,
                               enable_double_click=False)

        self.apn = InputEntry()
        self.network_id = InputEntry()
        self.network_type = ComboBox([("Any", None),
                                      ("3G", 0),
                                      ("2G", 1),
                                      ("Prefer 3G", 2),
                                      ("Prefer 2G", 3)],
                                      fixed_width=self.ENTRY_WIDTH)
        self.roam_check = CheckButton(_("Allow roaming if home network is not available"), padding_x=0)
        self.pin = InputEntry()
        
        
        # Connect signals
        self.number.entry.connect("changed", self.save_settings_by, "number")
        self.username.entry.connect("changed", self.save_settings_by, "username")
        self.password.entry.connect("changed", self.save_settings_by, "password")
        self.apn.entry.connect("changed", self.save_settings_by, "apn")
        self.network_id.entry.connect("changed", self.save_settings_by, "network_id")
        self.network_type.connect("item-selected", self.network_type_selected)

        self.password_show.connect("toggled", self.password_show_toggled)
        self.roam_check.connect("toggled", self.roam_check_toggled)


        table_align = gtk.Alignment(0, 0, 0, 0)
        table_align.add(self.table)
        self.pack_start(table_align)

        # wrap with alignment
        
        # Refesh
        self.refresh()

    def password_show_toggled(self, widget):
        if widget.get_active():
            self.password.show_password(True)
        else:
            self.password.show_password(False)

    def init_table(self, network_type):
        #container_remove_all(self.table)
        if self.table.get_children() != []:
            pass
        else:
            #self.table.attach(self.label_basic, 0,2 ,0, 1)
            self.table.attach(style.wrap_with_align(self.label_number, width=self.LEFT_PADDING), 0, 1, 1, 2)
            self.table.attach(style.wrap_with_align(self.label_username, width=self.LEFT_PADDING), 0, 1, 2, 3)
            self.table.attach(style.wrap_with_align(self.label_password, width=self.LEFT_PADDING), 0, 1, 3, 4)

            self.table.attach(style.wrap_with_align(self.number), 1, 2, 1, 2)
            self.table.attach(style.wrap_with_align(self.username), 1, 2, 2, 3)
            self.table.attach(style.wrap_with_align(self.password), 1, 2, 3, 4)
            self.table.attach(style.wrap_with_align(self.password_show, align="left"), 1, 2, 4, 5)

            def to_region(widget):
                region = slider.get_page_by_name("region")
                region.init(self.connection)
                #region.need_new_connection =False
                slider._slide_to_page("region", "none")

            if network_type == "gsm":
                self.button_to_region.connect("clicked", to_region)
                self.table.attach(style.wrap_with_align(self.button_to_region), 1,2,5,6)
                self.table.attach(self.label_advanced, 0, 2, 6, 7)
                self.table.attach(style.wrap_with_align(self.label_apn), 0, 1 , 7, 8)
                self.table.attach(style.wrap_with_align(self.label_network), 0, 1, 8, 9)
                self.table.attach(style.wrap_with_align(self.label_type), 0, 1, 9, 10)
                self.table.attach(style.wrap_with_align(self.label_pin), 0, 1, 11, 12)

                self.table.attach(style.wrap_with_align(self.apn), 1, 2, 7, 8)
                self.table.attach(style.wrap_with_align(self.network_id), 1, 2, 8, 9)
                self.table.attach(style.wrap_with_align(self.network_type), 1, 2, 9, 10)
                self.table.attach(style.wrap_with_align(self.roam_check, align="left"), 1, 2, 10, 11)
                self.table.attach(style.wrap_with_align(self.pin), 1, 2, 11, 12)
            #TODO ui change
            #style.set_table_items(self.table, 'entry')
            entry_list = ["number", "username", "password",
                          "apn", "network_id", "pin"]
            for entry in entry_list:
                widget = getattr(self, entry)
                widget.entry.set_size_request(self.ENTRY_WIDTH, 22)

            style.set_table(self.table)
        self.table.show_all()

    def refresh(self):
        # get_settings
        mobile_type = self.connection.get_setting("connection").type
        self.broadband_setting = self.connection.get_setting(mobile_type)
        number = self.broadband_setting.number
        username = self.broadband_setting.username

        password = self.broadband_setting.password

        if password == None:
            try:
                (setting_name, method) = self.connection.guess_secret_info() 
                password = nm_module.secret_agent.agent_get_secrets(self.connection.object_path,
                                                        setting_name,
                                                        method)
            except:
                password = ""

        # both
        self.number.set_text(number)
        self.username.set_text(username)
        self.password.entry.set_text(password)

        if  mobile_type == "gsm":
            apn = self.broadband_setting.apn
            network_id = self.broadband_setting.network_id
            network_type = self.broadband_setting.network_type
            home_only = self.broadband_setting.home_only
            
            # gsm
            self.apn.set_text(apn)
            self.network_id.set_text(network_id)
            if network_type:
                self.network_type.set_select_index(network_type + 1)
            else:
                self.network_type.set_select_index(0)

            self.roam_check.set_active(home_only is None)

        self.init_table(mobile_type)
        
        ## retrieve wired info

    def set_new_values(self, new_dict, type):
        params = new_dict[type]

        for key, value in params.iteritems():
            setattr(self.broadband_setting, key, value)
        self.refresh()

    def save_settings_by(self, widget, text, attr):
        if text == "":
            delattr(self.broadband_setting, attr)
        else:
            setattr(self.broadband_setting, attr, text)
        self.set_button("save", True)

    def network_type_selected(self, widget, content, value, index):
        if value == None:
            del self.broadband_setting.network_type
        else:
            self.broadband_setting.network_type = value

    def roam_check_toggled(self, widget):
        if widget.get_active():
            del self.broadband_setting.home_only
        else:
            self.broadband_setting.home_only = 1

    def expose_bg(self, widget, event):
        cr = widget.window.cairo_create()
        rect = widget.allocation
        cr.set_source_rgb( 1, 1, 1) 
        cr.rectangle(rect.x, rect.y, rect.width, rect.height)
        cr.fill()
Example #31
0
    def __init__(self):
        super(EqualizerWindow, self).__init__(_("Equalizer"),
                                              372,
                                              168,
                                              DIALOG_MASK_SINGLE_PAGE,
                                              close_callback=self.hide_all,
                                              modal=False,
                                              window_hint=None,
                                              skip_taskbar_hint=False)

        self.manual_flag = False

        try:
            pre_value = float(config.get("equalizer", "preamp"))
        except:
            pre_value = 0.6

        pre_adjust = gtk.Adjustment(value=pre_value,
                                    lower=-10,
                                    upper=10,
                                    step_incr=0.1,
                                    page_incr=1,
                                    page_size=0)
        self.preamp_scale = PreampScalebar()
        self.preamp_scale.scalebar.set_adjustment(pre_adjust)
        pre_adjust.connect("value-changed", self.preamp_change)

        self.connect("configure-event", self.equalizer_configure_event)
        control_box = gtk.HBox(spacing=10)
        control_box.pack_start(self.preamp_scale, False, False)
        self.__scales = {}

        for i, label in enumerate(
            ["32", "64", "125", "250", "500", "1k", "2k", "4k", "8k", "16k"]):
            slipper_scale = SlipperScalebar(label)
            try:
                value = float(
                    config.get("equalizer", "equalizer-band%s" % str(i)))
            except:
                value = 0.0

            adjust = gtk.Adjustment(value=value,
                                    lower=-12,
                                    upper=12,
                                    step_incr=0.1,
                                    page_incr=1,
                                    page_size=0)
            adjust.changed_id = adjust.connect("value-changed",
                                               self.__on_adjust_change, i)
            slipper_scale.scalebar.set_adjustment(adjust)
            self.__scales[i] = slipper_scale.scalebar
            control_box.pack_start(slipper_scale, False, False)

        try:
            self.__equalizer = gst.element_factory_make("equalizer-10bands")
        except gst.PluginNotFoundError:
            self.__equalizer = None
            self.logerror(
                "Equalizer support requires gstreamer-plugins-bad (>= 0.10.5)")
        else:
            Player.bin.xfade_add_filter(self.__equalizer)
            for i in range(0, 10):
                try:
                    value = float(
                        config.get("equalizer", "equalizer-band%s" % str(i)))
                except:
                    value = 0

                self.__equalizer.set_property("band" + str(i), float(value))

            Player.bin.connect("tee-removed", self.__on_remove)
            config.connect("config-changed", self.__on_config_change)

        self.active_button = Button(_("Close"))
        self.active_button.connect("clicked", self.hide_win)
        self.reset_button = Button(_("Reset"))
        self.reset_button.connect("clicked", self.set_default_value)
        self.predefine_button = Button(_("Predefined"))
        self.predefine_button.connect("clicked", self.show_predefine)

        self.predefine_combo_box = ComboBox(
            [(value, key) for key, value in mandatory_i18n.items()],
            250,
            select_index=self.get_selected_index())
        self.predefine_combo_box.connect("item-selected",
                                         self.set_predefine_value)

        control_box_align = gtk.Alignment()
        control_box_align.set(0.0, 0.0, 1.0, 1.0)
        control_box_align.set_padding(10, 20, 15, 15)
        control_box_align.add(control_box)

        main_align = gtk.Alignment()
        main_align.set(0.0, 0.0, 1.0, 1.0)
        main_align.set_padding(0, 5, 2, 2)
        main_box = gtk.VBox(spacing=5)
        main_align.add(main_box)

        main_box.add(control_box_align)

        self.body_box.pack_start(main_align, True, True)
        self.left_button_box.set_buttons([self.predefine_combo_box])
        self.right_button_box.set_buttons(
            [self.reset_button, self.active_button])
 def __setup_combo(self, items=[], max_width=130, fixed_width=130):
     return ComboBox(items=items,
                     select_index=0,
                     max_width=max_width,
                     fixed_width=fixed_width)
    def __init__(self):
        '''
        init docs
        '''
        gtk.HBox.__init__(self)

        self.__toggle_id = None
        self.__time_id = None

        self.datetime_settings = deepin_gsettings.new("com.deepin.dde.datetime")

        self.__deepin_dt = DeepinDateTime()
        self.current_tz_gmtoff = self.__deepin_dt.get_gmtoff()

        self.timezone_items = []
        self.timezone_items.append((_("(UTC-11:00)Samoa"), -11))
        self.timezone_items.append((_("(UTC-10:00)Hawaii"), -10))
        self.timezone_items.append((_("(UTC-09:00)Alaska"), -9))
        self.timezone_items.append((_("(UTC-08:00)Lower California"), -8))
        self.timezone_items.append((_("(UTC-07:00)Arizona, Llamas, Mazatlan, Chihuahua"), -7))
        self.timezone_items.append((_("(UTC-06:00)Saskatchewan, Mexico City, Monterrey"), -6))
        self.timezone_items.append((_("(UTC-05:00)Indiana, Bogota, Lima, Quito"), -5))
        self.timezone_items.append((_("(UTC-04:00)San Diego, Georgetown, San Juan"), -4))
        self.timezone_items.append((_("(UTC-03:00)Greenland, Brasilia, Fortaleza"), -3))
        self.timezone_items.append((_("(UTC-02:00)Mid-Atlantic"), -2))
        self.timezone_items.append((_("(UTC-01:00)Cape Verde Islands, Azores"), -1))
        self.timezone_items.append((_("(UTC)London, Dublin, Edinburgh, Lisbon, Casablanca"), 0))
        self.timezone_items.append((_("(UTC+01:00)Paris, Amsterdam, Berlin, Rome, Vienna"), 1))
        self.timezone_items.append((_("(UTC+02:00)Cairo, Athens, Istanbul, Jerusalem"), 2))
        self.timezone_items.append((_("(UTC+03:00)Moscow, St. Petersburg, Baghdad"), 3))
        self.timezone_items.append((_("(UTC+04:00)Port Louis, Abu Dhabi, Muscat, Yerevan"), 4))
        self.timezone_items.append((_("(UTC+05:00)Islamabad, Karachi, Tashkent"), 5))
        self.timezone_items.append((_("(UTC+06:00)Dhaka, Novosibirsk"), 6))
        self.timezone_items.append((_("(UTC+07:00)Bangkok, Hanoi, Jakarta"), 7))
        self.timezone_items.append((_("(UTC+08:00)Beijing, Chongqing, HongKong, Taipei, Urumqi"), 8))
        self.timezone_items.append((_("(UTC+09:00)Osaka, Sapporo, Tokyo, Seoul"), 9))
        self.timezone_items.append((_("(UTC+10:00)Guam, Canberra, Melbourne, Sydney"), 10))
        self.timezone_items.append((_("(UTC+11:00)Magadan, Solomon Islands"), 11))
        self.timezone_items.append((_("(UTC+12:00)New Zealand, Kiribati"), 12))
        self.is_24hour = self.datetime_settings.get_boolean("is-24hour")
        '''
        left align
        '''
        self.left_align = self.__setup_align(
            padding_top = TEXT_WINDOW_TOP_PADDING, 
            padding_left = TEXT_WINDOW_LEFT_PADDING)
        '''
        left box
        '''
        self.left_box = gtk.VBox()
        '''
        calendar title
        '''
        self.calendar_title_align = self.__setup_title_align(
            app_theme.get_pixbuf("datetime/calendar.png"), _("Calendar"))
        '''
        current date
        '''
        self.cur_date_align = self.__setup_align()
        self.cur_date_label = self.__setup_label(
            _("Current Date: %d-%d-%d") % (time.localtime().tm_year, 
                                           time.localtime().tm_mon, 
                                           time.localtime().tm_mday), 
            190)
        self.cur_date_align.add(self.cur_date_label)
        '''
        calendar widget
        '''
        self.calendar_align = self.__setup_align(padding_top = BETWEEN_SPACING, 
            padding_bottom = 10)
        self.calendar = deepin_lunar.new()
        if MAIN_LANG == "en_US":
            self.calendar = dltk_calendar.new()
        self.calendar.mark_day(time.localtime().tm_mday)
        self.calendar.get_handle().set_size_request(300, 280)
        self.calendar.get_handle().connect("day-selected", self.__on_day_selected, self.calendar)
        self.calendar_align.add(self.calendar.get_handle())
        self.change_date_box = gtk.HBox(spacing = 5)
        self.change_date_box.set_size_request(300, -1)
        self.change_date_align = self.__setup_align()
        self.change_date_button = Button(_("Change Date"))
        self.change_date_button.connect("button-press-event", self.__on_change_date)
        self.change_date_align.add(self.change_date_button)
        self.edit_date_align = self.__setup_align()
        self.edit_date_box = gtk.HBox(spacing = 5)
        self.cancel_date_button = Button(_("Cancel"))
        self.cancel_date_button.connect("button-press-event", self.__on_cancel_change_date)
        self.confirm_date_button = Button(_("Confirm"))
        self.confirm_date_button.connect("button-press-event", self.__on_confirm_change_date)
        self.__widget_pack_start(self.edit_date_box, 
            [self.cancel_date_button, self.confirm_date_button])
        self.edit_date_align.add(self.edit_date_box)

        self.change_date_box.pack_end(self.change_date_align, False, False)
        '''
        left box && align
        '''
        self.__widget_pack_start(self.left_box, 
            [self.calendar_title_align, 
             self.cur_date_align, 
             self.calendar_align, 
             self.change_date_box])
        self.left_align.add(self.left_box)
        '''
        right align
        '''
        self.right_align = self.__setup_align(
            padding_top = TEXT_WINDOW_TOP_PADDING, padding_left = TEXT_WINDOW_LEFT_PADDING)
        '''
        right box
        '''
        self.right_box = gtk.VBox()
        '''
        time title
        '''
        self.time_title_align = self.__setup_title_align(
            app_theme.get_pixbuf("datetime/time.png"), _("Time"))
        '''
        current time
        '''
        self.cur_time_align = self.__setup_align()
        if self.is_24hour:
            self.cur_time_label = self.__setup_label(
                _("Current Time: %s %02d:%02d:%02d (%d Hour)") % 
                  (time.strftime('%p'), 
                   time.localtime().tm_hour, 
                   time.localtime().tm_min, 
                   time.localtime().tm_sec, 
                   24), 
                260)
        else:
            self.cur_time_label = self.__setup_label(                           
                _("Current Time: %s %02d:%02d:%02d (%d Hour)") %                
                  (time.strftime('%p'),                                         
                   time.localtime().tm_hour,                                    
                   time.localtime().tm_min,                                     
                   time.localtime().tm_sec,                                     
                   12),                                                         
                260)     

        self.cur_time_align.add(self.cur_time_label)
        '''
        DateTime widget
        '''
        self.datetime_widget_align = self.__setup_align(padding_top = BETWEEN_SPACING)
        self.datetime_widget = DateTimeHTCStyle(is_24hour = self.is_24hour)
        self.datetime_widget_align.add(self.datetime_widget)
        self.set_time_align = self.__setup_align()
        '''
        auto time get && set
        '''
        self.auto_time_align = self.__setup_align(padding_top = TEXT_WINDOW_TOP_PADDING)
        self.auto_time_box = gtk.HBox(spacing = BETWEEN_SPACING)
        self.auto_time_label = self.__setup_label(_("NTP"))
        self.auto_time_toggle = self.__setup_toggle()
        is_auto_set_time = self.datetime_settings.get_boolean("is-auto-set")
        if is_auto_set_time:
            #AutoSetTimeThread(self).start()
            self.__deepin_dt.set_using_ntp(True)
        else:
            self.__deepin_dt.set_using_ntp(False)
        self.auto_time_toggle_align = self.__setup_align(padding_top = 4)
        self.auto_time_toggle.set_active(is_auto_set_time)
        self.auto_time_toggle.connect("toggled", self.__toggled, "auto_time_toggle")
        self.auto_time_toggle_align.add(self.auto_time_toggle)
        '''
        set time
        '''
        self.set_time_spin_align = self.__setup_align(padding_left = 10, padding_top = 1)
        self.set_time_box = gtk.HBox(spacing = BETWEEN_SPACING)
        self.set_time_label = self.__setup_label(_("Set Time"), 60)
        self.set_time_spin = TimeSpinBox(is_24hour = self.is_24hour)                 
        self.set_time_spin.set_size_request(85, WIDGET_HEIGHT)                               
        self.set_time_spin.connect("value-changed", self.__time_changed)
        self.__widget_pack_start(self.set_time_box, 
            [self.set_time_label, self.set_time_spin])
        self.set_time_spin_align.add(self.set_time_box)
        self.__widget_pack_start(self.auto_time_box, 
                                 [
                                  self.auto_time_label, 
                                  self.auto_time_toggle_align, 
                                  self.set_time_spin_align]) 
        if is_auto_set_time:
            self.set_time_spin_align.set_child_visible(False)
        self.auto_time_align.add(self.auto_time_box)
        '''
        24hour display
        '''
        self.time_display_align = self.__setup_align(padding_top = BETWEEN_SPACING)
        self.time_display_box = gtk.HBox(spacing = BETWEEN_SPACING)
        self.time_display_label = self.__setup_label("24 %s" % _("Hour"))
        self.time_display_toggle_align = self.__setup_align()
        self.time_display_toggle = self.__setup_toggle()                        
        self.time_display_toggle.set_active(self.is_24hour)                          
        self.time_display_toggle.connect("toggled", self.__toggled, "time_display_toggle")
        self.time_display_toggle_align.add(self.time_display_toggle)
        self.__widget_pack_start(self.time_display_box, 
            [self.time_display_label, self.time_display_toggle_align])
        self.time_display_align.add(self.time_display_box)
        '''
        timezone
        '''
        self.timezone_title_align = self.__setup_title_align(
            app_theme.get_pixbuf("datetime/globe-green.png"), 
            _("Time Zone"), 
            TEXT_WINDOW_TOP_PADDING)
        self.timezone_combo_align = self.__setup_align(padding_top = 6)
        self.timezone_combo = ComboBox(self.timezone_items, max_width = 340, fixed_width = 340)
        self.timezone_combo.set_select_index(self.__deepin_dt.get_gmtoff() + 11)
        self.timezone_combo.connect("item-selected", self.__combo_item_selected)
        self.timezone_combo_align.add(self.timezone_combo)

        self.__widget_pack_start(self.right_box, 
                                 [self.time_title_align, 
                                  self.cur_time_align, 
                                  self.datetime_widget_align, 
                                  self.auto_time_align, 
                                  self.time_display_align, 
                                  self.timezone_title_align, 
                                  self.timezone_combo_align])
        self.right_align.add(self.right_box)
       
        self.__widget_pack_start(self, [self.left_align, self.right_align])

        self.connect("expose-event", self.__expose)

        self.__send_message("status", ("date_time", ""))

        SecondThread(self).start()
        DateThread(self).start()
    def __create_widget(self):
        '''create gtk widget'''
        title_item_font_size = TITLE_FONT_SIZE
        option_item_font_szie = CONTENT_FONT_SIZE

        self.label_widgets["speaker"] = Label(_("Speaker"), app_theme.get_color("globalTitleForeground"), text_size=title_item_font_size, enable_select=False, enable_double_click=False)
        self.label_widgets["microphone"] = Label(_("Microphone"), app_theme.get_color("globalTitleForeground"), text_size=title_item_font_size, enable_select=False, enable_double_click=False)
        self.label_widgets["left"] = Label(_("Left"), enable_select=False, enable_double_click=False)
        self.label_widgets["right"] = Label(_("Right"), enable_select=False, enable_double_click=False)
        self.label_widgets["speaker_port"] = Label(_("Output Port"), text_size=option_item_font_szie,
                                                   text_x_align=ALIGN_END, enable_select=False,
                                                   enable_double_click=False, fixed_width=STANDARD_LINE)
        self.label_widgets["speaker_volume"] = Label(_("Output Volume"), text_size=option_item_font_szie,
                                                     text_x_align=ALIGN_END, enable_select=False,
                                                     enable_double_click=False, fixed_width=STANDARD_LINE)
        self.label_widgets["speaker_mute"] = Label(_("Sound Enabled"), text_size=option_item_font_szie,
                                                   text_x_align=ALIGN_END, enable_select=False,
                                                   enable_double_click=False, fixed_width=STANDARD_LINE)
        self.label_widgets["speaker_balance"] = Label(_("Balance"), text_size=option_item_font_szie,
                                                      text_x_align=ALIGN_END, enable_select=False,
                                                      enable_double_click=False, fixed_width=STANDARD_LINE)
        self.label_widgets["microphone_port"] = Label(_("Input Port"), text_size=option_item_font_szie,
                                                      text_x_align=ALIGN_END, enable_select=False,
                                                      enable_double_click=False, fixed_width=STANDARD_LINE)
        self.label_widgets["microphone_volume"] = Label(_("Input Volume"), text_size=option_item_font_szie,
                                                        text_x_align=ALIGN_END, enable_select=False,
                                                        enable_double_click=False, fixed_width=STANDARD_LINE)
        self.label_widgets["microphone_mute"] = Label(_("Sound Enabled"), text_size=option_item_font_szie,
                                                      text_x_align=ALIGN_END, enable_select=False,
                                                      enable_double_click=False, fixed_width=STANDARD_LINE)
        #####################################
        # image init
        self.image_widgets["balance"] = ImageBox(app_theme.get_pixbuf("%s/balance.png" % MODULE_NAME))
        self.image_widgets["speaker"] = ImageBox(app_theme.get_pixbuf("%s/speaker-3.png" % MODULE_NAME))
        self.image_widgets["microphone"] = ImageBox(app_theme.get_pixbuf("%s/microphone.png" % MODULE_NAME))
        self.image_widgets["device"] = app_theme.get_pixbuf("%s/device.png" % MODULE_NAME)
        # button init
        self.button_widgets["balance"] = SwitchButton(
            inactive_disable_dpixbuf=app_theme.get_pixbuf("toggle_button/inactive_normal.png"), 
            active_disable_dpixbuf=app_theme.get_pixbuf("toggle_button/inactive_normal.png"))
        self.button_widgets["speaker"] = SwitchButton(
            inactive_disable_dpixbuf=app_theme.get_pixbuf("toggle_button/inactive_normal.png"), 
            active_disable_dpixbuf=app_theme.get_pixbuf("toggle_button/inactive_normal.png"))
        self.button_widgets["microphone"] = SwitchButton(
            inactive_disable_dpixbuf=app_theme.get_pixbuf("toggle_button/inactive_normal.png"), 
            active_disable_dpixbuf=app_theme.get_pixbuf("toggle_button/inactive_normal.png"))
        self.button_widgets["advanced"] = Button(_("Advanced"))
        self.button_widgets["speaker_combo"] = ComboBox(fixed_width=HSCALEBAR_WIDTH)
        self.button_widgets["microphone_combo"] = ComboBox(fixed_width=HSCALEBAR_WIDTH)
        # container init
        self.container_widgets["main_vbox"] = gtk.VBox(False)
        self.container_widgets["statusbar"] = StatusBar()
        self.container_widgets["slider"] = HSlider()
        self.container_widgets["swin"] = ScrolledWindow()
        self.container_widgets["advance_set_tab_box"] = TabBox()
        self.container_widgets["advance_set_tab_box"].draw_title_background = self.draw_tab_title_background
        self.container_widgets["main_hbox"] = gtk.HBox(False)
        self.container_widgets["left_vbox"] = gtk.VBox(False)
        self.container_widgets["right_vbox"] = gtk.VBox(False)
        self.container_widgets["balance_hbox"] = gtk.HBox(False)
        self.container_widgets["speaker_main_vbox"] = gtk.VBox(False)     # speaker
        self.container_widgets["speaker_label_hbox"] = gtk.HBox(False)
        self.container_widgets["speaker_table"] = gtk.Table(4, 2)
        self.container_widgets["microphone_main_vbox"] = gtk.VBox(False)     # microphone
        self.container_widgets["microphone_label_hbox"] = gtk.HBox(False)
        self.container_widgets["microphone_table"] = gtk.Table(4, 2)
        # alignment init
        self.alignment_widgets["slider"] = gtk.Alignment()
        self.alignment_widgets["main_hbox"] = gtk.Alignment()
        self.alignment_widgets["advance_set_tab_box"] = gtk.Alignment()
        self.alignment_widgets["left"] = gtk.Alignment()
        self.alignment_widgets["right"] = gtk.Alignment()
        self.alignment_widgets["speaker_label"] = gtk.Alignment()      # speaker
        self.alignment_widgets["speaker_set"] = gtk.Alignment()
        self.alignment_widgets["microphone_label"] = gtk.Alignment()      # microphone
        self.alignment_widgets["microphone_set"] = gtk.Alignment()
        # adjust init
        volume_max_percent = pypulse.MAX_VOLUME_VALUE * 100 / pypulse.NORMAL_VOLUME_VALUE
        self.adjust_widgets["balance"] = gtk.Adjustment(0, -1.0, 1.0, 0.1, 0.2)
        self.adjust_widgets["speaker"] = gtk.Adjustment(0, 0, volume_max_percent, 1, 5)
        self.adjust_widgets["microphone"] = gtk.Adjustment(0, 0, volume_max_percent, 1, 5)
        # scale init
        self.scale_widgets["balance"] = HScalebar(value_min=-1, value_max=1, gray_progress=True)
        self.scale_widgets["balance"].set_magnetic_values([(0, 0.1), (1, 0.1), (2, 0.1)])
        self.scale_widgets["speaker"] = HScalebar(show_value=True, format_value="%", value_min=0, value_max=volume_max_percent)
        self.scale_widgets["speaker"].set_magnetic_values([(0, 5), (100, 5), (volume_max_percent, 5)])
        self.scale_widgets["microphone"] = HScalebar(show_value=True, format_value="%", value_min=0, value_max=volume_max_percent)
        self.scale_widgets["microphone"].set_magnetic_values([(0, 5), (100, 5), (volume_max_percent, 5)])
        ###################################
        # advance set
        self.container_widgets["advance_input_box"] = gtk.VBox(False)
        self.container_widgets["advance_output_box"] = gtk.VBox(False)
        self.container_widgets["advance_hardware_box"] = gtk.VBox(False)
        self.alignment_widgets["advance_input_box"] = gtk.Alignment()
        self.alignment_widgets["advance_output_box"] = gtk.Alignment()
        self.alignment_widgets["advance_hardware_box"] = gtk.Alignment()
        #
        self.label_widgets["ad_output"] = Label(_("Choose a device for sound output:"), enable_select=False, enable_double_click=False)
        self.label_widgets["ad_input"] = Label(_("Choose a device for sound input:"), enable_select=False, enable_double_click=False)
        self.label_widgets["ad_hardware"] = Label(_("Choose a device to configure:"), enable_select=False, enable_double_click=False)
        #
        self.container_widgets["ad_output"] = gtk.VBox(False)
        self.container_widgets["ad_input"] = gtk.VBox(False)
        self.container_widgets["ad_hardware"] = gtk.VBox(False)
        #
        self.view_widgets["ad_output"] = TreeView()
        self.view_widgets["ad_input"] = TreeView()
        self.view_widgets["ad_hardware"] = TreeView()
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)
Example #36
0
    def init_table(self):

        table = gtk.Table(8, 3, False)

        #info_label = Label(_("You can choose the operation after plugining media or device"))

        cd_label = Label(_("CD"))
        dvd_label = Label(_("DVD"))
        player_label = Label(_("Audio Player"))
        photo_label = Label(_("Camera"))
        software_label = Label(_("Applications"))
        auto_mount_label = Label(_("Automatically Mount"))

        self.all_label_list = [cd_label, dvd_label, player_label,
                               photo_label, software_label]

        default_list = [(_("Other applications"), "other_app"),
                        (_("Ask"), "ask"),
                        (_("Do nothing"), "do_nothing"),
                        (_("Open folder"),"open_folder")]
        auto_mount_list = [(_("Do nothing"), "do_nothing"), 
                           (_("Ask"), "ask"),
                           (_("Mount"), "mount"),
                           (_("Mount and open folder"), "mount_and_open")]
        #self.auto_mount_box = gtk.HBox(spacing = WIDGET_SPACING)
        #self.auto_mount_label = Label(_("apply auto open for all media and devices"))
        self.auto_mount_label = Label(_("AutoPlay"))
        self.auto_mount_toggle = ToggleButton(app_theme.get_pixbuf("toggle_button/inactive_normal.png"), 
            app_theme.get_pixbuf("toggle_button/active_normal.png"))
        #self.auto_mount_box.pack_start(self.auto_mount_label, False, False)
        #self.auto_mount_box.pack_start(self.auto_mount_toggle, False, False)

        self.cd = ComboBox(default_list, fixed_width=self.ENTRY_WIDTH)
        self.dvd = ComboBox(default_list, fixed_width=self.ENTRY_WIDTH)
        self.player= ComboBox(default_list, fixed_width=self.ENTRY_WIDTH)
        self.photo = ComboBox(default_list, fixed_width=self.ENTRY_WIDTH)
        self.software = ComboBox(default_list, fixed_width=self.ENTRY_WIDTH)
        self.auto_mount = ComboBox(auto_mount_list, fixed_width=self.ENTRY_WIDTH)
        self.auto_mount.set_select_index(self.__get_index_from_value(get_auto_mount(), auto_mount_list))
        #self.more_option = Button(_("more option"))

        ###below content type displayed as more option is clicked"
        self.audio_dvd = ComboBox(default_list, fixed_width=self.ENTRY_WIDTH)
        self.blank_bd = ComboBox(default_list, fixed_width=self.ENTRY_WIDTH)
        self.blank_cd = ComboBox(default_list, fixed_width=self.ENTRY_WIDTH)
        self.blank_hddvd = ComboBox(default_list, fixed_width=self.ENTRY_WIDTH)
        self.video_bluray = ComboBox(default_list, fixed_width=self.ENTRY_WIDTH)
        self.ebook_reader = ComboBox(default_list, fixed_width=self.ENTRY_WIDTH)
        self.video_hddvd = ComboBox(default_list, fixed_width=self.ENTRY_WIDTH)
        self.image_picturecd = ComboBox(default_list, fixed_width=self.ENTRY_WIDTH)
        self.video_svcd = ComboBox(default_list, fixed_width=self.ENTRY_WIDTH)
        self.video_vcd = ComboBox(default_list, fixed_width=self.ENTRY_WIDTH)

        #table.attach(style.wrap_with_align(info_label, width=self.LEFT_WIDTH), 0, 3, 0, 1)
        table.attach(style.wrap_with_align(cd_label, width=self.LEFT_WIDTH), 0, 1, 4, 5)
        table.attach(style.wrap_with_align(dvd_label, width=self.LEFT_WIDTH), 0, 1, 5, 6)
        table.attach(style.wrap_with_align(player_label, width=self.LEFT_WIDTH), 0, 1, 6, 7)
        table.attach(style.wrap_with_align(photo_label, width=self.LEFT_WIDTH), 0, 1, 7, 8)
        table.attach(style.wrap_with_align(software_label, width=self.LEFT_WIDTH), 0, 1, 8, 9)
        table.attach(style.wrap_with_align(auto_mount_label, width=self.LEFT_WIDTH), 0, 1, 9, 10)

        #table.attach(style.wrap_with_align(self.auto_mount_box, align = "left", left = 180), 0, 3, 1, 2)
        table.attach(style.wrap_with_align(self.auto_mount_label, width=self.LEFT_WIDTH), 0, 1, 1, 2)
        table.attach(style.wrap_with_align(self.auto_mount_toggle), 1, 3, 1, 2)

        table.attach(style.wrap_with_align(self.cd), 1, 3, 4, 5)
        table.attach(style.wrap_with_align(self.dvd), 1, 3, 5, 6)
        table.attach(style.wrap_with_align(self.player), 1, 3, 6, 7)
        table.attach(style.wrap_with_align(self.photo), 1, 3, 7, 8)
        table.attach(style.wrap_with_align(self.software), 1, 3, 8, 9)
        table.attach(style.wrap_with_align(self.auto_mount), 1, 3, 9, 10)

        # UI style
        table_align = style.set_box_with_align(table, "text")
        style.set_table(table)

        self.pack_start(table_align, False, False)

        combo_list = [self.cd, self.dvd, self.player, self.photo, self.software]
        for combo in combo_list:
            combo.set_size_request(self.ENTRY_WIDTH, 22)

        self.refresh_app_list(default_list)

        self.media_handle.auto_mount = True
        if self.media_handle.automount_open:
            for combo in self.all_app_dict:
                combo.set_sensitive(True)
            for l in self.all_label_list:
                l.set_sensitive(True)
        else:
            for combo in self.all_app_dict:
                combo.set_sensitive(False)
            for l in self.all_label_list:
                l.set_sensitive(False)
    
        self.auto_mount_toggle.set_active(self.media_handle.automount_open)

        self.connect_signal_to_combos()
    def add_toolbar(self):

        toolbar_btn_box = gtk.HBox()
        toolbar_btn_box_align = gtk.Alignment(0.5, 0.5, 0, 0)

        import_btn = ToolbarItem(self.import_btn_pixbuf, _("Import"))
        import_btn.connect("clicked", self.on_toolbar_import_clicked)
        export_btn = ToolbarItem(self.export_btn_pixbuf, _("Export"))
        export_btn.connect("clicked", self.on_toolbar_export_clicked)
        delete_btn = ToolbarItem(self.delete_btn_pixbuf, _("Delete"))
        delete_btn.connect("clicked", self.on_toolbar_delete_clicked)
        refresh_btn = ToolbarItem(self.refresh_btn_pixbuf, _("Refresh"))
        refresh_btn.connect("clicked", self.on_toolbar_refresh_clicked)

        toolbar_btn_box.pack_start(import_btn, False, False, 2)
        toolbar_btn_box.pack_start(export_btn, False, False, 2)
        toolbar_btn_box.pack_start(delete_btn, False, False, 2)
        toolbar_btn_box.pack_start(refresh_btn, False, False, 2)
        toolbar_btn_box_align.add(toolbar_btn_box)

        look_in_Label = Label(
            _("Look up in"),
            text_color=ui_theme.get_color("title_text"),
            )

        self.category_comb = ComboBox([(_("All"), 0)])
        self.category_comb.add_items([(item, index) for index, item in enumerate(self.classified_items)], clear_first=False)
        self.time_comb = ComboBox([(_("Today"), 0),
                                   (_("Last week"), 1),
                                   (_("Last month"), 2),
                                   (_("Last three months"), 3),
                                   (_("Last year"), 4),
                                   (_("All"), 5)
                                   ])

        self.category_comb.set_size_request(-1, TOOLBAR_ENTRY_HEIGHT)
        self.category_comb.connect("item-selected", self.on_category_comb_item_selected)
        self.time_comb.set_size_request(-1, TOOLBAR_ENTRY_HEIGHT)
        self.time_comb.connect("item-selected", self.on_time_comb_item_selected)
        combos_box = gtk.HBox()
        combos_box.pack_start(self.category_comb, False, False, 5)
        combos_box.pack_start(self.time_comb, False, False)

        combos_box_align = gtk.Alignment(0.5, 0.5, 1, 1)
        padding_height = (TOOLBAR_HEIGHT - TOOLBAR_ENTRY_HEIGHT) / 2
        combos_box_align.set_padding(padding_height, padding_height, 5, 5)
        combos_box_align.add(combos_box)


        find_content_Label = Label(
            _("Find in content"),
            text_color=ui_theme.get_color("title_text"),
            )


        search_entry = SearchEntry()
        search_entry.connect("action-active", self.on_search_entry_action_active)
        search_entry_align = gtk.Alignment(0.5, 0.5, 1, 1)
        search_entry_align.set_padding(padding_height, padding_height, 5, 5)
        search_entry_align.add(search_entry)

        #Align left
        self.toolbar_box.pack_start(toolbar_btn_box_align, False, False, 5)

        #Align right
        self.toolbar_box.pack_end(search_entry_align, False, True, 5)
        self.toolbar_box.pack_end(find_content_Label, False, False, 5)
        self.toolbar_box.pack_end(combos_box_align, False, False, 0)
        self.toolbar_box.pack_end(look_in_Label, False, False, 5)
        self.toolbar_box.pack_end(ToolbarSep(), False, False, 5)
    def __init__(self):
        super(EqualizerWindow, self).__init__(
            _("Equalizer"),
            372,
            168,
            DIALOG_MASK_SINGLE_PAGE,
            close_callback=self.hide_all,
            modal=False,
            window_hint=None,
            skip_taskbar_hint=False,
        )

        self.manual_flag = False

        try:
            pre_value = float(config.get("equalizer", "preamp"))
        except:
            pre_value = 0.6

        pre_adjust = gtk.Adjustment(value=pre_value, lower=-10, upper=10, step_incr=0.1, page_incr=1, page_size=0)
        self.preamp_scale = PreampScalebar()
        self.preamp_scale.scalebar.set_adjustment(pre_adjust)
        pre_adjust.connect("value-changed", self.preamp_change)

        self.connect("configure-event", self.equalizer_configure_event)
        control_box = gtk.HBox(spacing=10)
        control_box.pack_start(self.preamp_scale, False, False)
        self.__scales = {}

        for i, label in enumerate(["32", "64", "125", "250", "500", "1k", "2k", "4k", "8k", "16k"]):
            slipper_scale = SlipperScalebar(label)
            try:
                value = float(config.get("equalizer", "equalizer-band%s" % str(i)))
            except:
                value = 0.0

            adjust = gtk.Adjustment(value=value, lower=-12, upper=12, step_incr=0.1, page_incr=1, page_size=0)
            adjust.changed_id = adjust.connect("value-changed", self.__on_adjust_change, i)
            slipper_scale.scalebar.set_adjustment(adjust)
            self.__scales[i] = slipper_scale.scalebar
            control_box.pack_start(slipper_scale, False, False)

        try:
            self.__equalizer = gst.element_factory_make("equalizer-10bands")
        except gst.PluginNotFoundError:
            self.__equalizer = None
            self.logerror("Equalizer support requires gstreamer-plugins-bad (>= 0.10.5)")
        else:
            Player.bin.xfade_add_filter(self.__equalizer)
            for i in range(0, 10):
                try:
                    value = float(config.get("equalizer", "equalizer-band%s" % str(i)))
                except:
                    value = 0

                self.__equalizer.set_property("band" + str(i), float(value))

            Player.bin.connect("tee-removed", self.__on_remove)
            config.connect("config-changed", self.__on_config_change)

        self.active_button = Button(_("Close"))
        self.active_button.connect("clicked", self.hide_win)
        self.reset_button = Button(_("Reset"))
        self.reset_button.connect("clicked", self.set_default_value)
        self.predefine_button = Button(_("Predefined"))
        self.predefine_button.connect("clicked", self.show_predefine)

        self.predefine_combo_box = ComboBox(
            [(value, key) for key, value in mandatory_i18n.items()], 250, select_index=self.get_selected_index()
        )
        self.predefine_combo_box.connect("item-selected", self.set_predefine_value)

        control_box_align = gtk.Alignment()
        control_box_align.set(0.0, 0.0, 1.0, 1.0)
        control_box_align.set_padding(10, 20, 15, 15)
        control_box_align.add(control_box)

        main_align = gtk.Alignment()
        main_align.set(0.0, 0.0, 1.0, 1.0)
        main_align.set_padding(0, 5, 2, 2)
        main_box = gtk.VBox(spacing=5)
        main_align.add(main_box)

        main_box.add(control_box_align)

        self.body_box.pack_start(main_align, True, True)
        self.left_button_box.set_buttons([self.predefine_combo_box])
        self.right_button_box.set_buttons([self.reset_button, self.active_button])
class EqualizerWindow(DialogBox):
    def __init__(self):
        super(EqualizerWindow, self).__init__(
            _("Equalizer"),
            372,
            168,
            DIALOG_MASK_SINGLE_PAGE,
            close_callback=self.hide_all,
            modal=False,
            window_hint=None,
            skip_taskbar_hint=False,
        )

        self.manual_flag = False

        try:
            pre_value = float(config.get("equalizer", "preamp"))
        except:
            pre_value = 0.6

        pre_adjust = gtk.Adjustment(value=pre_value, lower=-10, upper=10, step_incr=0.1, page_incr=1, page_size=0)
        self.preamp_scale = PreampScalebar()
        self.preamp_scale.scalebar.set_adjustment(pre_adjust)
        pre_adjust.connect("value-changed", self.preamp_change)

        self.connect("configure-event", self.equalizer_configure_event)
        control_box = gtk.HBox(spacing=10)
        control_box.pack_start(self.preamp_scale, False, False)
        self.__scales = {}

        for i, label in enumerate(["32", "64", "125", "250", "500", "1k", "2k", "4k", "8k", "16k"]):
            slipper_scale = SlipperScalebar(label)
            try:
                value = float(config.get("equalizer", "equalizer-band%s" % str(i)))
            except:
                value = 0.0

            adjust = gtk.Adjustment(value=value, lower=-12, upper=12, step_incr=0.1, page_incr=1, page_size=0)
            adjust.changed_id = adjust.connect("value-changed", self.__on_adjust_change, i)
            slipper_scale.scalebar.set_adjustment(adjust)
            self.__scales[i] = slipper_scale.scalebar
            control_box.pack_start(slipper_scale, False, False)

        try:
            self.__equalizer = gst.element_factory_make("equalizer-10bands")
        except gst.PluginNotFoundError:
            self.__equalizer = None
            self.logerror("Equalizer support requires gstreamer-plugins-bad (>= 0.10.5)")
        else:
            Player.bin.xfade_add_filter(self.__equalizer)
            for i in range(0, 10):
                try:
                    value = float(config.get("equalizer", "equalizer-band%s" % str(i)))
                except:
                    value = 0

                self.__equalizer.set_property("band" + str(i), float(value))

            Player.bin.connect("tee-removed", self.__on_remove)
            config.connect("config-changed", self.__on_config_change)

        self.active_button = Button(_("Close"))
        self.active_button.connect("clicked", self.hide_win)
        self.reset_button = Button(_("Reset"))
        self.reset_button.connect("clicked", self.set_default_value)
        self.predefine_button = Button(_("Predefined"))
        self.predefine_button.connect("clicked", self.show_predefine)

        self.predefine_combo_box = ComboBox(
            [(value, key) for key, value in mandatory_i18n.items()], 250, select_index=self.get_selected_index()
        )
        self.predefine_combo_box.connect("item-selected", self.set_predefine_value)

        control_box_align = gtk.Alignment()
        control_box_align.set(0.0, 0.0, 1.0, 1.0)
        control_box_align.set_padding(10, 20, 15, 15)
        control_box_align.add(control_box)

        main_align = gtk.Alignment()
        main_align.set(0.0, 0.0, 1.0, 1.0)
        main_align.set_padding(0, 5, 2, 2)
        main_box = gtk.VBox(spacing=5)
        main_align.add(main_box)

        main_box.add(control_box_align)

        self.body_box.pack_start(main_align, True, True)
        self.left_button_box.set_buttons([self.predefine_combo_box])
        self.right_button_box.set_buttons([self.reset_button, self.active_button])

    def set_default_value(self, widget):
        self.predefine_combo_box.set_select_index(1)
        self.__change("Default")
        self.preamp_scale.scalebar.set_value(0.6)

    def db_to_percent(self, dB):
        return 10 ** (dB / 10)

    def preamp_change(self, adjust):

        config.set("equalizer", "preamp", str(adjust.get_value()))
        Player.volume = self.db_to_percent(adjust.get_value())

    def __on_remove(self, bin, tee, element):
        if element != self.__equalizer:
            return
        self.__equalizer.set_state(gst.STATE_NULL)
        self.__equalizer = None

    def __on_config_change(self, dispacher, section, option, value):
        if section == "equalizer" and option.find("equalizer-band") == 0:
            band_name = option.replace("equalizer-", "")
            self.__equalizer.set_property(band_name, float(value))

    def equalizer_configure_event(self, widget, event):
        if widget.get_property("visible"):
            if widget.get_resizable():
                config.set("equalizer", "width", "%d" % event.width)
                config.set("equalizer", "height", "%d" % event.height)
            config.set("equalizer", "x", "%d" % event.x)
            config.set("equalizer", "y", "%d" % event.y)

    def hide_win(self, widget):
        self.hide_all()

    def __select_name(self):
        self.menu_dict = OrderedDict()
        for name in MANDATORY.keys():
            self.menu_dict[name] = [None, name, self.__change, name]

        values = []
        for i in range(0, 10):
            try:
                value = int(float(config.get("equalizer", "equalizer-band%s" % str(i))))
            except:
                value = 0
            values.append(str(value))
        values = ":".join(values)

        self.has_tick = False
        for name, value in MANDATORY.iteritems():
            value = value.split(":")
            value = ":".join([str(int(float(v))) for v in value])

            if value == values:
                self.menu_dict[name][0] = (
                    app_theme.get_pixbuf("menu/tick.png"),
                    app_theme.get_pixbuf("menu/tick_press.png"),
                )
                self.has_tick = True
        if not self.has_tick:
            self.menu_dict[MANDATORY_CUSTOM][0] = (
                app_theme.get_pixbuf("menu/tick.png"),
                app_theme.get_pixbuf("menu/tick_press.png"),
            )

    def get_selected_index(self):
        values = []
        for i in range(0, 10):
            try:
                value = int(float(config.get("equalizer", "equalizer-band%s" % str(i))))
            except:
                value = 0
            values.append(str(value))
        values = ":".join(values)

        for index, value in enumerate(MANDATORY.values()):
            value = value.split(":")
            value = ":".join([str(int(float(v))) for v in value])

            if value == values:
                return index
        return 0

    def set_predefine_value(self, widget, label, allocated_data, index):
        self.__change(allocated_data)

    def show_predefine(self, widget):
        self.__select_name()
        menu_items = self.menu_dict.values()
        menu_items.insert(2, None)
        Menu(menu_items, True).show(get_widget_root_coordinate(widget))

    def __on_adjust_change(self, adjust, i):
        if not self.manual_flag:
            self.predefine_combo_box.set_select_index(0)
        config.set("equalizer", "equalizer-band%s" % str(i), str(adjust.get_value()))
        self.manual_flag = False

    def __save(self, *args):
        text = self.predefine_button.get_label()

        if text in MANDATORY.keys():
            return
        values = []
        for i in range(0, 10):
            try:
                value = float(config.get("equalizer", "equalizer-band%s" % str(i)))
            except:
                value = 0.0
            values.append(str(value))

    def __change(self, name):
        if name == MANDATORY_CUSTOM:
            self.predefine_combo_box.set_select_index(0)
            return True

        self.manual_flag = True
        if name in MANDATORY.keys():
            values = MANDATORY[name].split(":")

            for i, value in enumerate(values):
                adj = self.__scales[i].get_adjustment()
                adj.handler_block(adj.changed_id)
                self.__scales[i].set_value(float(value))
                config.set("equalizer", "equalizer-band%s" % str(i), str(float(value)))
                adj.handler_unblock(adj.changed_id)
        return True

    def run(self):
        if config.get("equalizer", "x") == "-1":
            self.set_position(gtk.WIN_POS_CENTER)
        else:
            self.move(int(config.get("equalizer", "x")), int(config.get("equalizer", "y")))
        self.show_all()
Example #40
0
    def __init__(self, connection, set_button_callback, settings_obj=None):
        gtk.VBox.__init__(self)
        self.tab_name = _("Broadband")
        self.connection = connection        
        self.set_button = set_button_callback
        # 新增settings_obj变量,用于访问shared_methods.Settings对象
        self.settings_obj = settings_obj

        # Init widgets
        self.table = gtk.Table(12, 4, False)
        
        #self.label_basic = Label(_("Basic"), text_size = TITLE_FONT_SIZE)
        self.label_basic = TitleBar(None, _("Basic"))
        self.label_number = Label(_("Code:"), text_size=CONTENT_FONT_SIZE,
                               enable_select=False,
                               enable_double_click=False)
        self.label_username = Label(_("Username:"******"Password:"******"Show password"), padding_x=0)
        self.button_to_region = Button(_("Regions setting"))


        #self.table = gtk.Table(6, 4, False)
        self.label_advanced = TitleBar(None,_("Advanced"))
        self.label_apn = Label(_("APN:"), text_size=CONTENT_FONT_SIZE,
                               enable_select=False,
                               enable_double_click=False)
        self.label_network = Label(_("Network ID:"), text_size=CONTENT_FONT_SIZE,
                               enable_select=False,
                               enable_double_click=False)
        self.label_type = Label(_("Type:"), text_size=CONTENT_FONT_SIZE,
                               enable_select=False,
                               enable_double_click=False)
        self.label_pin = Label(_("PIN:"), text_size=CONTENT_FONT_SIZE,
                               enable_select=False,
                               enable_double_click=False)

        self.apn = InputEntry()
        self.network_id = InputEntry()
        self.network_type = ComboBox([("Any", None),
                                      ("3G", 0),
                                      ("2G", 1),
                                      ("Prefer 3G", 2),
                                      ("Prefer 2G", 3)],
                                      fixed_width=self.ENTRY_WIDTH)
        self.roam_check = CheckButton(_("Allow roaming if home network is not available"), padding_x=0)
        self.pin = InputEntry()
        
        
        # Connect signals
        self.number.entry.connect("changed", self.save_settings_by, "number")
        self.username.entry.connect("changed", self.save_settings_by, "username")
        self.password.entry.connect("changed", self.save_settings_by, "password")
        self.apn.entry.connect("changed", self.save_settings_by, "apn")
        self.network_id.entry.connect("changed", self.save_settings_by, "network_id")
        self.network_type.connect("item-selected", self.network_type_selected)

        self.password_show.connect("toggled", self.password_show_toggled)
        self.roam_check.connect("toggled", self.roam_check_toggled)


        table_align = gtk.Alignment(0, 0, 0, 0)
        table_align.add(self.table)
        self.pack_start(table_align)

        # wrap with alignment
        
        # Refesh
        self.refresh()
Example #41
0
    # Add entry widget.
    entry_box = gtk.HBox(spacing=10)

    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)
Example #42
0
class MediaView(gtk.VBox):
    ENTRY_WIDTH = 200
    LEFT_WIDTH = STANDARD_LINE - TEXT_WINDOW_LEFT_PADDING

    def __init__(self):
        gtk.VBox.__init__(self)
        self.all_app_default_value = {}
        style.draw_background_color(self)
        self.media_handle = MediaAutorun()
        self.app_manager = AppManager()
        self.init_table()
        
    def __get_index_from_value(self, value, _list):
        for tup in _list:
            if tup[1] == value:
                return _list.index(tup)

    def init_table(self):

        table = gtk.Table(8, 3, False)

        #info_label = Label(_("You can choose the operation after plugining media or device"))

        cd_label = Label(_("CD"))
        dvd_label = Label(_("DVD"))
        player_label = Label(_("Audio Player"))
        photo_label = Label(_("Camera"))
        software_label = Label(_("Applications"))
        auto_mount_label = Label(_("Automatically Mount"))

        self.all_label_list = [cd_label, dvd_label, player_label,
                               photo_label, software_label]

        default_list = [(_("Other applications"), "other_app"),
                        (_("Ask"), "ask"),
                        (_("Do nothing"), "do_nothing"),
                        (_("Open folder"),"open_folder")]
        auto_mount_list = [(_("Do nothing"), "do_nothing"), 
                           (_("Ask"), "ask"),
                           (_("Mount"), "mount"),
                           (_("Mount and open folder"), "mount_and_open")]
        #self.auto_mount_box = gtk.HBox(spacing = WIDGET_SPACING)
        #self.auto_mount_label = Label(_("apply auto open for all media and devices"))
        self.auto_mount_label = Label(_("AutoPlay"))
        self.auto_mount_toggle = ToggleButton(app_theme.get_pixbuf("toggle_button/inactive_normal.png"), 
            app_theme.get_pixbuf("toggle_button/active_normal.png"))
        #self.auto_mount_box.pack_start(self.auto_mount_label, False, False)
        #self.auto_mount_box.pack_start(self.auto_mount_toggle, False, False)

        self.cd = ComboBox(default_list, fixed_width=self.ENTRY_WIDTH)
        self.dvd = ComboBox(default_list, fixed_width=self.ENTRY_WIDTH)
        self.player= ComboBox(default_list, fixed_width=self.ENTRY_WIDTH)
        self.photo = ComboBox(default_list, fixed_width=self.ENTRY_WIDTH)
        self.software = ComboBox(default_list, fixed_width=self.ENTRY_WIDTH)
        self.auto_mount = ComboBox(auto_mount_list, fixed_width=self.ENTRY_WIDTH)
        self.auto_mount.set_select_index(self.__get_index_from_value(get_auto_mount(), auto_mount_list))
        #self.more_option = Button(_("more option"))

        ###below content type displayed as more option is clicked"
        self.audio_dvd = ComboBox(default_list, fixed_width=self.ENTRY_WIDTH)
        self.blank_bd = ComboBox(default_list, fixed_width=self.ENTRY_WIDTH)
        self.blank_cd = ComboBox(default_list, fixed_width=self.ENTRY_WIDTH)
        self.blank_hddvd = ComboBox(default_list, fixed_width=self.ENTRY_WIDTH)
        self.video_bluray = ComboBox(default_list, fixed_width=self.ENTRY_WIDTH)
        self.ebook_reader = ComboBox(default_list, fixed_width=self.ENTRY_WIDTH)
        self.video_hddvd = ComboBox(default_list, fixed_width=self.ENTRY_WIDTH)
        self.image_picturecd = ComboBox(default_list, fixed_width=self.ENTRY_WIDTH)
        self.video_svcd = ComboBox(default_list, fixed_width=self.ENTRY_WIDTH)
        self.video_vcd = ComboBox(default_list, fixed_width=self.ENTRY_WIDTH)

        #table.attach(style.wrap_with_align(info_label, width=self.LEFT_WIDTH), 0, 3, 0, 1)
        table.attach(style.wrap_with_align(cd_label, width=self.LEFT_WIDTH), 0, 1, 4, 5)
        table.attach(style.wrap_with_align(dvd_label, width=self.LEFT_WIDTH), 0, 1, 5, 6)
        table.attach(style.wrap_with_align(player_label, width=self.LEFT_WIDTH), 0, 1, 6, 7)
        table.attach(style.wrap_with_align(photo_label, width=self.LEFT_WIDTH), 0, 1, 7, 8)
        table.attach(style.wrap_with_align(software_label, width=self.LEFT_WIDTH), 0, 1, 8, 9)
        table.attach(style.wrap_with_align(auto_mount_label, width=self.LEFT_WIDTH), 0, 1, 9, 10)

        #table.attach(style.wrap_with_align(self.auto_mount_box, align = "left", left = 180), 0, 3, 1, 2)
        table.attach(style.wrap_with_align(self.auto_mount_label, width=self.LEFT_WIDTH), 0, 1, 1, 2)
        table.attach(style.wrap_with_align(self.auto_mount_toggle), 1, 3, 1, 2)

        table.attach(style.wrap_with_align(self.cd), 1, 3, 4, 5)
        table.attach(style.wrap_with_align(self.dvd), 1, 3, 5, 6)
        table.attach(style.wrap_with_align(self.player), 1, 3, 6, 7)
        table.attach(style.wrap_with_align(self.photo), 1, 3, 7, 8)
        table.attach(style.wrap_with_align(self.software), 1, 3, 8, 9)
        table.attach(style.wrap_with_align(self.auto_mount), 1, 3, 9, 10)

        # UI style
        table_align = style.set_box_with_align(table, "text")
        style.set_table(table)

        self.pack_start(table_align, False, False)

        combo_list = [self.cd, self.dvd, self.player, self.photo, self.software]
        for combo in combo_list:
            combo.set_size_request(self.ENTRY_WIDTH, 22)

        self.refresh_app_list(default_list)

        self.media_handle.auto_mount = True
        if self.media_handle.automount_open:
            for combo in self.all_app_dict:
                combo.set_sensitive(True)
            for l in self.all_label_list:
                l.set_sensitive(True)
        else:
            for combo in self.all_app_dict:
                combo.set_sensitive(False)
            for l in self.all_label_list:
                l.set_sensitive(False)
    
        self.auto_mount_toggle.set_active(self.media_handle.automount_open)

        self.connect_signal_to_combos()

    def refresh_app_list(self, default_list):
        self.default_list = default_list
        self.all_app_dict = {self.cd: self.media_handle.cd_content_type,
                             self.dvd: self.media_handle.dvd_content_type,
                             self.player: self.media_handle.player_content_type,
                             self.photo: self.media_handle.photo_content_type,
                             self.software: self.media_handle.software_content_type,
                             }

        for key, value in self.all_app_dict.iteritems():
            app_info_list = []
            app_info_list.extend(self.app_manager.get_all_for_type(value))
            
            state = self.get_state(value)
            if state == "set_default":
                default_value = 0
            else:
                default_value = len(app_info_list) + ["ask", "do_nothing","open_folder"].index(state) + 1

            key.add_items(map(lambda info:(info.get_name(), info), app_info_list) + default_list, select_index=default_value)

        self.all_app_default_value = {self.cd: self.cd.get_select_index(), 
                                      self.dvd: self.dvd.get_select_index(), 
                                      self.player: self.player.get_select_index(), 
                                      self.photo: self.photo.get_select_index(), 
                                      self.software: self.software.get_select_index(),
                                     }

    def connect_signal_to_combos(self):
        for combo in self.all_app_dict:
            combo.connect("item-selected", self.change_autorun_callback)
        self.auto_mount.connect("item-selected", self.auto_mount_combo_changed)
        self.auto_mount_toggle.connect("toggled", self.automount_open_toggle_cb)
        
    def auto_mount_combo_changed(self, widget, content, value, index):
        set_auto_mount(value)

    def change_autorun_callback(self, widget, content, value, index):
        if value != "other_app":
            self.all_app_default_value[widget] = index
        if type(value) is not str:
            self.set_media_handler_preference(self.all_app_dict[widget], widget, "set_default")
            self.app_manager.set_default_for_type(value, self.all_app_dict[widget])
        else:
            self.set_media_handler_preference(self.all_app_dict[widget], widget, value)

    def automount_open_toggle_cb(self, widget):
        self.media_handle.automount_open = widget.get_active()
        
        if widget.get_active():
            for combo in self.all_app_dict:
                combo.set_sensitive(True)
            for l in self.all_label_list:
                l.set_sensitive(True)
        else:
            for combo in self.all_app_dict:
                combo.set_sensitive(False)
            for l in self.all_label_list:
                l.set_sensitive(False)

    def set_media_handler_preference(self, x_content, widget, action_name=None):
        if action_name == "ask":
            self.media_handle.remove_x_content_start_app(x_content)
            self.media_handle.remove_x_content_ignore(x_content)
            self.media_handle.remove_x_content_open_folder(x_content)
            print action_name, ">>>",self.get_state(x_content)

        elif action_name == "do_nothing":
            self.media_handle.remove_x_content_start_app(x_content)
            self.media_handle.add_x_content_ignore(x_content)
            self.media_handle.remove_x_content_open_folder(x_content)
            print action_name, ">>>",self.get_state(x_content)

        elif action_name == "open_folder":
            self.media_handle.remove_x_content_start_app(x_content)
            self.media_handle.remove_x_content_ignore(x_content)
            self.media_handle.add_x_content_open_folder(x_content)
            print action_name, ">>>",self.get_state(x_content)

        elif action_name == "set_default":
            self.media_handle.add_x_content_start_app(x_content)
            self.media_handle.remove_x_content_ignore(x_content)
            self.media_handle.remove_x_content_open_folder(x_content)
            print action_name, ">>>",self.get_state(x_content)
        else:
            from dtk.ui.dialog import OpenFileDialog
            OpenFileDialog(
                _("Other applications"), 
                self.get_toplevel(), 
                lambda name: self.add_app_info(name, x_content), 
                self.__cancel_other_application(widget))

    def __cancel_other_application(self, widget):
        widget.set_select_index(self.all_app_default_value[widget])

    def add_app_info(self, app_name, x_content):
        import os
        app_name = os.path.basename(app_name)
        app_info = self.app_manager.get_app_info(app_name + " %u", app_name)
        self.set_media_handler_preference(x_content, "set_default")
        self.app_manager.set_default_for_type(app_info, x_content)
        self.app_manager.get_all_for_type(x_content)
        self.refresh_app_list(self.default_list)

    def get_state(self, x_content):
        start_up = self.media_handle.autorun_x_content_start_app
        ignore = self.media_handle.autorun_x_content_ignore
        open_folder = self.media_handle.autorun_x_content_open_folder

        start_up_flag = x_content in start_up
        ignore_flag = x_content in ignore
        open_folder_flag = x_content in open_folder

        if start_up_flag:
            return "set_default"
        elif ignore_flag:
            return "do_nothing"
        elif open_folder_flag:
            return "open_folder"
        else:
            return "ask"
 def __setup_combo(self, items=[], width=HSCALEBAR_WIDTH):
     combo = ComboBox(items, None, 0, width, width)
     combo.set_size_request(width, WIDGET_HEIGHT)
     return combo
Example #44
0
class GeneralBox(BaseBox):
    def __init__(self):
        BaseBox.__init__(self)

        self.main_box.pack_start(self.create_uninstall_box(), False, True)
        self.main_box.pack_start(self.create_download_dir_table(), False, True)

    def create_uninstall_box(self):
        main_table = gtk.Table(2, 2)
        main_table.set_row_spacings(CONTENT_ROW_SPACING)
        uninstall_title_label = Label(_("On uninstalling the software"))

        # 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)
        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 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(_('Maximum number of download tasks: '))
        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)
        main_table.attach(create_separator_box(), 0, 2, 1, 2, yoptions=gtk.FILL)
        main_table.attach(download_number_hbox, 0, 2, 2, 3, xoptions=gtk.FILL)
        main_table.attach(download_dir_hbox, 0, 2, 3, 4, xoptions=gtk.FILL)
        return main_table

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

    def change_download_save_dir(self, widget):
        local_dir = FolderChooseDialog(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')