def on_category_right_press(self, widget, x, y, item, cloumn):
        menu_items = [
            (None, "新建试听列表", self.new_listen_list),
            (None, "新建在线歌单", self.new_online_list),
        ]

        if not item:
            Menu(menu_items, True).show((x, y))
            return

        if item.list_type == MusicListItem.COLLECT_TYPE:
            if bplayer.is_login:
                menu_items = [(None, "刷新", item.refrush),
                              (None, "新建歌单", self.new_online_list),
                              (None, "更换帐号", lambda: bplayer.relogin())]
            else:
                menu_items = None

        elif item.list_type == MusicListItem.PLAYLIST_TYPE:
            menu_items = [
                (None, "新建歌单", self.new_online_list),
                (None, "删除歌单", lambda: self.del_online_list(item)),
                (None, "重命名", lambda: self.rename_online_list(item)),
                (None, "刷新", item.refrush),
            ]
        elif item.list_type == MusicListItem.LOCAL_TYPE:
            menu_items.extend([
                (None, "删除列表", lambda: self.del_listen_list(item)),
                (None, "重命名",
                 lambda: self.rename_online_list(item, is_online=False))
            ])

        if menu_items:
            Menu(menu_items, True).show((x, y))
Esempio n. 2
0
 def _list_menu_show(self, button, x, y, offset_x, offset_y):
     '''the combo button clicked callback. show combo_buton list menu'''
     menu_item = [(None, _("Save automatically"), self._list_menu_click,
                   SAVE_OP_AUTO, button),
                  (None, _("Save as"), self._list_menu_click, SAVE_OP_AS,
                   button),
                  (None, _("Save to clipboard"), self._list_menu_click,
                   SAVE_OP_CLIP, button),
                  (None, _("Save automatically to file and clipboard"),
                   self._list_menu_click, SAVE_OP_AUTO_AND_CLIP, button)]
     # set current operate icon
     current_item = menu_item[self.screenshot.save_op_index]
     menu_pixbuf = (app_theme.get_pixbuf("action/selected.png"),
                    app_theme.get_pixbuf("action/selected_hover.png"),
                    app_theme.get_pixbuf("action/selected.png"))
     menu_item[self.screenshot.save_op_index] = (menu_pixbuf,
                                                 current_item[1],
                                                 current_item[2],
                                                 current_item[3])
     self.combo_menu = Menu(
         menu_item,
         is_root_menu=True,
         menu_item_select_color=app_theme.get_shadow_color(
             "menu_item_select").get_color_info())
     self.set_all_inactive()
     self.combo_menu.show((x, y), (offset_x, offset_y))
Esempio n. 3
0
    def on_music_view_right_press_items(self, widget, x, y, current_item,
                                        select_items):
        if current_item and select_items:
            selected_songs_id = [
                item.get_song()['id'] for item in select_items
            ]
            # 子菜单 - 添加到创建的歌单
            addto_submenu = [
                (None, _(gobject.markup_escape_text(key)), self.add_to_list,
                 selected_songs_id, self.CREATED_LISTS_DICT[key])
                for key in self.CREATED_LISTS_DICT.keys()
            ]
            addto_submenu.insert(
                0, (None, _('播放列表'), self.add_to_list, selected_songs_id, 0))
            addto_submenu = Menu(addto_submenu)

            if len(select_items) > 1:
                items = [
                    (None, _("播放"), lambda: self.add_play_emit(
                        [item.get_song()['id'] for item in select_items])),
                ]
            else:
                items = [
                    (None, _("播放"), lambda: self.add_play_emit(
                        [current_item.get_song()['id']])),
                ]
            items.insert(0, (None, _("添加到"), addto_submenu))
            Menu(items, True).show((int(x), int(y)))
Esempio n. 4
0
 def right_press_items(self, widget, x, y, current_item, select_items):
     if current_item and select_items and nplayer.is_login:
         subscribe_submenu = [
             (None, _('**确定收藏**'), self.subscribe_playlist, current_item),
             (None, _(current_item.get_playlist['name']),
              self.subscribe_playlist, current_item),
             (None, _('**确定收藏**'), self.subscribe_playlist, current_item),
         ]
         menu_items = [
             (None, _('收藏歌单'), Menu(subscribe_submenu)),
         ]
         Menu(menu_items, True).show((x, y))
Esempio n. 5
0
    def popup_detail_menu(self, widget, x, y, item, select_items):
        if self.detail_menu != None:
            self.detail_menu.destroy()
        play_mode_menu = self.current_item.song_view.get_playmode_menu(
            align=True)
        sort_dict = OrderedDict()
        sort_dict["file"] = _("By Filename")
        sort_dict["title"] = _("By Title")
        sort_dict["artist"] = _("By Artist")
        sort_dict["album"] = _("By Album")
        sort_dict["genre"] = _("By Genre")
        sort_dict["#track"] = _("By Track")
        sort_dict["#playcount"] = _("By Play Count")
        sort_dict["#added"] = _("By Date Added")

        sort_items = [(None, value,
                       self.current_item.song_view.set_sort_keyword, key)
                      for key, value in sort_dict.iteritems()]
        sort_items.append(None)
        sort_items.append(
            (None, _("Randomize"), self.current_item.song_view.random_reorder))
        sub_sort_menu = Menu(sort_items)
        add_to_list_menu = self.get_edit_sub_menu(select_items)
        move_to_list_menu = self.get_edit_sub_menu(select_items, True)
        self.detail_menu = Menu([
            (None, _("Play"), self.current_item.song_view.play_select_item),
            (None, _("Add to List"), add_to_list_menu),
            (None, _("move to List"), move_to_list_menu),
            None,
            (None, _("Remove Track"),
             self.current_item.song_view.remove_select_items),
            (None, _("Move to Trash"),
             self.current_item.song_view.try_move_trash),
            (None, _("Clear List"), self.current_item.song_view.erase_items),
            None,
            (None, _("Playback Order"), play_mode_menu),
            (None, _("Sort"), sub_sort_menu),
            (None, _("Convert"), self.current_item.song_view.songs_convert),
            (None, _("Open directory"),
             self.current_item.song_view.open_song_dir),
            (None, _("Properties"),
             self.current_item.song_view.open_song_editor),
        ], True)

        if item and item.song.get_type() == "cue":
            self.detail_menu.set_menu_item_sensitive_by_index(5, False)
            self.detail_menu.set_menu_item_sensitive_by_index(10, False)
        self.detail_menu.show((int(x), int(y)))
Esempio n. 6
0
 def get_add_menu(self):    
     menu_items = [
         (None, _("File"), self.add_file),
         (None, _("Directory(include subdirectories)"), self.recursion_add_dir),
         (None, _("Directory"), self.add_dir),
         ]
     return Menu(menu_items)
 def popup_desktop_right_menu(self, widget, event):
     if event.button == 3 and Player.song:
         adjust_menu_item = [(None, _("Forward 0.5 seconds"),
                              lambda: self.after_offset(None)),
                             (None, _("Rewind 0.5 seconds"),
                              lambda: self.before_offset(None))]
         menu_items = [
             (None, _("Search"), lambda: self.open_search_window(None)),
             (None, _("Adjust lyrics"), Menu(adjust_menu_item)), None,
             (None, _("Choose local lrc"), self.allocation_lrc),
             (None, _("Open directory"), self.open_lrc_dir), None,
             (None, _("Settings"), lambda: self.open_setting_window(None)),
             (None, _("Switch to window mode"),
              lambda: self.switch_to_scroll_lyrics(None))
         ]
         Menu(menu_items, True).show((int(event.x_root), int(event.y_root)))
Esempio n. 8
0
 def get_convert_sub_menu(self):
     menu_items = [
         (None, _("Convert"), self.choose_file_and_convert),
         (None, _("Task Manager"),
          lambda: convert_task_manager.visible_it()),
     ]
     return Menu(menu_items)
Esempio n. 9
0
    def show_instance_menu(self, obj, x, y):
        curren_view = self.playlist_ui.get_selected_song_view()
        menu_items = [
            (None, _("Add"), curren_view.get_add_menu()),
            (None, _("Controls"), self.get_play_control_menu()),
            (self.get_pixbuf_group("playmode"), _("Playback Order"),
             curren_view.get_playmode_menu()),
            None,
            (None, _("Equalizer"), lambda: self.equalizer_win.run()),
            (None, _("Convert"), self.get_convert_sub_menu()),
            None,
            self.get_app_mode_menu(),
            None,
            self.get_lyrics_menu_items(),
            self.get_locked_menu_items(),
            None,
            (None, _("View New Features"), self.show_wizard_win),
            (self.get_pixbuf_group("setting"), _("Preferences"),
             lambda: self.preference_dialog.show_all()),
            None,
            (self.get_pixbuf_group("close"), _("Quit"), self.force_quit),
        ]

        if config.getboolean("lyrics", "status"):
            menu_items.insert(10, (None, _("Search Lyrics"),
                                   lambda: Dispatcher.emit("search-lyrics")))

        Menu(menu_items, True).show((x, y))
Esempio n. 10
0
    def update_menu(self):
        menu_items = []
        if Player.is_paused():
            pixbuf_group = self.get_pixbuf_group("play")
            status_label = _("Play")
        else:
            pixbuf_group = self.get_pixbuf_group("pause")
            status_label = _("Pause")
        menu_items.append((pixbuf_group, status_label, Player.playpause))
        menu_items.append((self.get_pixbuf_group("previous"), _("Previous"), Player.previous))
        menu_items.append((self.get_pixbuf_group("next"), _("Next"), Player.next))
        menu_items.append(None)
        menu_items.append((self.get_pixbuf_group("volume"), _("Volume"), self.get_volume_menu()))
        menu_items.append(None)

        if config.getboolean("lyrics", "status"):
            menu_items.append((None, _("Close Lyrics"), lambda: Dispatcher.close_lyrics()))
            menu_items.append((None, _("Search Lyrics"), lambda: Dispatcher.emit("search-lyrics")))
        else:
            menu_items.append((None, _("Show Lyrics"), lambda: Dispatcher.show_lyrics()))

        if config.getboolean("lyrics", "locked"):
            menu_items.append((self.get_pixbuf_group("unlock"), _("Unlock Lyrics"), lambda: Dispatcher.unlock_lyrics()))
        else:
            menu_items.append((self.get_pixbuf_group("lock"), _("Lock Lyrics"), lambda: Dispatcher.lock_lyrics()))

        menu_items.append(None)
        menu_items.append((self.get_pixbuf_group("setting"), _("Preferences"), lambda: Dispatcher.show_setting()))
        menu_items.append((self.get_pixbuf_group("close"), _("Quit"), lambda: Dispatcher.quit()))
        if self.menu is not None:
            del self.menu
        self.menu = Menu(menu_items, True)
Esempio n. 11
0
 def get_volume_menu(self):
     menu_items = [
         (None, _("Volume Up"), Player.increase_volume),
         (None, _("Volume Down"), Player.decrease_volume),
         (None, _("Mute"), Player.mute_volume),
     ]
     return Menu(menu_items)
Esempio n. 12
0
 def popup_list_menu(self, widget, event):
     menu_items = [(None, _("New List"), self.new_list),
                   (None, _("Import List"), self.leading_in_list),
                   (None, _("Open List"), self.add_to_list),
                   (None, _("Export List"), self.leading_out_list),
                   (None, _("Remove List"), self.delete_item_list), None,
                   (None, _("Save all Lists"), self.save_all_list)]
     Menu(menu_items, True).show((int(event.x_root), int(event.y_root)))
Esempio n. 13
0
 def popup_add_menu(self, x, y):
     menu_items = [
         (None, _("URL") , self.add_unknow_uri),            
         (None, _("File"), self.add_file),
         (None, _("Directory (include subdirectories)"), self.recursion_add_dir),
         (None, _("Directory"), self.add_dir),
         ]
     Menu(menu_items, True).show((x, y))
Esempio n. 14
0
 def popup_delete_menu(self, x, y):
     items = [
         (None, _("Remove Track from this List"), self.remove_select_items),
         (None, _("Remove Unavailable Tracks"), self.delete_error_items),
         (None, _("Move to Trash"), lambda: self.try_move_trash()),
         (None, _("Clear List"), self.erase_items)
     ]
     Menu(items, True).show((int(x), int(y)))
    def popup_right_menu(self, widget, x, y, item, select_items):
        menu_items = [
            (None, _("Play"), self.play_song),
            (None, _("Add to Playlist"), self.emit_to_playlist),
            None,
            (None, _("Remove from Library"), self.remove_songs),
            (None, _("Move to Trash"), lambda : self.try_move_trash()),
            None,
            (None, _("Open Directory"), self.open_song_dir),
            (None, _("Converter"), self.songs_convert),
            (None, _("Properties"), self.open_song_editor)
                        ]

        right_menu = Menu(menu_items, True)
        if item.song.get_type() == "cue":
            right_menu.set_menu_item_sensitive_by_index(4, False)
            right_menu.set_menu_item_sensitive_by_index(7, False)
        right_menu.show((int(x), int(y)))    
Esempio n. 16
0
 def popup_right_menu(self, widget, x, y, item, select_items):        
     menu_items = [
         # (None, _("优先转换"), self.set_job_priority, item),
         (None, _("Open directory"), lambda : utils.open_file_directory(item.output_path)),
         None,            
         (None, _("Delete task"), self.delete_job, item),            
         (None, _("Clear finished tasks"), self.delete_finish_jobs)
         ]
     Menu(menu_items, True).show((int(x), int(y)))
Esempio n. 17
0
    def update_menu(self):
        menu_items = []
        if Player.is_paused():
            pixbuf_group = self.get_pixbuf_group("play")
            status_label = _("Play")
        else:
            pixbuf_group = self.get_pixbuf_group("pause")
            status_label = _("Pause")
        menu_items.append((pixbuf_group, status_label, Player.playpause))
        menu_items.append((self.get_pixbuf_group("previous"), _("Previous"),
                           Player.previous))
        menu_items.append(
            (self.get_pixbuf_group("next"), _("Next"), Player.next))
        menu_items.append(None)
        menu_items.append((self.get_pixbuf_group("volume"), _("Volume"),
                           self.get_volume_menu()))
        menu_items.append(None)

        if config.getboolean("lyrics", "status"):
            menu_items.append(
                (None, _("Close Lyrics"), lambda: Dispatcher.close_lyrics()))
            menu_items.append((None, _("Search Lyrics"),
                               lambda: Dispatcher.emit("search-lyrics")))
        else:
            menu_items.append(
                (None, _("Show Lyrics"), lambda: Dispatcher.show_lyrics()))

        if config.getboolean("lyrics", "locked"):
            menu_items.append(
                (self.get_pixbuf_group("unlock"), _("Unlock Lyrics"),
                 lambda: Dispatcher.unlock_lyrics()))
        else:
            menu_items.append((self.get_pixbuf_group("lock"), _("Lock Lyrics"),
                               lambda: Dispatcher.lock_lyrics()))

        menu_items.append(None)
        menu_items.append((self.get_pixbuf_group("setting"), _("Preferences"),
                           lambda: Dispatcher.show_setting()))
        menu_items.append((self.get_pixbuf_group("close"), _("Quit"),
                           lambda: Dispatcher.quit()))
        if self.menu is not None:
            del self.menu
        self.menu = Menu(menu_items, True)
    def __on_right_click_item(self, widget, item, x, y):
        menu_items = [(None, _("Pair"), lambda: item.do_pair())]
        if item.is_paired:
            menu_items = []
            menu_items.extend(item.menu_items)
            menu_items.append(None)
            menu_items.append((None, _("Remove Device"),
                               lambda: self.__do_remove_item(item)))

        Menu(menu_items, True).show((int(x), int(y)))
Esempio n. 19
0
 def show_right_menu(self, widget, event):
     menu_items = [
         (self.get_menu_pixbuf_group("artist"), _("By Artist"),
          self.update_widget_icon, "artist", _("By Artist")),
         (self.get_menu_pixbuf_group("genre"), _("By Genre"),
          self.update_widget_icon, "genre", _("By Genre")),
         (self.get_menu_pixbuf_group("album"), _("By Album"),
          self.update_widget_icon, "album", _("By Album")),
     ]
     Menu(menu_items, True).show(
         (int(event.x_root) - 10, int(event.y_root)))
