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 FootBox(gtk.HBox): def __init__(self): gtk.HBox.__init__(self) self.set_size_request(-1, 35) self.apply_method = None self.init_ui() self.timer = Timer(3000, self.__clear_tips) Dispatcher.connect("button-change", self.set_button) Dispatcher.connect("set-tip", self.set_tip) event_manager.add_callback("update-delete-button", self.__on_update_delete_button) def __on_update_delete_button(self, name, obj, data): #self.btn_delete.set_child_visible(data) self.queue_draw() def expose_line(self, widget, event): cr = widget.window.cairo_create() rect = widget.allocation style.draw_out_line(cr, rect) def init_ui(self): self.tip_align = gtk.Alignment(0, 0.5, 0, 1) self.tip = Label("", text_x_align=pango.ALIGN_CENTER, label_width=500) self.tip_align.set_padding(5, 5, 20, 0) self.tip_align.add(self.tip) self.btn_delete = Button(_("Delete")) self.btn_delete.connect("clicked", self.delete_click) self.btn_delete.set_no_show_all(True) self.btn_save = Button() self.btn_save.connect("clicked", self.button_click) button_box = gtk.HBox(spacing=10) button_box.pack_start(self.btn_delete) button_box.pack_start(self.btn_save) self.buttons_align = gtk.Alignment(1, 0.5, 0, 0) self.buttons_align.set_padding(0, 0, 0, 10) self.buttons_align.add(button_box) self.pack(self, [self.tip_align], True, True) self.pack_end(self.buttons_align, False, False) def pack(self, parent, widgets, expand=False, fill=False): for widget in widgets: parent.pack_start(widget, expand, fill) def set_lock(self, state): self.__setting_module.set_lock(state) def get_lock(self): return self.__setting_module.get_lock() def set_button(self, widget, content, state): self.btn_save.set_label(_("Save")) self.btn_save.set_sensitive(state) def delete_click(self, widget): if self.focus_connection: Dispatcher.delete_setting(self.focus_connection) Dispatcher.to_main_page() def show_delete(self, connection): self.btn_delete.show() self.focus_connection = connection def hide_delete(self): self.btn_delete.hide() self.focus_connection = None #if content == "save": #if state and not self.get_lock(): #Dispatcher.emit("setting-saved") #else: #self.btn_save.set_label(_("connect")) #self.btn_save.set_sensitive(False) #else: #self.btn_save.set_label(_("connect")) #self.btn_save.set_sensitive(True) def get_button(self): return self.__setting_module.get_button_state() def set_setting(self, module): self.__setting_module = module def button_click(self, widget): #if self.btn_save.label == "save": Dispatcher.emit("setting-saved") #elif self.btn_save.label == _("connect"): #Dispatcher.set_tip("setting saved") #Dispatcher.emit("setting-appled") def __clear_tips(self): self.tip.set_text("") def set_tip(self, widget, new_tip): self.tip.set_text(_("Tip:") + new_tip) self.timer.restart()
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 DeletePage(gtk.VBox): ''' class docs ''' def __init__(self): ''' init docs ''' gtk.VBox.__init__(self) self.draw_title_background = self.draw_tab_title_background self.theme = None self.delete_view = DeleteView(padding_x=30, padding_y=ITEM_PADDING_Y) self.delete_view_sw = self.delete_view.get_scrolled_window() self.action_align = gtk.Alignment() self.action_align.set_padding(5, 5, 510, 5) self.action_box = gtk.HBox(spacing=10) self.back_button = Button(_("Back")) self.back_button.set_size_request(80, WIDGET_HEIGHT) self.back_button.connect("clicked", self.__on_back) 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.action_box.pack_start(self.select_all_button, False, False) self.action_box.pack_start(self.delete_button, False, False) self.action_box.pack_start(self.back_button, False, False) self.action_align.add(self.action_box) self.pack_start(self.delete_view_sw, True, True) self.pack_start(self.action_align, False, False) event_manager.add_callback("select-delete-wallpaper", self.__on_select_delete_wallpaper) def __on_back(self, widget): event_manager.emit("back-to-detailpage", self.theme) def __on_select_delete_wallpaper(self, name, obj, select_item): if self.delete_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.delete_view.select_all() if self.delete_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 __delete_confirm(self): self.delete_view.delete_wallpaper() def __on_delete(self, widget): if self.delete_view.is_deletable(): dlg = ConfirmDialog(_("Delete Wallpaper"), _("Are you sure delete wallpaper?"), 300, 100, lambda: self.__delete_confirm(), None, True, CONTENT_FONT_SIZE) dlg.show_all() 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 set_theme(self, theme): self.theme = theme self.delete_view.set_theme(self.theme) self.select_all_button.set_label(_("Select 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 DeletePage(gtk.VBox): ''' class docs ''' def __init__(self): ''' init docs ''' gtk.VBox.__init__(self) self.draw_title_background = self.draw_tab_title_background self.theme = None self.delete_view = DeleteView(padding_x=30, padding_y=ITEM_PADDING_Y) self.delete_view_sw = self.delete_view.get_scrolled_window() self.action_align = gtk.Alignment() self.action_align.set_padding(5, 5, 510, 5) self.action_box = gtk.HBox(spacing = 10) self.back_button = Button(_("Back")) self.back_button.set_size_request(80, WIDGET_HEIGHT) self.back_button.connect("clicked", self.__on_back) 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.action_box.pack_start(self.select_all_button, False, False) self.action_box.pack_start(self.delete_button, False, False) self.action_box.pack_start(self.back_button, False, False) self.action_align.add(self.action_box) self.pack_start(self.delete_view_sw, True, True) self.pack_start(self.action_align, False, False) event_manager.add_callback("select-delete-wallpaper", self.__on_select_delete_wallpaper) def __on_back(self, widget): event_manager.emit("back-to-detailpage", self.theme) def __on_select_delete_wallpaper(self, name, obj, select_item): if self.delete_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.delete_view.select_all() if self.delete_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 __delete_confirm(self): self.delete_view.delete_wallpaper() def __on_delete(self, widget): if self.delete_view.is_deletable(): dlg = ConfirmDialog(_("Delete Wallpaper"), _("Are you sure delete wallpaper?"), 300, 100, lambda : self.__delete_confirm(), None, True, CONTENT_FONT_SIZE) dlg.show_all() 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 set_theme(self, theme): self.theme = theme self.delete_view.set_theme(self.theme) self.select_all_button.set_label(_("Select 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()