def __create_single_toggle_button(self, normal_name, callback, tip_msg=None): if normal_name == "karaoke": toggle_button = ToggleButton( app_theme.get_pixbuf("lyric/%s_press.png" % normal_name), app_theme.get_pixbuf("lyric/%s_normal.png" % normal_name), app_theme.get_pixbuf("lyric/%s_hover.png" % normal_name), ) else: toggle_button = ToggleButton( app_theme.get_pixbuf("lyric/%s_normal.png" % normal_name), app_theme.get_pixbuf("lyric/%s_press.png" % normal_name), app_theme.get_pixbuf("lyric/%s_hover.png" % normal_name), ) toggle_button.connect("toggled", callback) toggle_align = gtk.Alignment() toggle_align.set(0.5, 0.5, 0, 0) toggle_align.add(toggle_button) if tip_msg: Tooltip.text(toggle_button, tip_msg) return toggle_align, toggle_button
def __init__(self): self.button = ToggleButton( app_theme.get_pixbuf("bottom_buttons/play_list_button.png"), app_theme.get_pixbuf("bottom_buttons/list_button_background.png"), ) self.button.set_active(False) tooltip_text(self.button, _("Playlist"))
def __setup_toggle(self): toggle_button = ToggleButton( app_theme.get_pixbuf("toggle_button/inactive_normal.png"), app_theme.get_pixbuf("toggle_button/active_normal.png"), inactive_disable_dpixbuf=app_theme.get_pixbuf( "toggle_button/inactive_normal.png")) toggle_button.set_active(self.my_bluetooth.adapter.get_powered()) return toggle_button
def __setup_toggle(self): return ToggleButton( app_theme.get_pixbuf("toggle_button/inactive_normal.png"), app_theme.get_pixbuf("toggle_button/active_normal.png"), inactive_disable_dpixbuf=app_theme.get_pixbuf( "toggle_button/inactive_normal.png"), active_disable_dpixbuf=app_theme.get_pixbuf( "toggle_button/inactive_normal.png"))
def __create_begin_button(self, callback): toggle_button = ToggleButton( app_theme.get_pixbuf("jobs/pause_normal.png"), app_theme.get_pixbuf("jobs/begin_normal.png"), app_theme.get_pixbuf("jobs/pause_hover.png"), app_theme.get_pixbuf("jobs/begin_hover.png")) if callback: toggle_button.connect("toggled", callback) return toggle_button
def get_togglebutton(): toggle = ToggleButton( app_theme.get_pixbuf("toggle_button/inactive_normal.png"), app_theme.get_pixbuf("toggle_button/active_normal.png"), inactive_disable_dpixbuf=app_theme.get_pixbuf( "toggle_button/inactive_normal.png"), active_disable_dpixbuf=app_theme.get_pixbuf( "toggle_button/inactive_normal.png")) return toggle
def create_revert_button(self): button = ToggleButton( app_theme.get_pixbuf("mode/simple_normal.png"), app_theme.get_pixbuf("mode/full_normal.png"), app_theme.get_pixbuf("mode/simple_hover.png"), app_theme.get_pixbuf("mode/full_hover.png"), app_theme.get_pixbuf("mode/simple_press.png"), app_theme.get_pixbuf("mode/full_press.png"), ) return button
def create_playpause_button(self): play_normal_pixbuf = app_theme.get_pixbuf("mini/play_normal.png") pause_normal_pixbuf = app_theme.get_pixbuf("mini/pause_normal.png") play_hover_pixbuf = app_theme.get_pixbuf("mini/play_hover.png") pause_hover_pixbuf = app_theme.get_pixbuf("mini/pause_hover.png") play_press_pixbuf = app_theme.get_pixbuf("mini/play_press.png") pause_press_pixbuf = app_theme.get_pixbuf("mini/pause_press.png") playpause_button = ToggleButton(play_normal_pixbuf, pause_normal_pixbuf, play_hover_pixbuf, pause_hover_pixbuf, play_press_pixbuf, pause_press_pixbuf) return playpause_button
def __create_simple_toggle_button(self, name, callback, tip_msg=""): toggle_button = ToggleButton( app_theme.get_pixbuf("toolbar/%s_normal.png" % name), app_theme.get_pixbuf("toolbar/%s_press.png" % name), ) toggle_button.connect("toggled", callback) if tip_msg: Tooltip.text(toggle_button, tip_msg) self.toolbar_box.pack_start(toggle_button, False, False) return toggle_button
def __create_simple_toggle_button(self, name, callback): toggle_button = ToggleButton( app_theme.get_pixbuf("lyrics_button/%s_inactive_normal.png" % name), app_theme.get_pixbuf("lyrics_button/%s_active_normal.png" % name), app_theme.get_pixbuf("lyrics_button/%s_inactive_hover.png" % name), app_theme.get_pixbuf("lyrics_button/%s_active_hover.png" % name), app_theme.get_pixbuf("lyrics_button/%s_inactive_press.png" % name), app_theme.get_pixbuf("lyrics_button/%s_active_press.png" % name), ) if callback: toggle_button.connect("toggled", callback) return toggle_button
def create_lyrics_button(self): toggle_button = ToggleButton( app_theme.get_pixbuf("mini/lyrics_inactive_normal.png"), app_theme.get_pixbuf("mini/lyrics_active_normal.png"), app_theme.get_pixbuf("mini/lyrics_inactive_hover.png"), app_theme.get_pixbuf("mini/lyrics_active_hover.png"), app_theme.get_pixbuf("mini/lyrics_inactive_press.png"), app_theme.get_pixbuf("mini/lyrics_active_press.png"), ) toggle_button.connect("toggled", self.change_lyrics_status) return toggle_button
def create_toggle_button(self, name): ''' create a togglebutton @param name: the button's name @return: a dtk.ui.ToggleButton ''' button = ToggleButton( app_theme.get_pixbuf("size/" + name + ".png"), app_theme.get_pixbuf("size/" + name + "_press.png"), app_theme.get_pixbuf("size/" + name + "_hover.png"), app_theme.get_pixbuf("size/" + name + "_press.png")) button.set_name(name) return button
def create_toggle_button(name, callback=None, tip_msg=None, parent=False): toggle_button = ToggleButton( app_theme.get_pixbuf("%s_normal.png" % name), app_theme.get_pixbuf("%s_press.png" % name), ) if callback: toggle_button.connect("toggled", callback) if tip_msg: Tooltip.text(toggle_button, tip_msg) if parent: parent.pack_start(toggle_button, False, False) return toggle_button
from dtk.ui.init_skin import init_theme init_theme() from dtk.ui.application import Application from dtk.ui.button import ToggleButton from dtk.ui.theme import ui_theme from dtk.ui.dialog import ConfirmDialog import gtk if __name__ == "__main__": application = Application() application.set_default_size(600, 450) application.add_titlebar(title="ToggleButton example!") toggle_button = ToggleButton( inactive_normal_dpixbuf=ui_theme.get_pixbuf("switchbutton/off.png"), active_normal_dpixbuf=ui_theme.get_pixbuf("switchbutton/on.png"), button_label="This is toggle button", padding_x=5, ) toggle_button.connect( "toggled", lambda w: ConfirmDialog( "反馈对话框", "按钮开启" if w.get_active() else "按钮关闭", ).show_all()) toggle_button_align = gtk.Alignment() toggle_button_align.set(0.5, 0.5, 0, 0) toggle_button_align.add(toggle_button) application.main_box.add(toggle_button_align) application.run()
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 __setup_toggle(self): toggle = ToggleButton(app_theme.get_pixbuf("inactive_normal.png"), app_theme.get_pixbuf("active_normal.png")) return toggle
def __init__(self): gtk.EventBox.__init__(self) self.set_visible_window(False) # init. self.cover_box = PlayerCoverButton() self.cover_box.show_all() # play button play_normal_pixbuf = app_theme.get_pixbuf("action/play_normal.png") pause_normal_pixbuf = app_theme.get_pixbuf("action/pause_normal.png") play_hover_pixbuf = app_theme.get_pixbuf("action/play_hover.png") pause_hover_pixbuf = app_theme.get_pixbuf("action/pause_hover.png") play_press_pixbuf = app_theme.get_pixbuf("action/play_press.png") pause_press_pixbuf = app_theme.get_pixbuf("action/pause_press.png") self.__play = ToggleButton( play_normal_pixbuf, pause_normal_pixbuf, play_hover_pixbuf, pause_hover_pixbuf, play_press_pixbuf, pause_press_pixbuf, ) Tooltip.text(self.__play, _("Play/Pause")) # swap played status handler Player.connect("played", self.__swap_play_status, True) Player.connect("paused", self.__swap_play_status, False) Player.connect("stopped", self.__swap_play_status, False) Player.connect("play-end", self.__swap_play_status, False) self.__id_signal_play = self.__play.connect("toggled", self.on_player_playpause) prev_button = self.__create_button("previous", _("Previous")) next_button = self.__create_button("next", _("Next")) # lyrics button self.lyrics_button = self.__create_simple_toggle_button( "lyrics", self.change_lyrics_status) Tooltip.text(self.lyrics_button, _("Show/Hide Lyrics")) lyrics_button_align = gtk.Alignment() lyrics_button_align.set_padding(0, 0, 0, 10) lyrics_button_align.set(0.5, 0.5, 0, 0) lyrics_button_align.add(self.lyrics_button) volume_button_align = gtk.Alignment() volume_button_align.set_padding(0, 0, 10, 0) volume_button_align.set(0.5, 0.5, 0, 0) self.volume_slider = VolumeSlider() volume_button_align.add(self.volume_slider) # volume_button_align.add(VolumeButton()) # action_box action_box = gtk.HBox() action_box.pack_start(lyrics_button_align, False, False) action_box.pack_start(set_widget_vcenter(prev_button), False, False) action_box.pack_start(set_widget_vcenter(self.__play), False, False) action_box.pack_start(set_widget_vcenter(next_button), False, False) action_box.pack_start(volume_button_align, False, False) # combo_box playinfo_align = gtk.Alignment() playinfo_align.set_padding(0, 0, 12, 0) playinfo_align.add(PlayInfo(200)) self.action_box_align = gtk.Alignment() self.action_box_align.set_padding(6, 0, 6, 0) self.action_box_align.add(action_box) self.action_box_align.connect("expose-event", self.on_expose_event) self.timer_label = "00:00" self.song_timer = SongTimer(self.draw_timer_label) combo_vbox = gtk.VBox(spacing=5) combo_vbox.pack_start(playinfo_align, False, False) combo_vbox.pack_start(self.action_box_align, False, False) cover_box_align = gtk.Alignment() cover_box_align.set_padding(0, 0, 10, 0) cover_box_align.add(self.cover_box) cover_main_box = gtk.HBox() cover_main_box.pack_start(cover_box_align, False, False) cover_main_box.pack_start(combo_vbox, False, False) body_vbox = gtk.VBox(spacing=6) body_vbox.pack_start(cover_main_box, False, True) body_vbox.pack_start(self.song_timer, False, True) # progressbar_align = gtk.Alignment() # progressbar_align.add(ProgressBar()) # progressbar_align.set(1, 1, 1, 1) # progressbar_align.set_padding(0, 0, 2, 2) # body_vbox.pack_start(progressbar_align, False, True) self.add(body_vbox) # right click self.connect("button-press-event", self.right_click_cb) Dispatcher.connect("close-lyrics", lambda w: self.lyrics_button.set_active(False)) Dispatcher.connect("show-lyrics", lambda w: self.lyrics_button.set_active(True)) self.signal_auto = False if config.getboolean("lyrics", "status"): self.lyrics_button.set_active(True) self.signal_auto = True
def init_toolbar(self): self.toolbar = Window(window_type=gtk.WINDOW_POPUP) self.toolbar.set_size_request(-1, 41) padding_x, padding_y = 10, 5 play_box = gtk.HBox(spacing=2) play_box.connect("expose-event", self.expose_toolbar_mask) # swap played status handler Player.connect("played", self.__swap_play_status, True) Player.connect("paused", self.__swap_play_status, False) Player.connect("stopped", self.__swap_play_status, False) Player.connect("play-end", self.__swap_play_status, False) self.playpause_button = ToggleButton( app_theme.get_pixbuf("lyric/play_normal.png"), app_theme.get_pixbuf("lyric/pause_normal.png"), app_theme.get_pixbuf("lyric/play_hover.png"), app_theme.get_pixbuf("lyric/pause_hover.png"), app_theme.get_pixbuf("lyric/play_press.png"), app_theme.get_pixbuf("lyric/pause_press.png"), ) self.__id_signal_play = self.playpause_button.connect( "toggled", lambda w: Player.playpause()) prev = self.__create_button("previous") next = self.__create_button("next") prev_align = gtk.Alignment() prev_align.set(0.5, 0.5, 0, 0) prev_align.add(prev) next_align = gtk.Alignment() next_align.set(0.5, 0.5, 0, 0) next_align.add(next) play_align = gtk.Alignment() play_align.set_padding(2, 0, 0, 0) play_align.set(0.5, 0.5, 0, 0) play_align.add(self.playpause_button) # separte line separate_line = ImageBox(app_theme.get_pixbuf("lyric/separate.png")) sep_align = gtk.Alignment() sep_align.set(0.5, 0.5, 0, 0) sep_align.add(separate_line) zoom_in_align = self.__create_zoom_button( "zoom_in", _("Increase the lyrics size")) zoom_out_align = self.__create_zoom_button( "zoom_out", _("Decrease the lyrics size")) predefine_align = self.__create_simple_button( "predefine_color", self.popup_predefine_menu, _("Select color theme"), True) lock_align = self.__create_simple_button("lock", self.__lock_lyrics, _("Lock Lyrics")) karaoke_align, self.karaoke_button = self.__create_single_toggle_button( "karaoke", self.change_karaoke_status, _("Karaoke on/off")) line_align, self.line_button = self.__create_simple_toggle_button( "single_line", "double_line", None, _("Switch lines")) self.line_button_toggled_id = self.line_button.connect( "toggled", self.change_line_status) setting_align = self.__create_simple_button("setting", self.open_setting_window, _("Open settings panel")) search_align = self.__create_simple_button( "search", self.open_search_window, _("Search lrc file for current track")) close_align = self.__create_simple_button("close", self.close_lyric_window, _("Close lyrics")) before_align = self.__create_simple_button("before", self.before_offset, _("Lyrics rewind")) after_align = self.__create_simple_button("after", self.after_offset, _("Lyrics forward")) lrc_align = self.__create_simple_button("lrc", self.switch_to_scroll_lyrics, _("Switch to window mode")) play_box.pack_start(prev_align, False, False) play_box.pack_start(play_align, False, False) play_box.pack_start(next_align, False, False) play_box.pack_start(sep_align, False, False) play_box.pack_start(zoom_in_align, False, False) play_box.pack_start(zoom_out_align, False, False) play_box.pack_start(before_align, False, False) play_box.pack_start(after_align, False, False) play_box.pack_start(predefine_align, False, False) play_box.pack_start(karaoke_align, False, False) play_box.pack_start(line_align, False, False) play_box.pack_start(lock_align, False, False) play_box.pack_start(setting_align, False, False) play_box.pack_start(lrc_align, False, False) play_box.pack_start(search_align, False, False) play_box.pack_start(close_align, False, False) main_align = gtk.Alignment() main_align.set_padding(0, 0, padding_x, padding_x) main_align.set(0.5, 0.5, 0, 0) main_align.add(play_box) self.toolbar.window_frame.pack_start(main_align) self.load_button_status()