Esempio n. 20
0
 def on_right_press_items(self, widget, x, y, current_item, select_items):
     if current_item and select_items:
         if len(select_items) > 1:
             items = [(None, _("Delete"),
                       lambda: self.delete_items(select_items)),
                      (None, _("Clear List"), lambda: self.clear_items())]
         else:
             items = [(None, _("Play"),
                       lambda: self.play_item(current_item)),
                      (None, _("Delete"),
                       lambda: self.delete_items([current_item])),
                      (None, _("Clear List"), lambda: self.clear_items())]
         Menu(items, True).show((int(x), int(y)))
 def popup_predefine_menu(self, widget, event):    
     menu_dict = OrderedDict()
     menu_dict["vitality_yellow"] = _("Vitality yellow")
     menu_dict["fresh_green"]  = _("Fresh green")
     menu_dict["playful_pink"] = _("Playful pink")
     menu_dict["cool_blue"] = _("Cool blue")
     
     menu_items = []
     save_predefine_color = config.get("lyrics", "predefine_color", "vitality_yellow")
     for key, value in menu_dict.iteritems():
         item_pixbuf = None
         if key == save_predefine_color:
             item_pixbuf = (app_theme.get_pixbuf("menu/tick.png"),
                            app_theme.get_pixbuf("menu/tick_press.png"),
                            app_theme.get_pixbuf("menu/tick_disable.png"))
             
         if item_pixbuf is None:    
             menu_items.append((None, value, self.set_predefine_color, key))    
         else:    
             menu_items.append((item_pixbuf, value, self.set_predefine_color, key))    
     predefine_menu = Menu(menu_items, True)
     predefine_menu.show((int(event.x_root), int(event.y_root)))
Esempio n. 22
0
 def get_edit_sub_menu(self, select_items, move=False):    
     sub_menu_items = []
     if len(self.category_list.get_items()) > 1:
         other_category_items = self.get_categroy_other_items()
         sub_menu_items = [(None, category_item.get_title(), 
                            self.edit_list_item, category_item, select_items ,move) for category_item in other_category_items]
     if sub_menu_items:    
         sub_menu_items.extend([None, ((app_theme.get_pixbuf("toolbar/add_normal.png"), None, None),
                                       _("New List"), self.edit_new_list_item, select_items, move)])
     else:    
         sub_menu_items.extend([((app_theme.get_pixbuf("toolbar/add_normal.png"), None, None),
                                 _("New List"), self.edit_new_list_item, select_items, move)])
     return Menu(sub_menu_items)
Esempio n. 23
0
 def __init__(self, screenshot):
     self.screenshot = screenshot    # a DeepinScreenshot object
     # sub menu in save node
     menu_item = [
         (None, _("save automatically"), self.save_sub_menu_clicked, SAVE_OP_AUTO),
         (None, _("save as"), self.save_sub_menu_clicked, SAVE_OP_AS),
         (None, _("save to clipboard"), self.save_sub_menu_clicked, SAVE_OP_CLIP),
         (None, _("save automatically to file and clipboard"), self.save_sub_menu_clicked, SAVE_OP_AUTO_AND_CLIP)]
     self.save_sub_menu = save_sub_menu = Menu(menu_item, 
         menu_item_select_color=app_theme.get_shadow_color("menu_item_select").get_color_info())
     # right button menu
     self.window = Menu([
         ((app_theme_get_dynamic_pixbuf('image/action_menu/rect_normal.png'),
           app_theme_get_dynamic_pixbuf('image/action_menu/rect_hover.png'),
           app_theme_get_dynamic_pixbuf('image/action_menu/rect_normal.png')),
           _("draw rectangle"), self._menu_click, "rect"),
         ((app_theme_get_dynamic_pixbuf('image/action_menu/ellipse_normal.png'),
           app_theme_get_dynamic_pixbuf('image/action_menu/ellipse_hover.png'),
           app_theme_get_dynamic_pixbuf('image/action_menu/ellipse_normal.png')),
           _("draw ellipse"), self._menu_click, "ellipse"),
         ((app_theme_get_dynamic_pixbuf('image/action_menu/arrow_normal.png'), 
           app_theme_get_dynamic_pixbuf('image/action_menu/arrow_hover.png'), 
           app_theme_get_dynamic_pixbuf('image/action_menu/arrow_normal.png')), 
           _("draw arrow"), self._menu_click, "arrow"),
         ((app_theme_get_dynamic_pixbuf('image/action_menu/line_normal.png'), 
           app_theme_get_dynamic_pixbuf('image/action_menu/line_hover.png'), 
           app_theme_get_dynamic_pixbuf('image/action_menu/line_normal.png')), 
           _("draw line"), self._menu_click, "line"),
         ((app_theme_get_dynamic_pixbuf('image/action_menu/text_normal.png'), 
           app_theme_get_dynamic_pixbuf('image/action_menu/text_hover.png'), 
           app_theme_get_dynamic_pixbuf('image/action_menu/text_normal.png')), 
           _("draw Text"), self._menu_click, "text"),
         None,
         ((app_theme_get_dynamic_pixbuf('image/action_menu/undo_normal.png'), 
           app_theme_get_dynamic_pixbuf('image/action_menu/undo_hover.png'), 
           app_theme_get_dynamic_pixbuf('image/action_menu/undo_normal.png')), 
           _("undo"), self._menu_click, "undo"),
         ((app_theme_get_dynamic_pixbuf('image/action_menu/save_normal.png'), 
           app_theme_get_dynamic_pixbuf('image/action_menu/save_hover.png'), 
           app_theme_get_dynamic_pixbuf('image/action_menu/save_normal.png')), 
           _("save"), save_sub_menu),
         ((app_theme_get_dynamic_pixbuf('image/action_menu/cancel_normal.png'), 
           app_theme_get_dynamic_pixbuf('image/action_menu/cancel_hover.png'), 
           app_theme_get_dynamic_pixbuf('image/action_menu/cancel_normal.png')), 
           _("cancel"), self._menu_click, "cancel"),
         ((app_theme_get_dynamic_pixbuf('image/action_menu/share_normal.png'), 
           app_theme_get_dynamic_pixbuf('image/action_menu/share_hover.png'), 
           app_theme_get_dynamic_pixbuf('image/action_menu/share_normal.png')), 
           _("share"), self._menu_click, "share"),
         ], True,
         menu_item_select_color=app_theme.get_shadow_color("menu_item_select").get_color_info())
Esempio n. 24
0
    def on_category_right_press(self, widget, x, y, item, column):
        if not item:
            menu_items = [(None, _("New List"), self.new_list),
                          (None, _("Import List"), self.leading_in_list), None,
                          (None, _("Save all Lists"), self.save_all_list)]
        else:
            menu_items = [
                (None, _("Rename"), lambda: self.rename_item_list(item)),
                (None, _("Remove List"), lambda: self.delete_item_list(item)),
                (None, _("Open List"), lambda: self.add_to_list(item)), None,
                (None, _("Save all Lists"), self.save_all_list)
            ]

        Menu(menu_items, True).show((x, y))
Esempio n. 25
0
    def get_playmode_menu(self, pos=[], align=False):
        mode_dict = OrderedDict()

        mode_dict["single_mode"] = _("Repeat (single)")
        mode_dict["order_mode"] = _("Order play")
        mode_dict["list_mode"] = _("Repeat (list)")
        mode_dict["random_mode"] = _("Randomize")

        mode_items = []
        for key, value in mode_dict.iteritems():
            if self.get_loop_mode() == key:
                tick = (app_theme.get_pixbuf("menu/tick.png"),
                        app_theme.get_pixbuf("menu/tick_press.png"),
                        app_theme.get_pixbuf("menu/tick_disable.png"))
                mode_items.append((tick, value, self.set_loop_mode, key))
            else:
                tick = None
                mode_items.append((None, value, self.set_loop_mode, key))

        if pos:
            Menu(mode_items, True).show((pos[0], pos[1]))
        else:
            return Menu(mode_items)
Esempio n. 26
0
    def popup_predefine_menu(self, widget, event):
        menu_dict = OrderedDict()
        menu_dict["vitality_yellow"] = _("Vitality yellow")
        menu_dict["fresh_green"] = _("Fresh green")
        menu_dict["playful_pink"] = _("Playful pink")
        menu_dict["cool_blue"] = _("Cool blue")

        menu_items = []
        save_predefine_color = config.get("lyrics", "predefine_color",
                                          "vitality_yellow")
        for key, value in menu_dict.iteritems():
            item_pixbuf = None
            if key == save_predefine_color:
                item_pixbuf = (app_theme.get_pixbuf("menu/tick.png"),
                               app_theme.get_pixbuf("menu/tick_press.png"),
                               app_theme.get_pixbuf("menu/tick_disable.png"))

            if item_pixbuf is None:
                menu_items.append((None, value, self.set_predefine_color, key))
            else:
                menu_items.append(
                    (item_pixbuf, value, self.set_predefine_color, key))
        predefine_menu = Menu(menu_items, True)
        predefine_menu.show((int(event.x_root), int(event.y_root)))
Esempio n. 27
0
 def get_add_online_list_menu(self, select_items):        
     category_items = [item for item in self.category_view.items if item.list_type == self.PLAYLIST_TYPE]
     if len(category_items) <= 0:
         return None
     
     songs = [ item.song for item in select_items ]
     sids = self.get_sids(select_items)
     
     def add_song_to_list(item, songs, sids):
         item.add_songs(songs, pos=0)
         pid = item.list_id
         bplayer.add_list_song(pid, sids)            
                 
     menu_items = [(None, item.title, add_song_to_list, item, songs, sids) for item in category_items ]
     return Menu(menu_items)
Esempio n. 28
0
 def scroll_right_press_cb(self, widget, event):
     menu_items = [
         (self.get_scroll_menu_pixbufs("lrc"), _("Switch to desktop mode"),
          self.switch_to_desktop_lyrics),
         None,
         (self.get_scroll_menu_pixbufs("before"), _("Lyrics rewind"),
          lambda: self.before_offset(None)),
         (self.get_scroll_menu_pixbufs("after"), _("Lyrics forward"),
          lambda: self.after_offset(None)),
         None,
         (self.get_scroll_menu_pixbufs("search"), _("Search"),
          lambda: self.open_search_window(None)),
         (self.get_scroll_menu_pixbufs("setting"), _("Settings"),
          lambda: Dispatcher.show_scroll_page()),
     ]
     Menu(menu_items, True).show((int(event.x_root), int(event.y_root)))
Esempio n. 29
0
 def get_play_control_menu(self):
     menu_items = []
     if Player.is_paused():
         state_label = _("Play")
         state_pixbuf = self.get_pixbuf_group("play")
     else:
         state_label = _("Pause")
         state_pixbuf = self.get_pixbuf_group("pause")
     menu_items.append((state_pixbuf, state_label, Player.playpause))
     control_items = [
         (self.get_pixbuf_group("forward"), _("Forward"), Player.forward),
         (self.get_pixbuf_group("rewind"), _("Rewind"), Player.rewind),
         (self.get_pixbuf_group("previous"), _("Previous"),
          Player.previous),
         (self.get_pixbuf_group("next"), _("Next"), Player.next),
     ]
     menu_items.extend(control_items)
     return Menu(menu_items)
Esempio n. 30
0
 def _list_menu_show(self, button, x, y, offset_x, offset_y):
     '''the combo button clicked callback. show combo_buton list menu'''
     menu_item = [
         (None, _("Save automatically"), self._list_menu_click, SAVE_OP_AUTO, button),
         (None, _("Save as"), self._list_menu_click, SAVE_OP_AS, button),
         (None, _("Save to clipboard"), self._list_menu_click, SAVE_OP_CLIP, button),
         (None, _("Save automatically to file and clipboard"), self._list_menu_click, SAVE_OP_AUTO_AND_CLIP, button)]
     # set current operate icon
     current_item = menu_item[self.screenshot.save_op_index] 
     menu_pixbuf = (
         app_theme.get_pixbuf("action/selected.png"),
         app_theme.get_pixbuf("action/selected_hover.png"),
         app_theme.get_pixbuf("action/selected.png"))
     menu_item[self.screenshot.save_op_index] = (menu_pixbuf, 
         current_item[1], current_item[2], current_item[3])
     self.combo_menu = Menu(menu_item, is_root_menu=True, 
         menu_item_select_color=app_theme.get_shadow_color("menu_item_select").get_color_info())
     self.set_all_inactive()
     self.combo_menu.show((x, y), (offset_x, offset_y))
Esempio n. 31
0
 def __on_right_press_items(self, widget, x, y, current_item, select_items):
     if current_item and select_items:
         if len(select_items) > 1:
             items = [
                 (None, _("Add to Playlist"),
                  lambda: self.emit_to_playlist(select_items)),
                 # (None, _("Delete"), None),
             ]
         else:
             items = [
                 (None, _("Play"),
                  lambda: Dispatcher.play_webcast(current_item.webcast)),
                 (None, _("Add to Playlist"),
                  lambda: self.emit_to_playlist([current_item])),
                 self.get_favorite_menu_item(current_item),
                 # None,
                 # (None, _("Clear List"), None),
             ]
         Menu(items, True).show((int(x), int(y)))
Esempio n. 32
0
 def __on_right_click_item(self, widget, item, x, y):
     if not item: return
     menu_items = [
         (None, _("Play All"), lambda : self.play_item(item)),
         (None, _("Add to List"), lambda : self.emit_to_list(item)),
         None,
         (None, _("Remove from Library"), lambda : self.real_remove_item(item)),
         (None, _("Move to Trash"), lambda : self.try_move_trash(item)),
         None,
         ]
     
     if item.tag == "folder":
         menu_items.append((None, _("Open Directory"), lambda : utils.open_directory(item.value_name)))
     elif item.tag in ["artist", "album"] and item.key_name != "deepin-all-songs":    
         menu_items.append((None, _("Change Cover"), lambda : self.change_item_cover(item)))
     else:    
         menu_items.pop()
         
     Menu(menu_items, True).show((int(x), int(y)))    
Esempio n. 33
0
    def popup_right_menu(self, widget, x, y, item, select_items):
        menu_items = [
            (None, _("Play"), self.play_song),
            (None, _("Add to Playlist"), self.emit_to_playlist), None,
            (None, _("Remove from Library"), self.remove_songs),
            (None, _("Move to Trash"), lambda: self.try_move_trash()), None,
            (None, _("Open Directory"), self.open_song_dir),
            (None, _("Converter"), self.songs_convert),
            (None, _("Properties"), self.open_song_editor)
        ]

        right_menu = Menu(menu_items, True)
        if item.song.get_type() == "cue":
            right_menu.set_menu_item_sensitive_by_index(4, False)
            right_menu.set_menu_item_sensitive_by_index(7, False)
        right_menu.show((int(x), int(y)))
Esempio n. 34
0
    def popup_detail_menu(self, widget, x, y, item, select_items):
        if self.detail_menu != None:
            self.detail_menu.destroy()
        play_mode_menu = self.current_item.song_view.get_playmode_menu(align=True)
        sort_dict = OrderedDict()
        sort_dict["file"] = _("By Filename")
        sort_dict["title"] = _("By Title")
        sort_dict["artist"] = _("By Artist")
        sort_dict["album"] = _("By Album")
        sort_dict["genre"] = _("By Genre")
        sort_dict["#track"] = _("By Track")
        sort_dict["#playcount"] = _("By Play Count")
        sort_dict["#added"] = _("By Added Time")

        sort_items = [(None, value, self.current_item.song_view.set_sort_keyword, key) for key, value in sort_dict.iteritems()]
        sort_items.append(None)
        sort_items.append((None, _("Randomize"), self.current_item.song_view.random_reorder))
        sub_sort_menu = Menu(sort_items)
        add_to_list_menu = self.get_edit_sub_menu(select_items)
        move_to_list_menu = self.get_edit_sub_menu(select_items, True)
        self.detail_menu = Menu([(None, _("Play"),  self.current_item.song_view.play_select_item),
                                 (None, _("Add to List"), add_to_list_menu),
                                 (None, _("Move to List"), move_to_list_menu),
                                 None,
                                 (None, _("Remove Track"), self.current_item.song_view.remove_select_items),
                                 (None, _("Move to Trash"), self.current_item.song_view.try_move_trash),
                                 (None, _("Clear List"), self.current_item.song_view.erase_items),
                                 None,
                                 (None, _("Playback mode"), play_mode_menu),
                                 (None, _("Sort"), sub_sort_menu),
                                 (None, _("Converter"), self.current_item.song_view.songs_convert),
                                 (None, _("Open directory"), self.current_item.song_view.open_song_dir),
                                 (None, _("Properties"), self.current_item.song_view.open_song_editor),
                                 ], True)

        if item and item.song.get_type() == "cue":
            self.detail_menu.set_menu_item_sensitive_by_index(5, False)
            self.detail_menu.set_menu_item_sensitive_by_index(10, False)
        self.detail_menu.show((int(x), int(y)))
