def __init__(self): """ init docs """ gtk.VBox.__init__(self) self.__background_settings = deepin_gsettings.new("com.deepin.dde.background") self.draw_title_background = self.draw_tab_title_background self.theme = None self.wallpaper_box = gtk.VBox() self.window_theme_box = gtk.VBox() self.wallpaper_view = WallpaperView(padding_x=30, padding_y=ITEM_PADDING_Y) self.wallpaper_view_sw = self.wallpaper_view.get_scrolled_window() self.wallpaper_view_sw.set_size_request(-1, 426) position_group, self.position_combobox = get_combo_group( _("Position"), DRAW_COMBO_ITEM, self.on_position_combox_selected ) time_group, self.time_combobox = get_combo_group(_("Duration"), TIME_COMBO_ITEM, self.on_time_combox_selected) self.__is_random = True if self.__background_settings.get_int("background-duration") == 0: self.__is_random = False self.unorder_play, self.random_toggle = get_toggle_group( _("Random"), self.__on_random_toggled, self.__is_random ) self.button_align = gtk.Alignment() self.button_box = gtk.HBox(spacing=5) self.select_all_button = Button(_("Select all")) self.select_all_button.set_size_request(80, WIDGET_HEIGHT) self.select_all_button.connect("clicked", self.__on_select_all) self.delete_button = Button(_("Delete")) self.delete_button.set_size_request(80, WIDGET_HEIGHT) self.delete_button.connect("clicked", self.__on_delete) self.button_box.pack_start(self.select_all_button, False, False) self.button_box.pack_start(self.delete_button, False, False) self.button_align.add(self.button_box) self.action_bar = gtk.HBox(spacing=26) self.action_bar.pack_start(position_group, False, False) self.action_bar.pack_start(time_group, False, False) self.action_bar.pack_start(self.unorder_play, False, False) self.action_bar.pack_end(self.button_align, False, False) action_bar_align = gtk.Alignment() action_bar_align.set_size_request(-1, STATUS_HEIGHT) action_bar_align.set_padding(5, 5, 50, 20) action_bar_align.add(self.action_bar) self.wallpaper_box.pack_start(self.wallpaper_view_sw, True, True) self.wallpaper_box.pack_start(action_bar_align, False, False) self.pack_start(self.wallpaper_box, False, False) event_manager.add_callback("select-wallpaper", self.on_wallpaper_select) event_manager.add_callback("apply-wallpaper", self.__on_wallpaper_apply) event_manager.add_callback("add-wallpapers", self.__on_add_wallpapers)
def __init__(self): ''' init docs ''' gtk.VBox.__init__(self) self.__background_settings = deepin_gsettings.new( "com.deepin.dde.background") self.draw_title_background = self.draw_tab_title_background self.theme = None self.wallpaper_box = gtk.VBox() self.window_theme_box = gtk.VBox() self.wallpaper_view = WallpaperView(padding_x=30, padding_y=ITEM_PADDING_Y) self.wallpaper_view_sw = self.wallpaper_view.get_scrolled_window() self.wallpaper_view_sw.set_size_request(-1, 426) position_group, self.position_combobox = get_combo_group( _("Position"), DRAW_COMBO_ITEM, self.on_position_combox_selected) time_group, self.time_combobox = get_combo_group( _("Duration"), TIME_COMBO_ITEM, self.on_time_combox_selected) self.__is_random = True if self.__background_settings.get_int("background-duration") == 0: self.__is_random = False self.unorder_play, self.random_toggle = get_toggle_group( _("Random"), self.__on_random_toggled, self.__is_random) self.button_align = gtk.Alignment() self.button_box = gtk.HBox(spacing=5) self.select_all_button = Button(_("Select all")) self.select_all_button.set_size_request(80, WIDGET_HEIGHT) self.select_all_button.connect("clicked", self.__on_select_all) self.delete_button = Button(_("Delete")) self.delete_button.set_size_request(80, WIDGET_HEIGHT) self.delete_button.connect("clicked", self.__on_delete) self.button_box.pack_start(self.select_all_button, False, False) self.button_box.pack_start(self.delete_button, False, False) self.button_align.add(self.button_box) self.action_bar = gtk.HBox(spacing=26) self.action_bar.pack_start(position_group, False, False) self.action_bar.pack_start(time_group, False, False) self.action_bar.pack_start(self.unorder_play, False, False) self.action_bar.pack_end(self.button_align, False, False) action_bar_align = gtk.Alignment() action_bar_align.set_size_request(-1, STATUS_HEIGHT) action_bar_align.set_padding(5, 5, 50, 20) action_bar_align.add(self.action_bar) self.wallpaper_box.pack_start(self.wallpaper_view_sw, True, True) self.wallpaper_box.pack_start(action_bar_align, False, False) self.pack_start(self.wallpaper_box, False, False) event_manager.add_callback("select-wallpaper", self.on_wallpaper_select) event_manager.add_callback("apply-wallpaper", self.__on_wallpaper_apply) event_manager.add_callback("add-wallpapers", self.__on_add_wallpapers)
class DetailPage(gtk.VBox): ''' class docs ''' def __init__(self): ''' init docs ''' gtk.VBox.__init__(self) self.__background_settings = deepin_gsettings.new( "com.deepin.dde.background") self.draw_title_background = self.draw_tab_title_background self.theme = None self.wallpaper_box = gtk.VBox() self.window_theme_box = gtk.VBox() self.wallpaper_view = WallpaperView(padding_x=30, padding_y=ITEM_PADDING_Y) self.wallpaper_view_sw = self.wallpaper_view.get_scrolled_window() self.wallpaper_view_sw.set_size_request(-1, 426) position_group, self.position_combobox = get_combo_group( _("Position"), DRAW_COMBO_ITEM, self.on_position_combox_selected) time_group, self.time_combobox = get_combo_group( _("Duration"), TIME_COMBO_ITEM, self.on_time_combox_selected) self.__is_random = True if self.__background_settings.get_int("background-duration") == 0: self.__is_random = False self.unorder_play, self.random_toggle = get_toggle_group( _("Random"), self.__on_random_toggled, self.__is_random) self.button_align = gtk.Alignment() self.button_box = gtk.HBox(spacing=5) self.select_all_button = Button(_("Select all")) self.select_all_button.set_size_request(80, WIDGET_HEIGHT) self.select_all_button.connect("clicked", self.__on_select_all) self.delete_button = Button(_("Delete")) self.delete_button.set_size_request(80, WIDGET_HEIGHT) self.delete_button.connect("clicked", self.__on_delete) self.button_box.pack_start(self.select_all_button, False, False) self.button_box.pack_start(self.delete_button, False, False) self.button_align.add(self.button_box) self.action_bar = gtk.HBox(spacing=26) self.action_bar.pack_start(position_group, False, False) self.action_bar.pack_start(time_group, False, False) self.action_bar.pack_start(self.unorder_play, False, False) self.action_bar.pack_end(self.button_align, False, False) action_bar_align = gtk.Alignment() action_bar_align.set_size_request(-1, STATUS_HEIGHT) action_bar_align.set_padding(5, 5, 50, 20) action_bar_align.add(self.action_bar) self.wallpaper_box.pack_start(self.wallpaper_view_sw, True, True) self.wallpaper_box.pack_start(action_bar_align, False, False) self.pack_start(self.wallpaper_box, False, False) event_manager.add_callback("select-wallpaper", self.on_wallpaper_select) event_manager.add_callback("apply-wallpaper", self.__on_wallpaper_apply) event_manager.add_callback("add-wallpapers", self.__on_add_wallpapers) def __random_enable(self): self.time_combobox.set_sensitive(True) self.unorder_play.set_child_visible(True) self.random_toggle.set_child_visible(True) self.random_toggle.set_active(self.theme.get_background_random_mode()) def __random_disable(self): self.time_combobox.set_sensitive(False) self.unorder_play.set_child_visible(False) self.random_toggle.set_child_visible(False) self.random_toggle.set_active(self.theme.get_background_random_mode()) def on_wallpaper_select(self, name, obj, select_item): if self.wallpaper_view.is_randomable(): self.__random_enable() else: self.__random_disable() if self.wallpaper_view.is_select_all(): self.select_all_button.set_label(_("Clear all")) else: self.select_all_button.set_label(_("Select all")) self.select_all_button.set_size_request(80, WIDGET_HEIGHT) def __on_wallpaper_apply(self, name, obj, select_item): self.__random_disable() if self.wallpaper_view.is_select_all(): self.select_all_button.set_label(_("Clear all")) else: self.select_all_button.set_label(_("Select all")) self.select_all_button.set_size_request(80, WIDGET_HEIGHT) def __on_select_all(self, widget): self.wallpaper_view.select_all() if self.wallpaper_view.is_select_all(): self.select_all_button.set_label(_("Clear all")) else: self.select_all_button.set_label(_("Select all")) self.select_all_button.set_size_request(80, WIDGET_HEIGHT) if self.wallpaper_view.is_randomable(): self.__random_enable() else: self.__random_disable() def __on_delete(self, widget): event_manager.emit("switch-to-deletepage", self.theme) def __on_random_toggled(self, widget): self.theme.set_background_random_mode(widget.get_active()) def draw_tab_title_background(self, cr, widget): rect = widget.allocation cr.set_source_rgb(1, 1, 1) cr.rectangle(0, 0, rect.width, rect.height - 1) cr.fill() def on_position_combox_selected(self, widget, label, data, index): self.theme.set_background_draw_mode(data) self.theme.save() def on_time_combox_selected(self, widget, label, data, index): self.theme.set_background_duration(data) self.theme.save() def __set_delete_button_visible(self): is_editable = self.wallpaper_view.is_editable() if is_editable: self.button_align.set_padding(0, 0, 113, 5) else: self.button_align.set_padding(0, 0, 204, 5) self.delete_button.set_child_visible(is_editable) def __on_add_wallpapers(self, name, obj, image_paths): if len(self.wallpaper_view.items) < 2: self.select_all_button.set_child_visible(False) else: self.select_all_button.set_child_visible(True) self.select_all_button.set_label(_("Select all")) self.__set_delete_button_visible() def set_theme(self, theme): self.theme = theme draw_mode = self.theme.get_background_draw_mode() item_index = 0 for index, item in enumerate(DRAW_COMBO_ITEM): if draw_mode == item[-1]: item_index = index self.position_combobox.set_select_index(item_index) duration = self.theme.get_background_duration() item_index = 0 for index, item in enumerate(TIME_COMBO_ITEM): if duration == item[-1]: item_index = index self.time_combobox.set_select_index(item_index) self.wallpaper_view.set_theme(theme) self.__set_delete_button_visible() if self.wallpaper_view.is_randomable(): self.__random_enable() else: self.__random_disable() if len(self.wallpaper_view.items) < 2: self.select_all_button.set_child_visible(False) else: self.select_all_button.set_child_visible(True) if self.wallpaper_view.is_select_all(): self.select_all_button.set_label(_("Clear all")) self.select_all_button.set_size_request(80, WIDGET_HEIGHT) def draw_mask(self, cr, x, y, w, h): ''' Draw mask interface. @param cr: Cairo context. @param x: X coordiante of draw area. @param y: Y coordiante of draw area. @param w: Width of draw area. @param h: Height of draw area. ''' cr.set_source_rgb(1, 1, 1) cr.rectangle(x, y, w, h) cr.fill()
class DetailPage(gtk.VBox): """ class docs """ def __init__(self): """ init docs """ gtk.VBox.__init__(self) self.__background_settings = deepin_gsettings.new("com.deepin.dde.background") self.draw_title_background = self.draw_tab_title_background self.theme = None self.wallpaper_box = gtk.VBox() self.window_theme_box = gtk.VBox() self.wallpaper_view = WallpaperView(padding_x=30, padding_y=ITEM_PADDING_Y) self.wallpaper_view_sw = self.wallpaper_view.get_scrolled_window() self.wallpaper_view_sw.set_size_request(-1, 426) position_group, self.position_combobox = get_combo_group( _("Position"), DRAW_COMBO_ITEM, self.on_position_combox_selected ) time_group, self.time_combobox = get_combo_group(_("Duration"), TIME_COMBO_ITEM, self.on_time_combox_selected) self.__is_random = True if self.__background_settings.get_int("background-duration") == 0: self.__is_random = False self.unorder_play, self.random_toggle = get_toggle_group( _("Random"), self.__on_random_toggled, self.__is_random ) self.button_align = gtk.Alignment() self.button_box = gtk.HBox(spacing=5) self.select_all_button = Button(_("Select all")) self.select_all_button.set_size_request(80, WIDGET_HEIGHT) self.select_all_button.connect("clicked", self.__on_select_all) self.delete_button = Button(_("Delete")) self.delete_button.set_size_request(80, WIDGET_HEIGHT) self.delete_button.connect("clicked", self.__on_delete) self.button_box.pack_start(self.select_all_button, False, False) self.button_box.pack_start(self.delete_button, False, False) self.button_align.add(self.button_box) self.action_bar = gtk.HBox(spacing=26) self.action_bar.pack_start(position_group, False, False) self.action_bar.pack_start(time_group, False, False) self.action_bar.pack_start(self.unorder_play, False, False) self.action_bar.pack_end(self.button_align, False, False) action_bar_align = gtk.Alignment() action_bar_align.set_size_request(-1, STATUS_HEIGHT) action_bar_align.set_padding(5, 5, 50, 20) action_bar_align.add(self.action_bar) self.wallpaper_box.pack_start(self.wallpaper_view_sw, True, True) self.wallpaper_box.pack_start(action_bar_align, False, False) self.pack_start(self.wallpaper_box, False, False) event_manager.add_callback("select-wallpaper", self.on_wallpaper_select) event_manager.add_callback("apply-wallpaper", self.__on_wallpaper_apply) event_manager.add_callback("add-wallpapers", self.__on_add_wallpapers) def __random_enable(self): self.time_combobox.set_sensitive(True) self.unorder_play.set_child_visible(True) self.random_toggle.set_child_visible(True) self.random_toggle.set_active(self.theme.get_background_random_mode()) def __random_disable(self): self.time_combobox.set_sensitive(False) self.unorder_play.set_child_visible(False) self.random_toggle.set_child_visible(False) self.random_toggle.set_active(self.theme.get_background_random_mode()) def on_wallpaper_select(self, name, obj, select_item): if self.wallpaper_view.is_randomable(): self.__random_enable() else: self.__random_disable() if self.wallpaper_view.is_select_all(): self.select_all_button.set_label(_("Clear all")) else: self.select_all_button.set_label(_("Select all")) self.select_all_button.set_size_request(80, WIDGET_HEIGHT) def __on_wallpaper_apply(self, name, obj, select_item): self.__random_disable() if self.wallpaper_view.is_select_all(): self.select_all_button.set_label(_("Clear all")) else: self.select_all_button.set_label(_("Select all")) self.select_all_button.set_size_request(80, WIDGET_HEIGHT) def __on_select_all(self, widget): self.wallpaper_view.select_all() if self.wallpaper_view.is_select_all(): self.select_all_button.set_label(_("Clear all")) else: self.select_all_button.set_label(_("Select all")) self.select_all_button.set_size_request(80, WIDGET_HEIGHT) if self.wallpaper_view.is_randomable(): self.__random_enable() else: self.__random_disable() def __on_delete(self, widget): event_manager.emit("switch-to-deletepage", self.theme) def __on_random_toggled(self, widget): self.theme.set_background_random_mode(widget.get_active()) def draw_tab_title_background(self, cr, widget): rect = widget.allocation cr.set_source_rgb(1, 1, 1) cr.rectangle(0, 0, rect.width, rect.height - 1) cr.fill() def on_position_combox_selected(self, widget, label, data, index): self.theme.set_background_draw_mode(data) self.theme.save() def on_time_combox_selected(self, widget, label, data, index): self.theme.set_background_duration(data) self.theme.save() def __set_delete_button_visible(self): is_editable = self.wallpaper_view.is_editable() if is_editable: self.button_align.set_padding(0, 0, 113, 5) else: self.button_align.set_padding(0, 0, 204, 5) self.delete_button.set_child_visible(is_editable) def __on_add_wallpapers(self, name, obj, image_paths): if len(self.wallpaper_view.items) < 2: self.select_all_button.set_child_visible(False) else: self.select_all_button.set_child_visible(True) self.select_all_button.set_label(_("Select all")) self.__set_delete_button_visible() def set_theme(self, theme): self.theme = theme draw_mode = self.theme.get_background_draw_mode() item_index = 0 for index, item in enumerate(DRAW_COMBO_ITEM): if draw_mode == item[-1]: item_index = index self.position_combobox.set_select_index(item_index) duration = self.theme.get_background_duration() item_index = 0 for index, item in enumerate(TIME_COMBO_ITEM): if duration == item[-1]: item_index = index self.time_combobox.set_select_index(item_index) self.wallpaper_view.set_theme(theme) self.__set_delete_button_visible() if self.wallpaper_view.is_randomable(): self.__random_enable() else: self.__random_disable() if len(self.wallpaper_view.items) < 2: self.select_all_button.set_child_visible(False) else: self.select_all_button.set_child_visible(True) if self.wallpaper_view.is_select_all(): self.select_all_button.set_label(_("Clear all")) self.select_all_button.set_size_request(80, WIDGET_HEIGHT) def draw_mask(self, cr, x, y, w, h): """ Draw mask interface. @param cr: Cairo context. @param x: X coordiante of draw area. @param y: Y coordiante of draw area. @param w: Width of draw area. @param h: Height of draw area. """ cr.set_source_rgb(1, 1, 1) cr.rectangle(x, y, w, h) cr.fill()