Esempio n. 35
0
 def on_music_view_right_press_items(self, widget, x, y, current_item, select_items):
     if current_item and select_items:
         if len(select_items) > 1:
             items = [
                 (None, _("Delete"), lambda : self.delete_items(select_items)),
                 (None, _("Clear List"), lambda : self.clear_items())
                 ]
         else:    
             items = [
                 (None, _("Play"), lambda : self.request_song(current_item.get_song())),
                 (None, _("Delete"), lambda : self.delete_items([current_item])),
                 (None, _("Clear List"), lambda : self.clear_items())
                 ]
             
         if self.view_type != self.PLAYLIST_TYPE and bplayer.is_login:
             sub_menu = self.get_add_online_list_menu(select_items)                    
             if sub_menu:
                 items.insert(1, (None, "添加到歌单", sub_menu))
                 
             if self.view_type != self.COLLECT_TYPE:    
                 
                 collect_items = filter(lambda item: item.list_type == self.COLLECT_TYPE, self.category_view.items)
                 if len(collect_items) > 0:
                     
                     collect_item = collect_items[0]
                     songs = [ item.song for item in select_items ]
                     sids = self.get_sids(select_items)
                     
                     def add_to_collect(item, songs, sids):
                         item.add_songs(songs, pos=0)
                         bplayer.add_collect_song(sids)
                                                             
                     items.insert(1, (None, "收藏", add_to_collect, collect_item, songs, sids))
                     
             
         Menu(items, True).show((int(x), int(y)))   
Esempio n. 36
0
    def init_root_menu(self):
        # Init file menu.
        file_menu = Menu([
            (None, "新建", lambda: self.code_edit.clear()),  # 清空代码编辑器.
            (None, "打开", lambda: self.open_file_dialog_window()),
            (None),
            (None, "我的程序...", None),
            (None),
            (None, "保存", lambda: self.code_edit.save()),
            (None, "另存为", None),
            (None),
            (None, "退出", lambda: gtk.main_quit())
        ])
        # Init edit menu.
        edit_menu = Menu([(None, "剪切", None), (None, "复制", None),
                          (None, "粘帖", None), (None, "全选", None), (None),
                          (None, "注释", lambda: self.notes_line()),
                          (None, "取消注释", lambda: self.notes_line()), (None),
                          (None, "撤销", None), (None, "恢复", None), (None),
                          (None, "查找", None), (None, "替换", None),
                          (None, "定位到行", None)])
        # Init run menu.
        run_menu = Menu([(None, "编译成目标文件", None), (None, "生成可执行文件", None),
                         (None, "生成动态链接库文件", None), (None, "运行", None),
                         (None, "多模块链接", None), (None, "调试", None),
                         (None, "运行LINUX控制台程序", None)])
        # Init tool menu.
        tool_menu = Menu([(None, "选项", None),
                          (None, "计算器", lambda: open_gcalctool())])
        # Init help menu.
        help_menu = Menu([
            (None, "帮助主题", None),
            (None, "关于", None),
        ])

        # Init root menu.
        self.root_menu = Menu([
            (None, "文件", file_menu),
            (None, "编辑", edit_menu),
            (None, "运行", run_menu),
            (None, "工具", tool_menu),
            (None, "帮助", help_menu),
        ], True)
Esempio n. 37
0
class Toolbar(object):
    ''' Toolbar window'''
    def __init__(self, parent=None, screenshot=None):
        '''
        init toolbar
        @param parent: the transient parent for this window
        @param screenshot: a Screenshot object
        '''
        self.screenshot = screenshot
        self.win = screenshot.window
        self.__config = OperateConfig()
        save_op = self.__config.get("save", "save_op")
        if save_op:
            self.screenshot.save_op_index = int(save_op)
        else:
            self.screenshot.save_op_index = SAVE_OP_AUTO

        #toolbar_padding_x = 15
        #toolbar_padding_y = 5
        #toolbar_icon_width = toolbar_icon_height = 28
        #toolbar_icon_num = 10
        #self.height = toolbar_icon_height + toolbar_padding_y * 2
        self.height = 30
        self.width = 279
        #self.width = 240

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

        self.toolbox = gtk.HBox(False, 6)
        toolbox_align = gtk.Alignment()
        toolbox_align.set(0, 0.5, 0, 0)
        toolbox_align.set_padding(2, 2, 11, 11)
        toolbox_align.add(self.toolbox)
        self.window.window_frame.pack_start(toolbox_align, True, True)
        #self.window.set_size_request(self.width, self.height)
        self.window.set_size_request(-1, self.height)

        self._toggle_button_list = []
        self.__button_accelerator_dict = {}
        self._toggle_button_group = ToggleButtonGroup([], 6)
        self.toolbox.pack_start(self._toggle_button_group)
        self.create_toggle_button("rect", ACTION_RECTANGLE, 0, _("Draw Rectangle"), "<Alt>1")
        self.create_toggle_button("ellipse", ACTION_ELLIPSE, 1, _("Draw Ellipse"), "<Alt>2")
        self.create_toggle_button("arrow",ACTION_ARROW, 2, _("Draw Arrow"), "<Alt>3")
        self.create_toggle_button("line",ACTION_LINE, 3, _("Draw Line"), "<Alt>4")
        self.create_toggle_button("text",ACTION_TEXT, 4, _("Draw Text"), "<Alt>5")

        self.create_button("undo", _("Undo"), "<Alt>6")

        if self.screenshot.is_subprocess:
            self.create_button("save", _("Save"), "<Alt>7")
        else:
            # pack save and list button
            save_combo_button = ComboButton(
                app_theme.get_pixbuf("action/save_normal.png"),
                app_theme.get_pixbuf("action/save_hover.png"),
                app_theme.get_pixbuf("action/save_press.png"),
                app_theme.get_pixbuf("action/save_normal.png"),
                app_theme.get_pixbuf("action/list_normal.png"),
                app_theme.get_pixbuf("action/list_hover.png"),
                app_theme.get_pixbuf("action/list_press.png"),
                app_theme.get_pixbuf("action/list_normal.png"),)
            save_combo_button.set_name("save")
            save_combo_button.connect("button-clicked", self._button_clicked, "save")
            save_combo_button.connect("arrow-clicked", self._list_menu_show)
            save_tip_text_list = ["Save automatically", "Save as", "Save to clipboard", "Save automatically to file and clipboard"]
            tip_text = save_tip_text_list[self.screenshot.save_op_index]
            save_combo_button.connect("enter-notify-event", self._show_tooltip, _(tip_text))
            self.toolbox.pack_start(save_combo_button)

        self.create_button("cancel", _("Cancel"), "<Alt>8")

        if not self.screenshot.is_subprocess:
            self.create_button("share", _("Share"), "<Alt>9")

        if self.screenshot:
            self._button_clicked_cb = {
                'undo': self.screenshot.undo,
                'save': self.save_operate,
                'cancel': self.win.quit,
                'share': self.share_picture}

    def create_toggle_button(self, name, action, index, text='', accel_key=None):
        '''
        create a togglebutton
        @param name: the button's name, a string
        @param action: one of ACTION Type Constants 
        @param index: the button's index in button list, an int num
        @param text: the button's tooltip text, a string
        '''
        button = ToggleButtonItem(
            (app_theme.get_pixbuf("action/" + name + "_normal.png"),
             app_theme.get_pixbuf("action/" + name + "_press.png"),
             app_theme.get_pixbuf("action/" + name + "_hover.png"),
             app_theme.get_pixbuf("action/" + name + "_press.png"), None),
            index, self._toggle_button_group.set_index, self._toggle_button_group.get_index)
        button.connect("pressed", self._toggle_button_pressed)
        button.connect("toggled", self._toggle_button_toggled, action)
        button.connect("enter-notify-event", self._show_tooltip, text)
        button.set_name(name)
        #self.toolbox.pack_start(button)
        self._toggle_button_group.pack_start(button)
        self._toggle_button_list.append(button)
        if accel_key:
            self.__button_accelerator_dict[gtk.accelerator_name(
                                           *gtk.accelerator_parse(accel_key))] = button

    def create_button(self, name, text='', accel_key=None):
        '''
        make a button
        @param name: the button's name, a string
        @param text: the button's tooltip text, a string
        '''
        button = ImageButton(
            app_theme.get_pixbuf("action/" + name + "_normal.png"),
            app_theme.get_pixbuf("action/" + name + "_hover.png"),
            app_theme.get_pixbuf("action/" + name + "_press.png"))
        button.connect("enter-notify-event", self._show_tooltip, text)
        button.connect("clicked", self._button_clicked, name)
        button.set_name(name)
        #button.set_size_request(28, 28)
        self.toolbox.pack_start(button)
        if accel_key:
            self.__button_accelerator_dict[gtk.accelerator_name(
                                           *gtk.accelerator_parse(accel_key))] = button
        return button

    def _show_tooltip(self, widget, event, text):
        '''the button enter-notify-event callback. Create help tooltip.'''
        #widget.set_has_tooltip(True)
        #widget.set_tooltip_text(text)
        #widget.trigger_tooltip_query()
        Tooltip.text(widget, text)

    def _list_menu_show(self, button, x, y, offset_x, offset_y):
        '''the combo button clicked callback. show combo_buton list menu'''
        menu_item = [
            (None, _("Save automatically"), self._list_menu_click, SAVE_OP_AUTO, button),
            (None, _("Save as"), self._list_menu_click, SAVE_OP_AS, button),
            (None, _("Save to clipboard"), self._list_menu_click, SAVE_OP_CLIP, button),
            (None, _("Save automatically to file and clipboard"), self._list_menu_click, SAVE_OP_AUTO_AND_CLIP, button)]
        # set current operate icon
        current_item = menu_item[self.screenshot.save_op_index] 
        menu_pixbuf = (
            app_theme.get_pixbuf("action/selected.png"),
            app_theme.get_pixbuf("action/selected_hover.png"),
            app_theme.get_pixbuf("action/selected.png"))
        menu_item[self.screenshot.save_op_index] = (menu_pixbuf, 
            current_item[1], current_item[2], current_item[3])
        self.combo_menu = Menu(menu_item, is_root_menu=True, 
            menu_item_select_color=app_theme.get_shadow_color("menu_item_select").get_color_info())
        self.set_all_inactive()
        self.combo_menu.show((x, y), (offset_x, offset_y))
    
    def _list_menu_click(self, save_op_index, button=None):
        '''list menu clicked callback'''
        self.screenshot.save_op_index = save_op_index
        self.__config.set("save", save_op=str(save_op_index))

        # reset the save button's tooltip
        if button:
            item = self.combo_menu.get_menu_items()[save_op_index]
            button.disconnect_by_func(self._show_tooltip)
            button.connect("enter-notify-event", self._show_tooltip, item.item[1])
            self.combo_menu.destroy()
        self.save_operate()

    def _button_clicked(self, widget, name):
        ''' button clicked callback '''
        if self.screenshot is None:
            return
        # save current input text
        if self.screenshot.show_text_window_flag:
            self.win.save_text_window()
        if name in self._button_clicked_cb:
            self._button_clicked_cb[name](widget)

    def _toggle_button_pressed(self, widget):
        ''' toggle button pressed callback '''
        # save current input text
        if self.screenshot.show_text_window_flag:
            self.win.save_text_window()
        widget.released()

    def _toggle_button_toggled(self, widget, action):
        ''' toggle button toggled callback'''
        if self.screenshot is None:
            return
        if widget.get_active():
            self.screenshot.set_action_type(action)
            self.win.set_cursor(action)
            self.win.show_colorbar()
            self.win.adjust_colorbar()
        elif widget.index == widget.get_index():
            self.win.set_cursor(None)
            self.win.hide_colorbar()
            if not self.screenshot.action_list and not self.screenshot.text_action_list and self.screenshot.show_toolbar_flag and not self.screenshot.window_flag:
                self.screenshot.set_action_type(ACTION_SELECT)
            elif self.screenshot.action_list:
                self.screenshot.set_action_type(None)
    
    def set_button_active(self, name, state):
        '''
        set button active
        @param name: the button's name which will set, a string type
        @param state: the state to set, True or False
        '''
        if self._toggle_button_group.is_active():
            button = self._toggle_button_list[self._toggle_button_group.get_index()]
            # if the button has been in this state, ignore
            if button.name == name:
                if button.get_active() == state:
                    return
            else:
                button.set_active(False)
                self._toggle_button_group.set_index(-1)
        i = 0
        for each in self._toggle_button_list:
            if name == each.get_name():
                each.set_active(state)
                self._toggle_button_group.set_index(i)
                break
            i += 1
    
    def has_button_active(self):
        '''
        is has one toggle button active
        @return: True if has one togglebutton active, otherwise False
        '''
        return self._toggle_button_group.is_active()
    
    def save_operate(self, widget=None):
        '''do save operate'''
        screenshot = self.screenshot
        if screenshot.is_subprocess:
            screenshot.save_to_tmp_file()
        else:
            # auto save
            if screenshot.save_op_index == SAVE_OP_AUTO:
                folder = utils.get_pictures_dir()
                filename = "%s%s.%s" % (_(DEFAULT_FILENAME), utils.get_format_time(), "png")
                screenshot.save_snapshot("%s/%s" % (folder, filename))
            # save as
            elif screenshot.save_op_index == SAVE_OP_AS:
                self.save_to_file()
            # copy to clip
            elif screenshot.save_op_index == SAVE_OP_CLIP:
                screenshot.save_snapshot()
            # auto save and copy to clip
            else:
                folder = utils.get_pictures_dir()
                filename = "%s%s.%s" % (_(DEFAULT_FILENAME), utils.get_format_time(), "png")
                screenshot.save_snapshot("%s/%s" % (folder, filename), clip_flag=True)
    
    def share_picture(self, widget):
        '''share picture. share button clicked callback'''
        self.screenshot.share_to_flag = True
        self.screenshot.save_op_index = SAVE_OP_AUTO
        self.save_operate()

    def save_to_file(self):
        ''' save to file '''
        self.win.hide_colorbar()
        self.win.hide_toolbar()
        #dialog = SaveFileDialog('', self.screenshot.window.window,
            #ok_callback=self._save_to_file_cb, cancel_callback=self._save_to_file_cancel)
        dialog = gtk.FileChooserDialog(
            "Save..",
            self.win.window,
            gtk.FILE_CHOOSER_ACTION_SAVE,
            (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT,
             gtk.STOCK_SAVE, gtk.RESPONSE_ACCEPT))
        dialog.set_action(gtk.FILE_CHOOSER_ACTION_SAVE)
        dialog.set_default_response(gtk.RESPONSE_ACCEPT)
        dialog.set_position(gtk.WIN_POS_MOUSE)
        dialog.set_local_only(True)
        last_folder = self.__config.get("save", "folder")
        if last_folder:
            dialog.set_current_folder(last_folder)
        else:
            dialog.set_current_folder(utils.get_pictures_dir())
        if config.OPTION_FILE:
            dialog.set_current_name(config.OPTION_FILE)
        else:
            dialog.set_current_name("%s%s.%s" % (_(DEFAULT_FILENAME), utils.get_format_time(), "png"))
        response = dialog.run()
        filename = dialog.get_filename()
        if response == gtk.RESPONSE_ACCEPT:
            self.__config.set("save", folder=dialog.get_current_folder())
            self._save_to_file_cb(filename)
        else:
            self._save_to_file_cancel(filename)
        dialog.destroy()

    def _save_to_file_cancel(self, filename):
        ''' save file dialog cancel_callback'''
        self.screenshot.share_to_flag = False
        self.win.adjust_toolbar()
        self.win.show_toolbar()
        if self.has_button_active():
            self.win.show_colorbar()
        
    def _save_to_file_cb(self, filename):
        ''' save file dialog ok_callback'''
        print "save", filename
        self.screenshot.save_snapshot(filename=filename)
    
    def set_all_inactive(self):
        '''set all toggle button inactive'''
        #index = self._toggle_button_group.get_index()
        #if index != -1:
            #self._toggle_button_list[index].set_active(False)
        #for each in self._toggle_button_list:
            #each.set_active(False)
        if self._toggle_button_group.is_active():
            self._toggle_button_group.set_index(-1)
    
    def accel_group_callback(self, group, acceleratable, keyval, modifier):
        accel_name = gtk.accelerator_name(keyval, modifier)
        if accel_name in self.__button_accelerator_dict:
            button = self.__button_accelerator_dict[accel_name]
            button.pressed()
            button.released()
            #button.clicked()
            self.set_button_active(button.get_name(), True)
        
    def show(self):
        ''' show the toolbar '''
        if not self.window.get_visible():
            self.window.show_window()
        #print "toolbox:", self.toolbox.allocation, self.window.allocation

    def hide(self):
        '''hide the toolbar'''
        if self.window.get_visible():
            self.window.hide_all()
Esempio n. 38
0
      None,
      (None, "子菜单B2", None),
      None,
      (None, "子菜单B3", sub_menu_c),
      ])
 
 menu = Menu(
     [(None,
       "测试测试测试1", lambda : PopupWindow(application.window)),
      (None,
       "测试测试测试2", sub_menu_a),
      (None,
       "测试测试测试3", sub_menu_b),
      (None,
       "测试测试测试", None),
      (None,
       "测试测试测试", None),
      (None,
       "测试测试测试4", None, (1, 2, 3)),
      (None,
       "测试测试测试5", None),
      (None,
       "测试测试测试6", None),
      ],
     True
     )
 application.set_menu_callback(lambda button: menu.show(
         get_widget_root_coordinate(button, WIDGET_POS_BOTTOM_LEFT),
         (button.get_allocation().width, 0)))
 
 # Add navigatebar.
 tab_window_items = map(create_tab_window_item, ["Tab1", "Tab2", "Tab3", "Tab4", "Tab5"])
Esempio n. 39
0
    def __init__(self, screenshot):
        self.screenshot = screenshot    # a DeepinScreenshot object
        # sub menu in save node
        menu_item = [
            (None, _("Save automatically"), self.save_sub_menu_clicked, SAVE_OP_AUTO),
            (None, _("Save as"), self.save_sub_menu_clicked, SAVE_OP_AS),
            (None, _("Save to clipboard"), self.save_sub_menu_clicked, SAVE_OP_CLIP),
            (None, _("Save automatically to file and clipboard"), self.save_sub_menu_clicked, SAVE_OP_AUTO_AND_CLIP)]
        self.save_sub_menu = Menu(menu_item, 
            menu_item_select_color=app_theme.get_shadow_color("menu_item_select").get_color_info())
        if self.screenshot.is_subprocess:
            save_sub_menu = self.screenshot.save_to_tmp_file
        else:
            save_sub_menu = self.save_sub_menu
        # right button menu
        menu_item_list = [
            ((app_theme_get_dynamic_pixbuf('image/action_menu/rect_normal.png'),
              app_theme_get_dynamic_pixbuf('image/action_menu/rect_hover.png'),
              app_theme_get_dynamic_pixbuf('image/action_menu/rect_normal.png')),
             _("Draw Rectangle"), self._menu_click, "rect"),
            ((app_theme_get_dynamic_pixbuf('image/action_menu/ellipse_normal.png'),
              app_theme_get_dynamic_pixbuf('image/action_menu/ellipse_hover.png'),
              app_theme_get_dynamic_pixbuf('image/action_menu/ellipse_normal.png')),
             _("Draw Ellipse"), self._menu_click, "ellipse"),
            ((app_theme_get_dynamic_pixbuf('image/action_menu/arrow_normal.png'), 
              app_theme_get_dynamic_pixbuf('image/action_menu/arrow_hover.png'), 
              app_theme_get_dynamic_pixbuf('image/action_menu/arrow_normal.png')), 
             _("Draw Arrow"), self._menu_click, "arrow"),
            ((app_theme_get_dynamic_pixbuf('image/action_menu/line_normal.png'), 
              app_theme_get_dynamic_pixbuf('image/action_menu/line_hover.png'), 
              app_theme_get_dynamic_pixbuf('image/action_menu/line_normal.png')), 
             _("Draw Line"), self._menu_click, "line"),
            ((app_theme_get_dynamic_pixbuf('image/action_menu/text_normal.png'), 
              app_theme_get_dynamic_pixbuf('image/action_menu/text_hover.png'), 
              app_theme_get_dynamic_pixbuf('image/action_menu/text_normal.png')), 
             _("Draw Text"), self._menu_click, "text"),
            None,
            ((app_theme_get_dynamic_pixbuf('image/action_menu/undo_normal.png'), 
              app_theme_get_dynamic_pixbuf('image/action_menu/undo_hover.png'), 
              app_theme_get_dynamic_pixbuf('image/action_menu/undo_normal.png')), 
             _("Undo"), self._menu_click, "undo"),
            ((app_theme_get_dynamic_pixbuf('image/action_menu/save_normal.png'), 
              app_theme_get_dynamic_pixbuf('image/action_menu/save_hover.png'), 
              app_theme_get_dynamic_pixbuf('image/action_menu/save_normal.png')), 
             _("Save"), save_sub_menu),
            ########
            #(None, _("解析二维码"), self.screenshot.parse_barcode),
            ########
            ((app_theme_get_dynamic_pixbuf('image/action_menu/cancel_normal.png'), 
              app_theme_get_dynamic_pixbuf('image/action_menu/cancel_hover.png'), 
              app_theme_get_dynamic_pixbuf('image/action_menu/cancel_normal.png')), 
             _("Cancel"), self._menu_click, "cancel")]

        if not self.screenshot.is_subprocess:
            menu_item_list.append(
                ((app_theme_get_dynamic_pixbuf('image/action_menu/share_normal.png'), 
                  app_theme_get_dynamic_pixbuf('image/action_menu/share_hover.png'), 
                  app_theme_get_dynamic_pixbuf('image/action_menu/share_normal.png')), 
                 _("Share"), self._menu_click, "share"))
        self.window = Menu(menu_item_list, True,
            menu_item_select_color=app_theme.get_shadow_color("menu_item_select").get_color_info())
Esempio n. 40
0
 def __init_menus(self):
     self.config_gui      = None
     self.quit            = None
     self.init_user_guide = None
     self.full_screen     = None
     self.normal_mode     = None
     self.compact_mode    = None # 简洁模式.
     self.next            = None
     self.prev            = None
     self.fseek           = None
     self.bseek           = None
     self.open_file       = None
     self.open_dir        = None
     self.open_url        = None
     self.menu_play_disc = Menu(None)
     ##############################################################
     self.file_menu = Menu([(None, _("Open File"), self.__menu_open_file),
                            (None, _("Open Directory"), self.__menu_open_dir),
                            (None, _("Play Disc"), self.menu_play_disc)
                           ])
     self.play_track            = None
     self.play_default          = None
     self.play_random           = None
     self.play_repeat_track     = None
     self.play_repeat_play_list = None
     
     # 播放顺序.
     self.play_state_menu = Menu([(None, _("Play (track)"),      self.__menu_play_track), # 单曲
                                  (None, _("Default"),           self.__menu_play_default), # 顺序
                                  (None, _("Random"),            self.__menu_play_random), # 随机
                                  (None, _("Repeat (track)"),    self.__menu_play_repeat_track), # 单曲循环
                                  (None, _("Repeat (playlist)"), self.__menu_play_repeat_play_list)] # 列表循环
                                 )                       
     self.play_menu = Menu([(self.full_pixbufs, _("Full Screen"),   self.__menu_full_screen),
                            (self.window_mode_none_pixbus, _("Normal Mode"),   self.__menu_normal_mode),
                            (self.concie_pixbufs, _("Compact Mode"),  self.__menu_compact_mode),
                            (self.pre_pixbufs, _("Previous"),      self.__menu_prev),
                            (self.next_pixbufs, _("Next"),          self.__menu_next),
                            (None),
                            (self.f_seek_5_pixbufs, _("Jump Forward"),  self.__menu_fseek),
                            (self.b_seek_5_pixbufs, _("Jump Backward"), self.__menu_bseek),
                            (self.play_sequence_pixbufs, _("Order"),         self.play_state_menu),
                            ])
                            
     self.normal_ascept     = None
     self._4X3_ascept       = None
     self._16X9_ascept      = None
     self._16X10_ascept     = None
     self._1_85X1_ascept    = None
     self._2_35X1_ascept    = None
     self._50_ascept  = None
     self._100_ascept = None
     self._150_ascept = None
     self._200_ascept = None
     
     self.video_menu = Menu([(None, _("Original"), self.__menu_normal_ascept),
                              (None,    "4:3",     self.__menu_4X3_ascept),
                              (None,   "16:9",     self.__menu_16X9_ascept),
                              (None,  "16:10",     self.__menu_16X10_ascept),
                              (None, "1.85:1",     self.__menu_1_85X1_ascept),
                              (None, "2.35:1",     self.__menu_2_35X1_ascept),
                              (None),
                              (None,  _("50%"),  self.__menu_50_ascept),
                              (None,  _("100%"), self.__menu_100_ascept),
                              (None,  _("150%"), self.__menu_150_ascept),
                              (None,  _("200%"), self.__menu_200_ascept),
                              ])  
     self.stereo_channel = None
     self.left_channel   = None
     self.right_channel  = None
     self.mute_unmute    = None
     self.inc_volume     = None
     self.dec_volume     = None
     ## 截图.
     self.take_scrot     = None
     self.open_scrot_dir = None
     self.set_scrot_dir  = None
     ## 格式转换.
     self.format_conversion = None
     self.task_manager      = None
     # 切换左右声道.
     self.channel_select_menu = Menu([
             (None, _("Stereo"), self.__menu_stereo_channel),
             (None, _("Left"),   self.__menu_left_channel),
             (None, _("Right"),  self.__menu_right_channel)
             ])
     self.audio_menu = Menu([(None, _("Channels"), self.channel_select_menu),
                              (None),
                              (self.add_volume_pixbufs, _("Increase Volume"),  self.__menu_inc_volume),
                              (self.sub_volume_pixbufs, _("Decrease Volume"),  self.__menu_dec_volume),
                              (self.mute_volume_pixbufs, _("Mute/Unmute"),      self.__menu_mute_unmute),
                            ])
     self.sort_menu = Menu([(None, _("Take Screenshot"),           self.__menu_take_scrot),
                            (None, _("Open Screenshot Directory"), self.__menu_open_scrot_dir),
                            (None, _("Set Screenshot Directory"),  self.__menu_set_scrot_dir)
                           ])
     self.format_menu = Menu([(None, _("Format conversion"), self.__menu_format_conversion),
                             (None, _("Task Manager"),       self.__menu_task_manager)
                             ])
     ################################################################
     ## 主题弹出菜单.
     self.title_root_menu = Menu([
                                 (None, _("File"),  self.file_menu),
                                 (None, _("Play"),  self.play_menu),
                                 (None, _("Video"), self.video_menu),
                                 (self.volume_pixbufs, _("Audio"), self.audio_menu),
                                 (self.sort_pixbufs, _("Take Screenshots"),  self.sort_menu),
                                 (None, _("Format conversion"), self.format_menu),
                                 (None, _("View New Features"), self.__menu_init_user_guide),
                                 (self.settings_pixbufs, _("Preferences"),       self.__menu_config_gui),
                                 (None),
                                 (self.quit_pixbufs, _("Quit"), self.__menu_quit)
                                 ],
                                 True)
     ###############################################################
     # 排序.
     self.sort_by_name = None
     self.sort_by_type = None
     self.sort_menu = Menu([(None, _("By Name"), self.__menu_sort_by_name),
                            (None, _("By Type"), self.__menu_sort_by_type)])
     #
     ###############################################################
     self.remove_selected = None #self.__menu_remove_selected
     self.save_playlist = None # 保存播放列表
     self.clear_playlist  = None #self.__menu_clear_playlist
     self.remove_unavailable_files  = None #self.__menu_remove_unavailable_files
     self.open_containing_directory = None #self.__menu_open_containing_directory
     self.add_open_file = None
     self.add_open_dir  = None
     self.add_open_url  = None
     self.screen_format_conversion = None
     # 最近播放.
     self.recent_played_menu = Menu(None)
     ## 播放列表弹出菜单.
     self.play_list_root_menu = Menu([(None, _("Add File"),      self.__menu_add_open_file),
                                      (None, _("Add Directory"), self.__menu_add_open_dir),
                                      (None, _("Add URL"),       self.__menu_add_open_url),
                                      (None),
                                      (None, _("Remove Selected"), self.__menu_remove_selected),
                                      (None, _("Save Playlist"), self.__menu_save_playlist),
                                      (None, _("Clear Playlist"),  self.__menu_clear_playlist),
                                      (None, _("Remove Unavailable Files"), self.__menu_remove_unavailable_files),
                                      (None),
                                      (None, _("Recent Played"), self.recent_played_menu),
                                      (self.play_sequence_pixbufs, _("Order"), self.play_state_menu),
                                      (None, _("Sort"),  self.sort_menu),
                                      (None),
                                      (None, _("Format conversion"), self.__menu_screen_format_conversion),
                                      (None, _("Open Containing Directory"), self.__menu_open_containing_directory),
                                      #(None, _("Properties"), None),
                                      ],
                                      True)
     #########################################################
     # 播放菜单
     self.screen_play_menu = Menu([            
                       (self.pre_pixbufs, _("Previous"),      self.__menu_prev),
                       (self.next_pixbufs, _("Next"),          self.__menu_next),
                       (None),
                       (self.f_seek_5_pixbufs, _("Jump Forward"),  self.__menu_fseek),
                       (self.b_seek_5_pixbufs, _("Jump Backward"), self.__menu_bseek),
                       ])
     ## 音轨选择
     # Menu([(None, "音轨一", None), (... "音轨二", None)...])
     self.switch_audio_menu = Menu(None) 
     self.audio_lang_menu = (None, _("Dubbing selection"), self.switch_audio_menu)
     # 声音.
     self.channel_select = Menu([
             (None, _("Audio channels"), self.channel_select_menu),
             self.audio_lang_menu,
             ])
     ### DVD内置菜单.
     self.return_to_root  = None
     self.return_to_title = None
     self.dvd_select = None
     self.dvd_right = None
     self.dvd_left  = None
     self.dvd_down  = None
     self.dvd_up    = None
     self.dvd_built_in_menu = Menu([
                 (None, _("Move Up"),         self.__menu_dvd_up), 
                 (None, _("Move Down"),       self.__menu_dvd_down),
                 (None, _("Move Left"),       self.__menu_dvd_left),
                 (None, _("Move Right"),      self.__menu_dvd_right), 
                 (None, _("Select"),          self.__menu_dvd_select),
                 (None, _("Return to Title"), self.__menu_return_to_title),
                 (None, _("Return to Root"),  self.__menu_return_to_root),
                 ])
     ## DVD控制菜单. 有DVD的时候才显示出来.
     self.jump_to = Menu(None)
     self.dvd_prev_title = None
     self.dvd_next_title = None
     self.dvd_navigation_menu = Menu([(None, _("Previous Title"), self.__menu_dvd_prev_title), 
                                      (None, _("Next title"),     self.__menu_dvd_next_title), 
                                      (None, _("Jump to"),        self.jump_to),
                                      (None, _("DVD Menu"),       self.dvd_built_in_menu),
                                      ]) 
     ## 字幕选择:
     self.subtitles_select = Menu(None)
     self.load_subtitles = None # 手动载入字幕.
     self.subtitles_child_menu = Menu([
             (None, _("Load subtitles"), self.__menu_load_subtitles), # 手动载入字幕.
             (None, _("Select a subtitle"), self.subtitles_select), # 字幕选择
             ])
     # 属性窗口.
     self.properties = None
     # 屏幕弹出菜单.
     self.screen_right_root_menu = Menu([
             (None, _("Open File"),      self.__menu_open_file),
             (None, _("Open Directory"), self.__menu_open_dir),
             (None, _("Open URL"),       self.__menu_open_url),
             (None),
             (self.full_pixbufs, _("Full Screen On/Off"), self.__menu_full_screen),
             (self.window_mode_none_pixbus, _("Normal Mode"),        self.__menu_normal_mode),
             (self.concie_pixbufs, _("Compact Mode"),       self.__menu_compact_mode),
             (self.play_sequence_pixbufs, _("Order"), self.play_state_menu),
             (None, _("Play"),  self.screen_play_menu),
             (None, _("Video"), self.video_menu),
             (self.volume_pixbufs, _("Audio"), self.channel_select),
             #(self.subtitle_pixbus, _("Subtitles"),      self.subtitles_select),
             (self.subtitle_pixbus, _("Subtitles"), self.subtitles_child_menu),
             (None, _("DVD Navigation"), self.dvd_navigation_menu),
             (self.settings_pixbufs, _("Preferences"),    self.__menu_config_gui),
             (None),
             (None, _("Properties"), self.__menu_properties),
             ], True)
Esempio n. 41
0
class PlayMenus(object):
    def __init__(self):
        self.init_system_pixbuf()
        self.__init_menus()
        
    def init_system_pixbuf(self):    
        # aspect state pixbuf.
        self.video_aspect_pixbuf        = app_theme.get_pixbuf("screen/check_normal.png") 
        self.video_aspect_select_pixbuf = app_theme.get_pixbuf("screen/check_hover.png")
        self.video_aspect_none_pixbuf   = app_theme.get_pixbuf("screen/check_none.png")
        self.select_pixbuf = (self.video_aspect_pixbuf, 
                              self.video_aspect_select_pixbuf,
                              self.video_aspect_none_pixbuf)
        # full .
        self.menu_full_normal_pixbuf = app_theme.get_pixbuf("screen/menu_full_normal.png") 
        self.menu_full_hover_pixbuf = app_theme.get_pixbuf("screen/menu_full_hover.png")
        self.menu_full_none_pixbuf = app_theme.get_pixbuf("screen/menu_full_none.png")
        self.full_pixbufs = (self.menu_full_normal_pixbuf,
                            self.menu_full_hover_pixbuf,
                            self.menu_full_normal_pixbuf)
        # window mode. 正常模式.
        self.menu_window_mode_normal_pixbuf = app_theme.get_pixbuf("screen/menu_window_mode_normal.png")
        self.menu_window_mode_hover_pixbuf = app_theme.get_pixbuf("screen/menu_window_mode_hover.png")
        self.menu_window_mode_none_pixbuf = app_theme.get_pixbuf("screen/menu_window_mode_none.png")
        self.window_mode_none_pixbus = (self.menu_window_mode_normal_pixbuf,
                                        self.menu_window_mode_hover_pixbuf,
                                        self.menu_window_mode_none_pixbuf)
        # concie pixbuf. 简洁模式.
        self.menu_concie_normal_pixbuf = app_theme.get_pixbuf("screen/menu_concise_normal.png")
        self.menu_concie_hover_pixbuf = app_theme.get_pixbuf("screen/menu_concise_hover.png")
        self.menu_concie_none_pixbuf = app_theme.get_pixbuf("screen/menu_concise_none.png")
        self.concie_pixbufs = (self.menu_concie_normal_pixbuf,
                               self.menu_concie_hover_pixbuf,
                               self.menu_concie_normal_pixbuf)
        # pre. 上一曲.
        self.menu_pre_normal_pixbuf = app_theme.get_pixbuf("screen/menu_pre_normal.png")
        self.menu_pre_hover_pixbuf = app_theme.get_pixbuf("screen/menu_pre_hover.png")
        self.menu_pre_none_pixbuf = app_theme.get_pixbuf("screen/menu_pre_none.png")
        self.pre_pixbufs = (self.menu_pre_normal_pixbuf,
                            self.menu_pre_hover_pixbuf,
                            self.menu_pre_none_pixbuf)
        # next. 下一曲.
        self.menu_next_normal_pixbuf = app_theme.get_pixbuf("screen/menu_next_normal.png")
        self.menu_next_hover_pixbuf = app_theme.get_pixbuf("screen/menu_next_hover.png")        
        self.menu_next_none_pixbuf = app_theme.get_pixbuf("screen/menu_next_none.png")        
        self.next_pixbufs = (self.menu_next_normal_pixbuf,
                             self.menu_next_hover_pixbuf,
                             self.menu_next_none_pixbuf)
        # f seek 5.
        self.menu_f_seek_5_normal_pixbuf = app_theme.get_pixbuf("screen/menu_f_seek_5_normal.png")
        self.menu_f_seek_5_hover_pixbuf = app_theme.get_pixbuf("screen/menu_f_seek_5_hover.png")
        self.menu_f_seek_5_none_pixbuf = app_theme.get_pixbuf("screen/menu_f_seek_5_none.png")
        self.f_seek_5_pixbufs = (self.menu_f_seek_5_normal_pixbuf,
                                 self.menu_f_seek_5_hover_pixbuf,
                                 self.menu_f_seek_5_none_pixbuf)
        # b seek 5.
        self.menu_b_seek_5_normal_pixbuf = app_theme.get_pixbuf("screen/menu_b_seek_5_normal.png")
        self.menu_b_seek_5_hover_pixbuf = app_theme.get_pixbuf("screen/menu_b_seek_5_hover.png")
        self.menu_b_seek_5_none_pixbuf = app_theme.get_pixbuf("screen/menu_b_seek_5_none.png")
        self.b_seek_5_pixbufs = (self.menu_b_seek_5_normal_pixbuf,
                                 self.menu_b_seek_5_hover_pixbuf,
                                 self.menu_b_seek_5_none_pixbuf)
        # play sequence. 播放顺序.
        self.menu_play_sequence_normal_pixbuf = app_theme.get_pixbuf("screen/menu_play_sequence_normal.png")
        self.menu_play_sequence_hover_pixbuf = app_theme.get_pixbuf("screen/menu_play_sequence_hover.png")
        self.menu_play_sequence_none_pixbuf = app_theme.get_pixbuf("screen/menu_play_sequence_none.png")
        self.play_sequence_pixbufs = (self.menu_play_sequence_normal_pixbuf,
                                      self.menu_play_sequence_hover_pixbuf,
                                      self.menu_play_sequence_none_pixbuf)
        # volume.
        self.menu_volume_normal_pixbuf = app_theme.get_pixbuf("screen/menu_volume_normal.png")
        self.menu_volume_hover_pixbuf = app_theme.get_pixbuf("screen/menu_volume_hover.png")
        self.menu_volume_none_pixbuf = app_theme.get_pixbuf("screen/menu_volume_none.png")
        self.volume_pixbufs = (self.menu_volume_normal_pixbuf,
                               self.menu_volume_hover_pixbuf,
                               self.menu_volume_none_pixbuf)
        # mute/add/sub volume pixbuf. 声音的静音,添加/减少 音量.
        self.mute_normal_pixbuf = app_theme.get_pixbuf("screen/menu_volume_menu_normal.png")
        self.mute_hover_pixbuf = app_theme.get_pixbuf("screen/menu_volume_menu_hover.png")
        self.mute_none_pixbuf = app_theme.get_pixbuf("screen/menu_volume_menu_none.png")                
        self.mute_volume_pixbufs = (self.mute_normal_pixbuf, 
                                    self.mute_hover_pixbuf, 
                                    self.mute_none_pixbuf)
        # add volume.
        self.add_volume_normal_pixbuf = app_theme.get_pixbuf("screen/menu_volume_add_normal.png")
        self.add_volume_hover_pixbuf = app_theme.get_pixbuf("screen/menu_volume_add_hover.png")
        self.add_volume_none_pixbuf = app_theme.get_pixbuf("screen/menu_volume_add_none.png")
        self.add_volume_pixbufs = (self.add_volume_normal_pixbuf, 
                                   self.add_volume_hover_pixbuf, 
                                   self.add_volume_none_pixbuf)
        # sub volume.
        self.sub_volume_normal_pixbuf = app_theme.get_pixbuf("screen/menu_volume_sub_normal.png")
        self.sub_volume_hover_pixbuf = app_theme.get_pixbuf("screen/menu_volume_sub_hover.png")
        self.sub_volume_none_pixbuf = app_theme.get_pixbuf("screen/menu_volume_sub_none.png")
        self.sub_volume_pixbufs = (self.sub_volume_normal_pixbuf, 
                                   self.sub_volume_hover_pixbuf, 
                                   self.sub_volume_none_pixbuf)        
        # quit. 退出.
        self.menu_quit_normal_pixbuf = app_theme.get_pixbuf("screen/menu_quit_normal.png")
        self.menu_quit_hover_pixbuf = app_theme.get_pixbuf("screen/menu_quit_hover.png")
        self.menu_quit_none_pixbuf = app_theme.get_pixbuf("screen/menu_quit_none.png")
        self.quit_pixbufs = (self.menu_quit_normal_pixbuf,
                             self.menu_quit_hover_pixbuf,
                             self.menu_quit_none_pixbuf)
        # settin. 配置界面.
        self.menu_setting_normal_pixbuf = app_theme.get_pixbuf("screen/menu_setting_normal.png")
        self.menu_setting_hover_pixbuf = app_theme.get_pixbuf("screen/menu_setting_hover.png")
        self.menu_setting_none_pixbuf = app_theme.get_pixbuf("screen/menu_setting_none.png")
        self.settings_pixbufs = (self.menu_setting_normal_pixbuf,
                                 self.menu_setting_hover_pixbuf,
                                 self.menu_setting_none_pixbuf)
        # subtitle. 字幕.
        self.menu_subtitle_normal_pixbuf = app_theme.get_pixbuf("screen/menu_subtitle_normal.png")
        self.menu_subtitle_hover_pixbuf = app_theme.get_pixbuf("screen/menu_subtitle_hover.png")
        self.menu_subtitle_none_pixbuf = app_theme.get_pixbuf("screen/menu_subtitle_none.png")        
        self.subtitle_pixbus = (self.menu_subtitle_normal_pixbuf,
                                self.menu_subtitle_hover_pixbuf,
                                self.menu_subtitle_none_pixbuf)
        # sort 截图.
        self.menu_sort_normal_pixbuf = app_theme.get_pixbuf("screen/menu_sort_normal.png")
        self.menu_sort_hover_pixbuf  = app_theme.get_pixbuf("screen/menu_sort_hover.png")
        self.menu_sort_none_pixbuf   = app_theme.get_pixbuf("screen/menu_sort_none.png")
        self.sort_pixbufs = (self.menu_sort_normal_pixbuf,
                             self.menu_sort_hover_pixbuf,
                             self.menu_sort_none_pixbuf)

    def __init_menus(self):
        self.config_gui      = None
        self.quit            = None
        self.init_user_guide = None
        self.full_screen     = None
        self.normal_mode     = None
        self.compact_mode    = None # 简洁模式.
        self.next            = None
        self.prev            = None
        self.fseek           = None
        self.bseek           = None
        self.open_file       = None
        self.open_dir        = None
        self.open_url        = None
        self.menu_play_disc = Menu(None)
        ##############################################################
        self.file_menu = Menu([(None, _("Open File"), self.__menu_open_file),
                               (None, _("Open Directory"), self.__menu_open_dir),
                               (None, _("Play Disc"), self.menu_play_disc)
                              ])
        self.play_track            = None
        self.play_default          = None
        self.play_random           = None
        self.play_repeat_track     = None
        self.play_repeat_play_list = None
        
        # 播放顺序.
        self.play_state_menu = Menu([(None, _("Play (track)"),      self.__menu_play_track), # 单曲
                                     (None, _("Default"),           self.__menu_play_default), # 顺序
                                     (None, _("Random"),            self.__menu_play_random), # 随机
                                     (None, _("Repeat (track)"),    self.__menu_play_repeat_track), # 单曲循环
                                     (None, _("Repeat (playlist)"), self.__menu_play_repeat_play_list)] # 列表循环
                                    )                       
        self.play_menu = Menu([(self.full_pixbufs, _("Full Screen"),   self.__menu_full_screen),
                               (self.window_mode_none_pixbus, _("Normal Mode"),   self.__menu_normal_mode),
                               (self.concie_pixbufs, _("Compact Mode"),  self.__menu_compact_mode),
                               (self.pre_pixbufs, _("Previous"),      self.__menu_prev),
                               (self.next_pixbufs, _("Next"),          self.__menu_next),
                               (None),
                               (self.f_seek_5_pixbufs, _("Jump Forward"),  self.__menu_fseek),
                               (self.b_seek_5_pixbufs, _("Jump Backward"), self.__menu_bseek),
                               (self.play_sequence_pixbufs, _("Order"),         self.play_state_menu),
                               ])
                               
        self.normal_ascept     = None
        self._4X3_ascept       = None
        self._16X9_ascept      = None
        self._16X10_ascept     = None
        self._1_85X1_ascept    = None
        self._2_35X1_ascept    = None
        self._50_ascept  = None
        self._100_ascept = None
        self._150_ascept = None
        self._200_ascept = None
        
        self.video_menu = Menu([(None, _("Original"), self.__menu_normal_ascept),
                                 (None,    "4:3",     self.__menu_4X3_ascept),
                                 (None,   "16:9",     self.__menu_16X9_ascept),
                                 (None,  "16:10",     self.__menu_16X10_ascept),
                                 (None, "1.85:1",     self.__menu_1_85X1_ascept),
                                 (None, "2.35:1",     self.__menu_2_35X1_ascept),
                                 (None),
                                 (None,  _("50%"),  self.__menu_50_ascept),
                                 (None,  _("100%"), self.__menu_100_ascept),
                                 (None,  _("150%"), self.__menu_150_ascept),
                                 (None,  _("200%"), self.__menu_200_ascept),
                                 ])  
        self.stereo_channel = None
        self.left_channel   = None
        self.right_channel  = None
        self.mute_unmute    = None
        self.inc_volume     = None
        self.dec_volume     = None
        ## 截图.
        self.take_scrot     = None
        self.open_scrot_dir = None
        self.set_scrot_dir  = None
        ## 格式转换.
        self.format_conversion = None
        self.task_manager      = None
        # 切换左右声道.
        self.channel_select_menu = Menu([
                (None, _("Stereo"), self.__menu_stereo_channel),
                (None, _("Left"),   self.__menu_left_channel),
                (None, _("Right"),  self.__menu_right_channel)
                ])
        self.audio_menu = Menu([(None, _("Channels"), self.channel_select_menu),
                                 (None),
                                 (self.add_volume_pixbufs, _("Increase Volume"),  self.__menu_inc_volume),
                                 (self.sub_volume_pixbufs, _("Decrease Volume"),  self.__menu_dec_volume),
                                 (self.mute_volume_pixbufs, _("Mute/Unmute"),      self.__menu_mute_unmute),
                               ])
        self.sort_menu = Menu([(None, _("Take Screenshot"),           self.__menu_take_scrot),
                               (None, _("Open Screenshot Directory"), self.__menu_open_scrot_dir),
                               (None, _("Set Screenshot Directory"),  self.__menu_set_scrot_dir)
                              ])
        self.format_menu = Menu([(None, _("Format conversion"), self.__menu_format_conversion),
                                (None, _("Task Manager"),       self.__menu_task_manager)
                                ])
        ################################################################
        ## 主题弹出菜单.
        self.title_root_menu = Menu([
                                    (None, _("File"),  self.file_menu),
                                    (None, _("Play"),  self.play_menu),
                                    (None, _("Video"), self.video_menu),
                                    (self.volume_pixbufs, _("Audio"), self.audio_menu),
                                    (self.sort_pixbufs, _("Take Screenshots"),  self.sort_menu),
                                    (None, _("Format conversion"), self.format_menu),
                                    (None, _("View New Features"), self.__menu_init_user_guide),
                                    (self.settings_pixbufs, _("Preferences"),       self.__menu_config_gui),
                                    (None),
                                    (self.quit_pixbufs, _("Quit"), self.__menu_quit)
                                    ],
                                    True)
        ###############################################################
        # 排序.
        self.sort_by_name = None
        self.sort_by_type = None
        self.sort_menu = Menu([(None, _("By Name"), self.__menu_sort_by_name),
                               (None, _("By Type"), self.__menu_sort_by_type)])
        #
        ###############################################################
        self.remove_selected = None #self.__menu_remove_selected
        self.save_playlist = None # 保存播放列表
        self.clear_playlist  = None #self.__menu_clear_playlist
        self.remove_unavailable_files  = None #self.__menu_remove_unavailable_files
        self.open_containing_directory = None #self.__menu_open_containing_directory
        self.add_open_file = None
        self.add_open_dir  = None
        self.add_open_url  = None
        self.screen_format_conversion = None
        # 最近播放.
        self.recent_played_menu = Menu(None)
        ## 播放列表弹出菜单.
        self.play_list_root_menu = Menu([(None, _("Add File"),      self.__menu_add_open_file),
                                         (None, _("Add Directory"), self.__menu_add_open_dir),
                                         (None, _("Add URL"),       self.__menu_add_open_url),
                                         (None),
                                         (None, _("Remove Selected"), self.__menu_remove_selected),
                                         (None, _("Save Playlist"), self.__menu_save_playlist),
                                         (None, _("Clear Playlist"),  self.__menu_clear_playlist),
                                         (None, _("Remove Unavailable Files"), self.__menu_remove_unavailable_files),
                                         (None),
                                         (None, _("Recent Played"), self.recent_played_menu),
                                         (self.play_sequence_pixbufs, _("Order"), self.play_state_menu),
                                         (None, _("Sort"),  self.sort_menu),
                                         (None),
                                         (None, _("Format conversion"), self.__menu_screen_format_conversion),
                                         (None, _("Open Containing Directory"), self.__menu_open_containing_directory),
                                         #(None, _("Properties"), None),
                                         ],
                                         True)
        #########################################################
        # 播放菜单
        self.screen_play_menu = Menu([            
                          (self.pre_pixbufs, _("Previous"),      self.__menu_prev),
                          (self.next_pixbufs, _("Next"),          self.__menu_next),
                          (None),
                          (self.f_seek_5_pixbufs, _("Jump Forward"),  self.__menu_fseek),
                          (self.b_seek_5_pixbufs, _("Jump Backward"), self.__menu_bseek),
                          ])
        ## 音轨选择
        # Menu([(None, "音轨一", None), (... "音轨二", None)...])
        self.switch_audio_menu = Menu(None) 
        self.audio_lang_menu = (None, _("Dubbing selection"), self.switch_audio_menu)
        # 声音.
        self.channel_select = Menu([
                (None, _("Audio channels"), self.channel_select_menu),
                self.audio_lang_menu,
                ])
        ### DVD内置菜单.
        self.return_to_root  = None
        self.return_to_title = None
        self.dvd_select = None
        self.dvd_right = None
        self.dvd_left  = None
        self.dvd_down  = None
        self.dvd_up    = None
        self.dvd_built_in_menu = Menu([
                    (None, _("Move Up"),         self.__menu_dvd_up), 
                    (None, _("Move Down"),       self.__menu_dvd_down),
                    (None, _("Move Left"),       self.__menu_dvd_left),
                    (None, _("Move Right"),      self.__menu_dvd_right), 
                    (None, _("Select"),          self.__menu_dvd_select),
                    (None, _("Return to Title"), self.__menu_return_to_title),
                    (None, _("Return to Root"),  self.__menu_return_to_root),
                    ])
        ## DVD控制菜单. 有DVD的时候才显示出来.
        self.jump_to = Menu(None)
        self.dvd_prev_title = None
        self.dvd_next_title = None
        self.dvd_navigation_menu = Menu([(None, _("Previous Title"), self.__menu_dvd_prev_title), 
                                         (None, _("Next title"),     self.__menu_dvd_next_title), 
                                         (None, _("Jump to"),        self.jump_to),
                                         (None, _("DVD Menu"),       self.dvd_built_in_menu),
                                         ]) 
        ## 字幕选择:
        self.subtitles_select = Menu(None)
        self.load_subtitles = None # 手动载入字幕.
        self.subtitles_child_menu = Menu([
                (None, _("Load subtitles"), self.__menu_load_subtitles), # 手动载入字幕.
                (None, _("Select a subtitle"), self.subtitles_select), # 字幕选择
                ])
        # 属性窗口.
        self.properties = None
        # 屏幕弹出菜单.
        self.screen_right_root_menu = Menu([
                (None, _("Open File"),      self.__menu_open_file),
                (None, _("Open Directory"), self.__menu_open_dir),
                (None, _("Open URL"),       self.__menu_open_url),
                (None),
                (self.full_pixbufs, _("Full Screen On/Off"), self.__menu_full_screen),
                (self.window_mode_none_pixbus, _("Normal Mode"),        self.__menu_normal_mode),
                (self.concie_pixbufs, _("Compact Mode"),       self.__menu_compact_mode),
                (self.play_sequence_pixbufs, _("Order"), self.play_state_menu),
                (None, _("Play"),  self.screen_play_menu),
                (None, _("Video"), self.video_menu),
                (self.volume_pixbufs, _("Audio"), self.channel_select),
                #(self.subtitle_pixbus, _("Subtitles"),      self.subtitles_select),
                (self.subtitle_pixbus, _("Subtitles"), self.subtitles_child_menu),
                (None, _("DVD Navigation"), self.dvd_navigation_menu),
                (self.settings_pixbufs, _("Preferences"),    self.__menu_config_gui),
                (None),
                (None, _("Properties"), self.__menu_properties),
                ], True)
                                     
    def show_theme_menu(self, button): 
        # 显示主题上菜单.
        self.title_root_menu.show(
             get_widget_root_coordinate(button, WIDGET_POS_BOTTOM_LEFT),
             (button.get_allocation().width, 0)) 
    
    def show_play_list_menu(self, event):
        # 显示播放列表上的菜单.
        self.play_list_root_menu.show((int(event.x_root), int(event.y_root)), (0, 0))
         
    def show_screen_menu(self, event):
        # 显示屏幕右键菜单.
        self.screen_right_root_menu.show(
                        (int(event.x_root),
                        int(event.y_root)),
                        (0, 0))
                 
    def __menu_init_user_guide(self):
        if self.init_user_guide:
            self.init_user_guide()
                      
    def __menu_config_gui(self):
        if self.config_gui:    
            self.config_gui()
    
    def __menu_quit(self):
        if self.quit:
            self.quit()
    
    def __menu_full_screen(self):
        if self.full_screen:
            self.full_screen()
           
    def __menu_normal_mode(self):
        if self.normal_mode:
            self.normal_mode()
    
    def __menu_compact_mode(self):
        if self.compact_mode:
            self.compact_mode()
     
    def __menu_next(self):
        if self.next:
            self.next()
    
    def __menu_prev(self):
        if self.prev:
            self.prev()
    
    def __menu_fseek(self):
        if self.fseek:
            self.fseek()
     
    def __menu_bseek(self):
        if self.bseek:
            self.bseek()
            
    def __menu_inc_volume(self):
        if self.inc_volume:
            self.inc_volume()
                
    def __menu_dec_volume(self):
        if self.dec_volume:
            self.dec_volume()
                  
    def __menu_stereo_channel(self):
        if self.stereo_channel:
            self.stereo_channel()
                
    def __menu_left_channel(self):
        if self.left_channel:
            self.left_channel()
            
    def __menu_right_channel(self):
        if self.right_channel:
            self.right_channel()
            
    def __menu_mute_unmute(self):
        if self.mute_unmute:
            self.mute_unmute()
                                             
    def __menu_normal_ascept(self):
        if self.normal_ascept:
            self.normal_ascept()
    
    def __menu_4X3_ascept(self):
        if self._4X3_ascept:
            self._4X3_ascept()
    
    def __menu_16X9_ascept(self):
        if self._16X9_ascept:
            self._16X9_ascept()       
                
    def __menu_16X10_ascept(self):
        if self._16X10_ascept:
            self._16X10_ascept()    
            
    def __menu_1_85X1_ascept(self):
        if self._1_85X1_ascept:  
            self._1_85X1_ascept()     
            
    def __menu_2_35X1_ascept(self):
        if self._2_35X1_ascept:
            self._2_35X1_ascept()

    def __menu_50_ascept(self):
        if self._50_ascept:
            self._50_ascept()

    def __menu_100_ascept(self):
        if self._100_ascept:
            self._100_ascept()

    def __menu_150_ascept(self):
        if self._150_ascept:
            self._150_ascept()

    def __menu_200_ascept(self):
        if self._200_ascept:
            self._200_ascept()
    
    def __menu_play_track(self):
        if self.play_track:
            self.play_track()
            
    def __menu_play_default(self):
        if self.play_default:
            self.play_default()
            
    def __menu_play_random(self):
        if self.play_random:
            self.play_random()
            
    def __menu_play_repeat_track(self):
        if self.play_repeat_track:
            self.play_repeat_track()
            
    def __menu_play_repeat_play_list(self):
        if self.play_repeat_play_list:
            self.play_repeat_play_list()

    def __menu_remove_selected(self):
        if self.remove_selected:
            self.remove_selected()
    
    def __menu_clear_playlist(self):
        if self.clear_playlist:
            self.clear_playlist()

    def __menu_remove_unavailable_files(self): 
        # 删除无效文件.
        if self.remove_unavailable_files:
            self.remove_unavailable_files()
    
    def __menu_open_containing_directory(self):
        # 开打文件的所在路径.
        if self.open_containing_directory:
            self.open_containing_directory()
    
    def __menu_open_file(self):
        if self.open_file:
            self.open_file()
            
    def __menu_open_dir(self):
        print "__menu_open_dir..."
        if self.open_dir:
            print "run..run"
            self.open_dir()
    
    def __menu_open_url(self):
        if self.open_url:
            self.open_url(True)
            
    def __menu_add_open_url(self):
        if self.add_open_url:
            self.add_open_url(False, False)
            
    def __menu_add_open_file(self):
        if self.add_open_file:
            self.add_open_file()
    
    def __menu_add_open_dir(self):
        if self.add_open_dir:
            self.add_open_dir()
            
    def __menu_format_conversion(self):
        if self.format_conversion:
            self.format_conversion()
    
    def __menu_task_manager(self):
        if self.task_manager:
            self.task_manager()
            
    def __menu_screen_format_conversion(self):
        if self.screen_format_conversion:
            self.screen_format_conversion()

    def __menu_properties(self): 
        if self.properties:
            self.properties()

    # 排序.
    def __menu_sort_by_name(self):
        if self.sort_by_name:
            self.sort_by_name()

    def __menu_sort_by_type(self):
        if self.sort_by_type:
            self.sort_by_type()
            
    # dvd 菜单.
    def __menu_return_to_root(self):
        # 主菜单.
        if self.return_to_root:
            self.return_to_root()

    def __menu_return_to_title(self):
        # 标题菜单.
        if self.return_to_title:
            self.return_to_title()

    def __menu_dvd_select(self):
        # 选择
        if self.dvd_select:
            self.dvd_select()

    def __menu_dvd_right(self):
        if self.dvd_right:
            self.dvd_right()

    def __menu_dvd_left(self):
        if self.dvd_left:
            self.dvd_left()

    def __menu_dvd_down(self):
        if self.dvd_down:
            self.dvd_down()

    def __menu_dvd_up(self):
        if self.dvd_up:
            self.dvd_up()

    def __menu_dvd_prev_title(self):
        # dvd 上一标题.
        if self.dvd_prev_title:
            self.dvd_prev_title()

    def __menu_dvd_next_title(self):
        # dvd 下一标题.
        if self.dvd_next_title:
            self.dvd_next_title()
    
    # 截图设置.
    def __menu_take_scrot(self):
        if self.take_scrot:
            self.take_scrot()

    def __menu_open_scrot_dir(self):
        if self.open_scrot_dir:
            self.open_scrot_dir()

    def __menu_set_scrot_dir(self):
        if self.set_scrot_dir:
            self.set_scrot_dir()

    # 保存播放列表.
    def __menu_save_playlist(self):        
        if self.save_playlist:
            self.save_playlist()
    
    # 手动载入字幕.
    def __menu_load_subtitles(self):
        if self.load_subtitles:
            self.load_subtitles()
Esempio n. 42
0
class RightMenu():
    ''' Right Button Menu'''
    def __init__(self, screenshot):
        self.screenshot = screenshot    # a DeepinScreenshot object
        # sub menu in save node
        menu_item = [
            (None, _("save automatically"), self.save_sub_menu_clicked, SAVE_OP_AUTO),
            (None, _("save as"), self.save_sub_menu_clicked, SAVE_OP_AS),
            (None, _("save to clipboard"), self.save_sub_menu_clicked, SAVE_OP_CLIP),
            (None, _("save automatically to file and clipboard"), self.save_sub_menu_clicked, SAVE_OP_AUTO_AND_CLIP)]
        self.save_sub_menu = save_sub_menu = Menu(menu_item, 
            menu_item_select_color=app_theme.get_shadow_color("menu_item_select").get_color_info())
        # right button menu
        self.window = Menu([
            ((app_theme_get_dynamic_pixbuf('image/action_menu/rect_normal.png'),
              app_theme_get_dynamic_pixbuf('image/action_menu/rect_hover.png'),
              app_theme_get_dynamic_pixbuf('image/action_menu/rect_normal.png')),
              _("draw rectangle"), self._menu_click, "rect"),
            ((app_theme_get_dynamic_pixbuf('image/action_menu/ellipse_normal.png'),
              app_theme_get_dynamic_pixbuf('image/action_menu/ellipse_hover.png'),
              app_theme_get_dynamic_pixbuf('image/action_menu/ellipse_normal.png')),
              _("draw ellipse"), self._menu_click, "ellipse"),
            ((app_theme_get_dynamic_pixbuf('image/action_menu/arrow_normal.png'), 
              app_theme_get_dynamic_pixbuf('image/action_menu/arrow_hover.png'), 
              app_theme_get_dynamic_pixbuf('image/action_menu/arrow_normal.png')), 
              _("draw arrow"), self._menu_click, "arrow"),
            ((app_theme_get_dynamic_pixbuf('image/action_menu/line_normal.png'), 
              app_theme_get_dynamic_pixbuf('image/action_menu/line_hover.png'), 
              app_theme_get_dynamic_pixbuf('image/action_menu/line_normal.png')), 
              _("draw line"), self._menu_click, "line"),
            ((app_theme_get_dynamic_pixbuf('image/action_menu/text_normal.png'), 
              app_theme_get_dynamic_pixbuf('image/action_menu/text_hover.png'), 
              app_theme_get_dynamic_pixbuf('image/action_menu/text_normal.png')), 
              _("draw Text"), self._menu_click, "text"),
            None,
            ((app_theme_get_dynamic_pixbuf('image/action_menu/undo_normal.png'), 
              app_theme_get_dynamic_pixbuf('image/action_menu/undo_hover.png'), 
              app_theme_get_dynamic_pixbuf('image/action_menu/undo_normal.png')), 
              _("undo"), self._menu_click, "undo"),
            ((app_theme_get_dynamic_pixbuf('image/action_menu/save_normal.png'), 
              app_theme_get_dynamic_pixbuf('image/action_menu/save_hover.png'), 
              app_theme_get_dynamic_pixbuf('image/action_menu/save_normal.png')), 
              _("save"), save_sub_menu),
            ((app_theme_get_dynamic_pixbuf('image/action_menu/cancel_normal.png'), 
              app_theme_get_dynamic_pixbuf('image/action_menu/cancel_hover.png'), 
              app_theme_get_dynamic_pixbuf('image/action_menu/cancel_normal.png')), 
              _("cancel"), self._menu_click, "cancel"),
            ((app_theme_get_dynamic_pixbuf('image/action_menu/share_normal.png'), 
              app_theme_get_dynamic_pixbuf('image/action_menu/share_hover.png'), 
              app_theme_get_dynamic_pixbuf('image/action_menu/share_normal.png')), 
              _("share"), self._menu_click, "share"),
            ], True,
            menu_item_select_color=app_theme.get_shadow_color("menu_item_select").get_color_info())
        
    def _menu_click(self, name):
        '''menu clicked callback'''
        buttons = self.screenshot.toolbar.toolbox.get_children()
        for each in buttons:
            if each.name == name:
                each.pressed()
                each.released()
                each.clicked()
                return
        # save current input text
        if self.screenshot.show_text_window_flag:
            self.screenshot.window.save_text_window()
        self.screenshot.toolbar.set_button_active(name, True)

    def save_sub_menu_clicked(self, save_op_index):
        '''save sub menu clicked callback'''
        self.screenshot.toolbar._list_menu_click(save_op_index)

    def show(self, coord=(0, 0)):
        ''' show menu '''
        # set current operate icon
        items = self.save_sub_menu.get_menu_items()
        i = 0
        for menu_item in items:
            item = list(menu_item.item)
            if i == self.screenshot.save_op_index:
                item[0] = (
                    app_theme.get_pixbuf("action/selected.png"),
                    app_theme.get_pixbuf("action/selected_hover.png"),
                    app_theme.get_pixbuf("action/selected.png"))
            else:
                item[0] = None
            i += 1
            menu_item.item = tuple(item)
        self.window.show(coord)
Esempio n. 43
0
class BaseTrayIcon(object):
    """Trayicon base, needs to be derived from."""

    def __init__(self, instance):
        self.update_icon()
        self.connect_events()
        self.instance = instance
        self.menu = None

    def update_icon(self):
        self.set_from_pixbuf(
            gtk.gdk.pixbuf_new_from_file(os.path.join(get_parent_dir(__file__, 3), "image", "logo1.png"))
        )

    def get_volume_menu(self):
        menu_items = [
            (None, _("Volume Up"), Player.increase_volume),
            (None, _("Volume Down"), Player.decrease_volume),
            (None, _("Mute"), Player.mute_volume),
        ]
        return Menu(menu_items)

    def update_menu(self):
        menu_items = []
        if Player.is_paused():
            pixbuf_group = self.get_pixbuf_group("play")
            status_label = _("Play")
        else:
            pixbuf_group = self.get_pixbuf_group("pause")
            status_label = _("Pause")
        menu_items.append((pixbuf_group, status_label, Player.playpause))
        menu_items.append((self.get_pixbuf_group("previous"), _("Previous"), Player.previous))
        menu_items.append((self.get_pixbuf_group("next"), _("Next"), Player.next))
        menu_items.append(None)
        menu_items.append((self.get_pixbuf_group("volume"), _("Volume"), self.get_volume_menu()))
        menu_items.append(None)

        if config.getboolean("lyrics", "status"):
            menu_items.append((None, _("Close Lyrics"), lambda: Dispatcher.close_lyrics()))
            menu_items.append((None, _("Search Lyrics"), lambda: Dispatcher.emit("search-lyrics")))
        else:
            menu_items.append((None, _("Show Lyrics"), lambda: Dispatcher.show_lyrics()))

        if config.getboolean("lyrics", "locked"):
            menu_items.append((self.get_pixbuf_group("unlock"), _("Unlock Lyrics"), lambda: Dispatcher.unlock_lyrics()))
        else:
            menu_items.append((self.get_pixbuf_group("lock"), _("Lock Lyrics"), lambda: Dispatcher.lock_lyrics()))

        menu_items.append(None)
        menu_items.append((self.get_pixbuf_group("setting"), _("Preferences"), lambda: Dispatcher.show_setting()))
        menu_items.append((self.get_pixbuf_group("close"), _("Quit"), lambda: Dispatcher.quit()))
        if self.menu is not None:
            del self.menu
        self.menu = Menu(menu_items, True)

    def get_pixbuf_group(self, name):
        return (
            app_theme.get_pixbuf("tray/%s_normal.png" % name),
            app_theme.get_pixbuf("tray/%s_hover.png" % name),
            app_theme.get_pixbuf("tray/%s_disable.png" % name),
        )

    def connect_events(self):
        self.connect("button-press-event", self.on_button_press_event)

    def on_button_press_event(self, widget, event):
        if event.button == 1:
            if event.state == gtk.gdk.CONTROL_MASK:
                Player.previous()
            else:
                self.instance.toggle_visible()

        elif event.button == 2:
            Player.playpause()

        elif event.button == 3:
            if event.state == gtk.gdk.CONTROL_MASK:
                Player.next()
            else:
                menu = gtk.Menu()
                (x, y, z) = self.get_menu_position(menu, self)
                self.update_menu()
                self.menu.show((int(x), int(y)), (0, -8))

    def destroy(self):
        self.instance.toggle_visible(True)
        self.set_visible(False)
Esempio n. 44
0
      None,
      (None, "子菜单B2", None),
      None,
      (None, "子菜单B3", sub_menu_c),
      ])
 
 menu = Menu(
     [(None,
       "测试测试测试1", None),
      (None,
       "测试测试测试2", sub_menu_a),
      (None,
       "测试测试测试3", sub_menu_b),
      (None,
       "测试测试测试", None),
      (None,
       "测试测试测试", None),
      (None,
       "测试测试测试4", None, (1, 2, 3)),
      (None,
       "测试测试测试5", None),
      (None,
       "测试测试测试6", None),
      ],
     True
     )
 menu.set_menu_item_sensitive_by_index(1, False)
 application.set_menu_callback(lambda button: menu.show(
         get_widget_root_coordinate(button, WIDGET_POS_BOTTOM_LEFT),
         (button.get_allocation().width, 0)))
 
 # Add navigatebar.
Esempio n. 45
0
class PlaylistUI(gtk.VBox):
    '''Playlist UI.'''

    def __init__(self):
        '''Init.'''
        gtk.VBox.__init__(self)

        # Init catagory list.
        self.category_list = CategoryView()
        setattr(self.category_list, "save_to_library", self.save_to_library)
        self.category_list.draw_mask = self.draw_category_list_mask
        self.category_list.connect("single-click-item", self.on_category_single_click)
        self.category_list.connect("right-press-items", self.on_category_right_press)
        self.category_list.set_size_request(CATEGROYLIST_WIDTH, -1)

        del self.category_list.keymap["Delete"]

        # Init SearchEntry.
        self.entry_box = SearchEntry("")
        self.entry_box.entry.connect("changed", self.search_cb)
        self.entry_box.set_no_show_all(True)
        entry_align = gtk.Alignment()
        entry_align.set(0, 0, 1, 1)
        entry_align.set_padding(2, 0, 10, 10)
        entry_align.add(self.entry_box)
        entry_align.connect("expose-event", self.expose_entry_mask)

        # Init toolbar.
        self.toolbar_box = gtk.HBox(spacing=45)
        self.search_button = self.__create_simple_toggle_button("search", self.show_text_entry,
                                                                _("Search in Current Playlist"))

        self.__create_simple_button("list", self.popup_list_menu, _("Playlist Operations"))
        self.__create_simple_button("add", self.popup_add_menu, _("Add"))

        self.playmode_button = PlaymodeButton(config.get("setting", "loop_mode", "list_mode").split("_")[0])
        Tooltip.text(self.playmode_button, _("Playback mode"))
        self.playmode_button.connect("button-press-event", self.popup_sort_menu)
        self.toolbar_box.pack_start(self.playmode_button, False, False)
        self.__create_simple_button("delete", self.popup_delete_menu, _("Delete"))
        toolbar_align = gtk.Alignment()
        toolbar_align.set_padding(6, 6, 28, 0)
        toolbar_align.add(self.toolbar_box)
        toolbar_align.connect("expose-event", self.expose_toolbar_mask)

        self.right_box = gtk.VBox()
        self.right_box.connect("size-allocate", self.on_right_box_size_allocate)
        self.list_paned = HPaned(handle_color=app_theme.get_color("panedHandler"), enable_drag=True)
        self.list_paned.pack1(self.category_list, True, True)
        self.list_paned.pack2(self.right_box, True, False)
        bottom_box = gtk.VBox()
        bottom_box.set_size_request(-1, 22)
        self.pack_start(self.list_paned, True, True)
        self.pack_start(entry_align, False, False)
        self.pack_start(toolbar_align, False, True)

        # Current
        self.current_playlist = None
        self.search_time_source = 0
        self.current_item = None
        self.search_flag = False
        self.cache_items = None
        self.delete_source_id = None
        self.drag_source_id = None
        self.menu_source_id = None
        self.song_notify_id = None
        self.detail_menu = None
        self.save_flag = False

        if MediaDB.isloaded():
            self.__on_db_loaded(MediaDB)
        else:
            MediaDB.connect("loaded", self.__on_db_loaded)

        Player.connect("loaded", self.__on_player_loaded)
        Dispatcher.connect("play-song", self.__play_and_add)
        Dispatcher.connect("add-songs", self.__add_songs_to_list)
        Dispatcher.connect("new-cd-playlist", self.__new_audiocd_playlist)
        Dispatcher.connect("del-cd-playlist", self.delete_audiocd_list)
        Dispatcher.connect("save-current-list", self.save_current_playlist)
        config.connect("config-changed", self.on_config_changed)

    def on_config_changed(self, config, section, option, value):
        if section == "setting" and option == "loop_mode":
            icon_name = value.split("_")[0]
            self.playmode_button.update_dpixbufs(icon_name, True)

    def on_right_box_size_allocate(self, widget, rect):
        if self.current_item:
            if rect.width > HIDE_PLAYLIST_WIDTH:
                self.current_item.song_view.set_hide_columns(None)
            else:
                self.current_item.song_view.set_hide_columns([1])

    def expose_toolbar_mask(self, widget, event):
        cr = widget.window.cairo_create()
        rect = widget.allocation
        cr.set_source_rgba(1, 1, 1, 0.95)
        cr.rectangle(rect.x, rect.y, rect.width, rect.height)
        cr.fill()

        draw_line(cr, (rect.x, rect.y + 1),
                  (rect.x + rect.width, rect.y + 1), "#b0b0b0")
        return False

    def expose_entry_mask(self, widget, event):
        cr = widget.window.cairo_create()
        rect = widget.allocation
        draw_alpha_mask(cr, rect.x , rect.y, rect.width, rect.height, "toolbarEntry")

    def draw_category_list_mask(self, cr, x, y, width, height):
        draw_alpha_mask(cr, x, y, width, height, "layoutLeft")

    def draw_item_mask(self, cr, x, y, width, height):
        draw_vlinear(cr, x, y, width, height,
                     app_theme.get_shadow_color("editlistItemPress").get_color_info())

    def __on_db_loaded(self, db):
        if not MediaDB.get_playlists():
            MediaDB.create_playlist("local", _("Default List"))

        # From MediaDB loaded playlists.
        init_items = [ListTreeItem(pl) for pl in MediaDB.get_playlists()]
        self.category_list.add_items(init_items)

        # Init Category_list.
        self.category_list.set_highlight_item(self.get_categroy_item_by_index(self.get_save_item_index()))
        self.current_item = self.category_list.get_highlight_item()

        self.delete_source_id = self.current_item.song_view.connect("delete-select-items", self.parser_delete_items)
        self.drag_source_id = self.current_item.song_view.connect("drag-data-received", self.parser_drag_event)
        self.menu_source_id = self.current_item.song_view.connect("right-press-items", self.popup_detail_menu)

        Player.set_source(self.current_item.song_view)
        self.right_box.add(self.current_item.get_list_widget())

        self.category_list.check_view_status()
        self.list_paned.show_all()

    def __on_player_loaded(self, player):
        if self.current_item:
            self.current_item.song_view.reset_error_items()
            self.current_item.song_view.set_highlight_song(Player.song)

    def restore_status(self):
        uri = config.get("player", "uri")
        seek = int(config.get("player", "seek"))
        state = config.get("player", "state")
        play = False

        if config.getboolean("player", "play_on_startup") and state == "playing":
            play = True

        if uri and self.current_item:
            song = MediaDB.get_song(uri)
            if song.get_type() == "cue":
                seek = seek + song.get("seek", 0)

            if song and song.exists():
                if not config.getboolean("player", "resume_last_progress") or not play:
                    if song.get_type() == "cue":
                        seek = song.get("seek", 0)
                    else:
                        seek = None

                self.current_item.song_view.play_song(song, play, seek)

    def __play_and_add(self, widget, song):
        self.current_item.song_view.add_songs(song, play=True)

    def __add_songs_to_list(self, widget, songs):
        if songs and self.current_item.song_view:
            self.current_item.song_view.add_songs(songs)

    def get_selected_song_view(self):
        if self.current_item:
            return self.current_item.song_view

    def search_cb(self, widget, text):
        if not self.search_flag:
            self.cache_items = self.current_item.song_view.get_items()

        # Clear song_view select status
        self.current_item.song_view.clear_highlight()
        self.current_item.song_view.select_rows = []

        if text != "":
            self.search_flag = True
            results = filter(lambda item: text.lower().replace(" ", "") in item.get_song().get("search", ""), self.cache_items)
            self.current_item.song_view.set_song_items(results)
        else:
            self.search_flag = False
            self.current_item.song_view.set_song_items(self.cache_items)

            if Player.song:
                self.current_item.song_view.set_highlight_song(Player.song)

    def parser_delete_items(self, widget, items):
        if self.search_flag:
            if self.cache_items != None:
                [self.cache_items.remove(item) for item in items if item in self.cache_items]

    def parser_drag_event(self, widget, context, x, y, selection, info, timestamp):
        if self.search_flag:
            self.reset_search_entry()

    def reset_search_entry(self):
        self.search_button.set_active(False)

    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_button(self, name, callback, tip_msg=""):
        button = ImageButton(
            app_theme.get_pixbuf("toolbar/%s_normal.png" % name),
            app_theme.get_pixbuf("toolbar/%s_hover.png" % name),
            app_theme.get_pixbuf("toolbar/%s_press.png" % name),
            )
        button.connect("button-press-event", callback)
        if tip_msg:
            Tooltip.text(button, tip_msg)

        self.toolbar_box.pack_start(button, False, False)
        return button

    def popup_add_menu(self, widget, event):
        self.current_item.song_view.popup_add_menu(int(event.x_root), int(event.y_root))


    def popup_list_menu(self, widget, event):
        menu_items = [(None, _("New List"), self.new_list),
                      (None, _("Import List"), self.leading_in_list),
                      (None, _("Open List"), self.add_to_list),
                      (None, _("Export List"), self.leading_out_list),
                      (None, _("Remove List"), self.delete_item_list),
                      None,
                      (None, _("Save all Lists"), self.save_all_list)]
        Menu(menu_items, True).show((int(event.x_root), int(event.y_root)))

    def new_list(self, items=[], name=None):
        index = len(self.category_list.get_items())
        if name is None:
            name = "%s%d" % (_("New List"), index)
        input_dialog = InputDialog(_("New List"), name, 300, 100, lambda name : self.create_new_playlist(name, items))
        input_dialog.show_all()

    def create_new_playlist(self, name, items):
        self.category_list.add_items([ListTreeItem(Playlist("local", name, items))])

    def __new_audiocd_playlist(self, obj, name, songs, udi):
        self.category_list.add_items([ListTreeItem(CDPlaylist("audiocd", name, songs), udi=udi)])

    def get_categroy_other_items(self):
        other_items = []
        highlight_item = self.category_list.get_highlight_item()
        for item in self.category_list.get_items():
            if highlight_item == item:
                continue
            other_items.append(item)
        return other_items

    def get_categroy_index_by_item(self, item):
        index = -1
        for each_index, each_item in enumerate(self.category_list.get_items()):
            if item == each_item:
                index = each_index
                break
        return index

    def get_categroy_item_by_index(self, index):
        try:
            return self.category_list.get_items()[index]
        except:
            return None

    def get_edit_sub_menu(self, select_items, move=False):
        sub_menu_items = []
        if len(self.category_list.get_items()) > 1:
            other_category_items = self.get_categroy_other_items()
            sub_menu_items = [(None, category_item.get_title(),
                               self.edit_list_item, category_item, select_items ,move) for category_item in other_category_items]
        if sub_menu_items:
            sub_menu_items.extend([None, ((app_theme.get_pixbuf("toolbar/add_normal.png"), None, None),
                                          _("New List"), self.edit_new_list_item, select_items, move)])
        else:
            sub_menu_items.extend([((app_theme.get_pixbuf("toolbar/add_normal.png"), None, None),
                                    _("New List"), self.edit_new_list_item, select_items, move)])
        return Menu(sub_menu_items)

    def edit_list_item(self, category_item, select_items, move):
        try:
            category_item.song_view.add_items(select_items)
            category_item.song_view.update_item_index()
            category_item.song_view.update_vadjustment()
            if move:
                self.current_item.song_view.remove_select_items()
        except:
            pass
        else:
            self.current_item.song_view.update_item_index()
            self.current_item.song_view.update_vadjustment()

    def edit_new_list_item(self, select_items, move):
        self.new_list([item.get_song().get("uri") for item in select_items])
        if move:
            self.current_item.song_view.remove_select_items()
        self.current_item.song_view.update_item_index()
        self.current_item.song_view.update_vadjustment()

    def leading_in_list(self):
        uri = WindowLoadPlaylist().run()
        try:
            self.import_list_from_uri(uri)
        except:
            pass

    def import_list_from_uri(self, uri):
        p_name = utils.get_filename(uri)
        pl = MediaDB.create_playlist("local", p_name, [])
        new_item = ListTreeItem(pl)
        self.category_list.add_items([new_item])
        new_item.song_view.async_add_uris(uri)

    def leading_out_list(self, item):
        if not item:
            item = self.current_item
        WindowExportPlaylist(item.get_songs()).run()

    def add_to_list(self, item=None):
        uri = WindowLoadPlaylist().run()
        if uri:
            try:
                if not item:
                    item = self.current_item
                item.song_view.async_add_uris(uri)
            except: pass

    def delete_audiocd_list(self, obj, udi):
        reset = False
        for item in self.category_list.get_items():
            if item.udi == udi:
                reset = True
                self.category_list.delete_items([item])
        if reset:
            self.reset_highlight_item(self.category_list.get_items()[-1])

    def delete_item_list(self, item):
        if len(self.category_list.get_items()) == 1:
            return

        index = self.get_categroy_index_by_item(item)
        self.category_list.delete_items([item])

        max_index = len(self.category_list.get_items()) - 1
        if index <= max_index:
            new_index = index
        else:
            new_index = index- 1
        self.reset_highlight_item(self.category_list.get_items()[new_index])

    def save_all_list(self):
        uri = WinDir().run()
        if uri:
            try:
                save_name_dict = {}
                dir_name = utils.get_path_from_uri(uri)
                for item in self.category_list.get_items():
                    item_name = item.get_title()
                    save_name_dict[item_name] = save_name_dict.get(item_name, -1) + 1
                    if save_name_dict.get(item_name) > 0:
                        filename = "%s%d.%s" % (os.path.join(dir_name, item_name), save_name_dict.get(item_name), "m3u")
                    else:
                        filename = "%s.%s" % (os.path.join(dir_name, item_name), "m3u")
                    utils.export_playlist(item.get_songs(), filename, "m3u")
            except:
                pass

    def reset_highlight_item(self, item):
        self.category_list.set_highlight_item(item)
        self.on_category_single_click(None, item, None, None, None)


    def get_current_item_index(self):
        item = self.category_list.get_highlight_item()
        index = self.get_categroy_index_by_item(item)
        if index is None:
            return 0
        else:
            return index

    def popup_sort_menu(self, widget, event):
        self.current_item.song_view.get_playmode_menu([int(event.x_root), int(event.y_root)])

    def popup_delete_menu(self, widget, event):
        self.current_item.song_view.popup_delete_menu(int(event.x_root), int(event.y_root))

    def get_save_item_index(self):
        index = config.getint("playlist", "current_index")
        if index <= len(self.category_list.get_items()) - 1:
            return index
        return 0

    def on_category_right_press(self, widget, x, y, item, column):
        if not item:
            menu_items = [
                (None, _("New List"), self.new_list),
                (None, _("Import List"), self.leading_in_list),
                None,
                (None, _("Save all Lists"), self.save_all_list)
                ]
        else:
            menu_items = [
                (None, _("Rename"), lambda : self.rename_item_list(item)),
                (None, _("Remove List"), lambda : self.delete_item_list(item)),
                (None, _("Open List"), lambda : self.add_to_list(item)),
                None,
                (None, _("Save all Lists"), self.save_all_list)
                ]

        Menu(menu_items, True).show((x, y))

    def rename_item_list(self, item):
        input_dialog = InputDialog(_("Rename"), item.get_title(), 300, 100,
                                   lambda name: item.set_title(name))
        input_dialog.show_all()

    def on_category_button_press(self, widget, event):
        if event.button == 3:
            self.popup_list_menu(widget, event)

    def on_category_single_click(self, widget, item, column, x, y):
        self.reset_search_entry()
        if self.drag_source_id != None or self.delete_source_id != None or self.menu_source_id !=None:
            gobject.source_remove(self.drag_source_id)
            gobject.source_remove(self.delete_source_id)
            gobject.source_remove(self.menu_source_id)

        self.current_item = item
        self.category_list.set_highlight_item(item)

        self.delete_source_id = self.current_item.song_view.connect("delete-select-items", self.parser_delete_items)
        self.drag_source_id = self.current_item.song_view.connect("drag-data-received", self.parser_drag_event)
        self.menu_source_id = self.current_item.song_view.connect("right-press-items", self.popup_detail_menu)

        container_remove_all(self.right_box)
        self.right_box.add(item.get_list_widget())
        self.list_paned.show_all()

    def show_text_entry(self, widget):
        if widget.get_active():
            self.entry_box.set_no_show_all(False)
            self.entry_box.show_all()
            self.entry_box.focus_input()
        else:
            self.entry_box.hide_all()
            self.entry_box.set_no_show_all(True)
            self.entry_box.entry.set_text("")

    def popup_detail_menu(self, widget, x, y, item, select_items):
        if self.detail_menu != None:
            self.detail_menu.destroy()
        play_mode_menu = self.current_item.song_view.get_playmode_menu(align=True)
        sort_dict = OrderedDict()
        sort_dict["file"] = _("By Filename")
        sort_dict["title"] = _("By Title")
        sort_dict["artist"] = _("By Artist")
        sort_dict["album"] = _("By Album")
        sort_dict["genre"] = _("By Genre")
        sort_dict["#track"] = _("By Track")
        sort_dict["#playcount"] = _("By Play Count")
        sort_dict["#added"] = _("By Added Time")

        sort_items = [(None, value, self.current_item.song_view.set_sort_keyword, key) for key, value in sort_dict.iteritems()]
        sort_items.append(None)
        sort_items.append((None, _("Randomize"), self.current_item.song_view.random_reorder))
        sub_sort_menu = Menu(sort_items)
        add_to_list_menu = self.get_edit_sub_menu(select_items)
        move_to_list_menu = self.get_edit_sub_menu(select_items, True)
        self.detail_menu = Menu([(None, _("Play"),  self.current_item.song_view.play_select_item),
                                 (None, _("Add to List"), add_to_list_menu),
                                 (None, _("Move to List"), move_to_list_menu),
                                 None,
                                 (None, _("Remove Track"), self.current_item.song_view.remove_select_items),
                                 (None, _("Move to Trash"), self.current_item.song_view.try_move_trash),
                                 (None, _("Clear List"), self.current_item.song_view.erase_items),
                                 None,
                                 (None, _("Playback mode"), play_mode_menu),
                                 (None, _("Sort"), sub_sort_menu),
                                 (None, _("Converter"), self.current_item.song_view.songs_convert),
                                 (None, _("Open directory"), self.current_item.song_view.open_song_dir),
                                 (None, _("Properties"), self.current_item.song_view.open_song_editor),
                                 ], True)

        if item and item.song.get_type() == "cue":
            self.detail_menu.set_menu_item_sensitive_by_index(5, False)
            self.detail_menu.set_menu_item_sensitive_by_index(10, False)
        self.detail_menu.show((int(x), int(y)))


    def save_current_playlist(self, *args):
        index = 0
        player_source = Player.get_source()
        for i, item in enumerate(self.category_list.get_items()):
            if item.song_view == player_source:
                index = i
        config.set("playlist","current_index", str(index))

    def save_to_library(self):
        if self.save_flag:
            return

        self.save_flag = True
        if self.search_flag:
            self.reset_search_entry()

        MediaDB.full_erase_playlists()
        for item in self.category_list.get_items():
            if item.udi is not None:
                continue
            songs = item.get_songs()
            name = item.get_title()
            MediaDB.create_playlist("local", name, songs)
        MediaDB.async_save()
        self.save_flag = False
Esempio n. 46
0
    def init_ui(self):
        self.application = Application()
        self.application.set_default_size(1000, 660)
        self.application.set_skin_preview(get_common_image("frame.png"))
        self.application.set_icon(get_common_image("logo48.png"))
        self.application.add_titlebar(
                ["theme", "menu", "max","min", "close"],
                show_title=False
                )
        self.application.window.set_title(_("Deepin Games"))

        # Init page box.
        self.page_box = gtk.VBox()
        self.page_box.connect('expose-event', self.page_box_render)
        
        # Init page align.
        self.page_align = gtk.Alignment()
        self.page_align.set(0.5, 0.5, 1, 1)
        self.page_align.set_padding(0, 0, 2, 2)
        
        # Append page to switcher.
        self.paned_box = PanedBox(24)
        self.paned_box.add_content_widget(self.page_box)
        self.bottom_tip_bar = BottomTipBar()
        self.bottom_tip_bar.close_button.connect('clicked', lambda w: self.paned_box.bottom_window.hide())
        self.paned_box.add_bottom_widget(self.bottom_tip_bar)

        self.page_align.add(self.paned_box)
        self.application.main_box.pack_start(self.page_align, True, True)
        
        # Init status bar.
        self.statusbar = Statusbar(30)
        status_box = gtk.HBox()

        self.statusbar.status_box.pack_start(status_box, True, True)
        self.application.main_box.pack_start(self.statusbar, False, False)

        self.webview = WebView(COOKIE_FILE)
        webkit.set_web_database_directory_path(CACHE_DIR)
        web_settings = self.webview.get_settings()
        web_settings.set_property("enable-page-cache", True)
        web_settings.set_property("enable-offline-web-application-cache", True)
        #web_settings.set_property("enable-file-access-from-file-uris", True)
        web_settings.set_property("enable-xss-auditor", False)
        web_settings.set_property('enable-universal-access-from-file-uris', True)
        web_settings.set_property("enable-default-context-menu", False)
        self.webview.set_settings(web_settings)
        #self.webview.enable_inspector()
        self.webview.connect('new-window-policy-decision-requested', self.navigation_policy_decision_requested_cb)
        #self.webview.connect('notify::load-status', self.webview_load_status_handler)
        self.webview.connect('notify::title', self.webview_title_changed_handler)
        self.webview.connect('script-alert', self.webview_script_alert_handler)
        self.webview.connect('window-object-cleared', self.webview_window_object_cleared)
        #self.webview.connect('load-progress-changed', self.load_progress)
        
        self.home_url = urllib.basejoin(GAME_CENTER_SERVER_ADDRESS, 'game/?hl=%s' % LANGUAGE)
        self.network_failed_box = NetworkConnectFailed(self.check_network_connection)
        self.check_network_connection()
        #self.page_box.add(self.network_failed_box)

        self.navigatebar = Navigatebar(
                [
                (None, _("Home"), self.show_home_page),
                (None, _("Topics"), self.show_subject_page),
                (None, _("My Games"), self.show_mygame_page),
                ],
                font_size = 11,
                padding_x = 5,
                padding_y = 16,
                vertical=False,
                item_normal_pixbuf=DynamicPixbuf(get_common_image('top/nav_normal.png')),
                item_hover_pixbuf=DynamicPixbuf(get_common_image('top/nav_hover.png')),
                item_press_pixbuf=DynamicPixbuf(get_common_image('top/nav_press.png')),
                )
        self.navigatebar.set_size_request(-1, 56)
        self.navigatebar_align = gtk.Alignment(0, 0, 1, 1)
        self.navigatebar_align.set_padding(0, 0, 4, 0)
        self.navigatebar_align.add(self.navigatebar)
        self.application.titlebar.set_size_request(-1, 56)
        self.application.titlebar.left_box.pack_start(self.navigatebar_align, True, True)
        self.application.window.add_move_event(self.navigatebar)

        self.about_dialog = AboutDialog(_('About us'))
        self.about_dialog.set_transient_for(self.application.window)

        # Init menu.
        #if LANGUAGE == 'en_US':
            #menu_min_width = 185
        #else:
            #menu_min_width = 150

        menu = Menu(
            [
             (None, _("Clear all cached data"), self.clean_download_cache),
             (None, _("See what's new"), lambda : self.show_wizard_win()),
             (None, _("About us"), self.show_about_dialog),
             (None, _("Quit"), lambda: gtk.main_quit()),
             ],
            is_root_menu=True,
            #menu_min_width=menu_min_width,
            )
        self.application.set_menu_callback(
            lambda button:
                menu.show(
                get_widget_root_coordinate(button, WIDGET_POS_BOTTOM_LEFT),
                (button.get_allocation().width, 0)))
        
        self.no_favorite_html_path = os.path.join(static_dir, "error-no-favorite.html")
        self.no_recent_html_path = os.path.join(static_dir, "error-no-recent.html")
        self.mygame_frame_path = os.path.join(static_dir, "mygame-frame.html")
        self.gallery_html_path = os.path.join(static_dir, 'game-mygame.html')

        skin_config.connect('theme-changed', self.theme_changed_handler)
        global_event.register_event('show-message', self.update_message)
Esempio n. 47
0
    def init_ui(self):
        self.loginfo("Init ui")
        # Init application.
        self.application = Application(
            resizable=False,
            destroy_func=self.application_close_window,
            )
        self.application.set_default_size(888, 634)
        self.application.set_skin_preview(utils.get_common_image("frame.png"))
        self.application.set_icon(utils.get_common_image("logo48.png"))
        self.application.add_titlebar(
                ["theme", "menu", "min", "close"],
                show_title=False
                )
        self.application.window.set_title(_("Deepin Store"))
        self.application.window.connect("delete-event", self.application_close_window)

        # Init page box.
        self.page_box = gtk.VBox()

        # Init page switcher.
        self.page_switcher = HSlider(200)
        self.page_switcher.append_page(self.page_box)
        self.page_switcher.set_to_page(self.page_box)

        # Init page align.
        self.page_align = gtk.Alignment()
        self.page_align.set(0.5, 0.5, 1, 1)
        self.page_align.set_padding(0, 0, 2, 2)

        # Append page to switcher.
        self.paned_box = PanedBox(24)
        self.paned_box.add_content_widget(self.page_switcher)
        self.bottom_tip_bar = BottomTipBar()
        self.bottom_tip_bar.close_button.connect('clicked', lambda w: self.paned_box.bottom_window.hide())
        self.paned_box.add_bottom_widget(self.bottom_tip_bar)
        self.page_align.add(self.paned_box)
        self.application.main_box.pack_start(self.page_align, True, True)

        # Init status bar.
        self.statusbar = Statusbar(24)
        status_box = gtk.HBox()
        self.message_box = gtk.HBox()

        self.message_label = Label("", enable_gaussian=True)
        label_align = gtk.Alignment()
        label_align.set(0.0, 0.5, 0, 0)
        label_align.set_padding(0, 0, 10, 0)
        label_align.add(self.message_label)
        self.message_box.pack_start(label_align)

        join_us_button = LinkButton(_("Join us"), "http://www.linuxdeepin.com/joinus/job")
        join_us_button_align = gtk.Alignment()
        join_us_button_align.set(0.5, 0.5, 0, 0)
        join_us_button_align.set_padding(0, 3, 0, 10)
        join_us_button_align.add(join_us_button)
        status_box.pack_start(self.message_box, True, True)
        status_box.pack_start(join_us_button_align, False, False)
        self.statusbar.status_box.pack_start(status_box, True, True)
        self.application.main_box.pack_start(self.statusbar, False, False)

        # Init navigatebar.
        self.detail_page = None
        self.home_page = None
        self.upgrade_page = None
        self.uninstall_page = None
        self.install_page = None

        self.navigatebar = Navigatebar(
                [
                (DynamicPixbuf(utils.get_common_image("navigatebar/nav_home.png")), _("Home"), self.show_home_page),
                (DynamicPixbuf(utils.get_common_image("navigatebar/nav_update.png")), _("Upgrade"), self.show_upgrade_page),
                (DynamicPixbuf(utils.get_common_image("navigatebar/nav_uninstall.png")), _("Uninstall"), self.show_uninstall_page),
                (DynamicPixbuf(utils.get_common_image("navigatebar/nav_download.png")), _("Installation"), self.show_install_page),
                ],
                font_size = 11,
                padding_x = 2,
                padding_y = 2,
                vertical=False,
                item_hover_pixbuf=DynamicPixbuf(utils.get_common_image("navigatebar/nav_hover.png")),
                item_press_pixbuf=DynamicPixbuf(utils.get_common_image("navigatebar/nav_press.png")),
                )
        self.navigatebar.set_size_request(-1, 56)
        self.navigatebar_align = gtk.Alignment(0, 0, 1, 1)
        self.navigatebar_align.set_padding(0, 0, 4, 0)
        self.navigatebar_align.add(self.navigatebar)
        self.application.titlebar.set_size_request(-1, 56)
        self.application.titlebar.left_box.pack_start(self.navigatebar_align, True, True)
        self.application.window.add_move_event(self.navigatebar)

        # Init menu.
        if LANGUAGE == 'en_US':
            menu_min_width = 185
        else:
            menu_min_width = 150
        menu = Menu(
            [
             (None, _("Refresh package lists"), lambda:global_event.emit('start-update-list')),
             (None, _("Open download directory"), self.open_download_directory),
             (None, _("Clear up cached packages"), self.clean_download_cache),
             (None, _("View new features"), lambda : self.show_wizard_win()),
             (self.get_pixbuf_group("menu", "setting"), _("Preferences"), self.show_preference_dialog),
             (self.get_pixbuf_group("menu", "close"), _("Quit"), self.exit),
             ],
            is_root_menu=True,
            menu_min_width=menu_min_width,
            )
        self.application.set_menu_callback(
            lambda button:
                menu.show(
                get_widget_root_coordinate(button, WIDGET_POS_BOTTOM_LEFT),
                (button.get_allocation().width, 0)))

        self.preference_dialog = DscPreferenceDialog()

        if hasattr(self, 'recommend_status'):
            self.init_home_page(self.recommend_status)
        else:
            self.init_home_page()