예제 #1
0
    def show_playlist_menu(self, url, playlistEmpty):
        self.menu = Menu(playlist_right_menu)
        self.menu.itemClicked.connect(self._menu_item_invoked)

        self.menu.getItemById("mode_group:radio:in_order").checked = \
            config.playerPlayOrderType == ORDER_TYPE_IN_ORDER
        self.menu.getItemById("mode_group:radio:random").checked = \
            config.playerPlayOrderType == ORDER_TYPE_RANDOM
        self.menu.getItemById("mode_group:radio:single").checked = \
            config.playerPlayOrderType == ORDER_TYPE_SINGLE
        self.menu.getItemById("mode_group:radio:single_cycle").checked = \
            config.playerPlayOrderType == ORDER_TYPE_SINGLE_CYCLE
        self.menu.getItemById("mode_group:radio:playlist_cycle").checked = \
            config.playerPlayOrderType == ORDER_TYPE_PLAYLIST_CYCLE

        self.menu.getItemById("_playlist_play").isActive = url != ""
        self.menu.getItemById(
            "_playlist_remove_item").isActive = not playlistEmpty
        self.menu.getItemById("_playlist_open_position").isActive = url != "" \
            and utils.urlIsNativeFile(url)
        self.menu.getItemById("_playlist_information").isActive = url != "" \
            and utils.urlIsNativeFile(url)
        self.menu.getItemById("_playlist_clear").isActive = not playlistEmpty

        self.menu.showRectMenu(QCursor.pos().x(), QCursor.pos().y())
예제 #2
0
    def on_activated(self, reason):
        if reason in [QSystemTrayIcon.Context, QSystemTrayIcon.Trigger]:
            geometry = self.geometry()
            mouse_x = int(geometry.x() / 2 + geometry.width() / 2)
            mouse_y = int(geometry.y() / 2)

            self.menu = Menu([
                CheckboxMenuItem("pause", "暂停翻译",
                                 setting_config.get_trayicon_config("pause")),
                CheckboxMenuItem(
                    "toggle_speech", "取词后发音",
                    setting_config.get_trayicon_config("toggle_speech")),
                CheckboxMenuItem(
                    "key_trigger_ocr", "按Ctrl键屏幕取词",
                    setting_config.get_trayicon_config("key_trigger_ocr")),
                CheckboxMenuItem(
                    "key_trigger_select", "按Shift键翻译选区",
                    setting_config.get_trayicon_config("key_trigger_select")),
                MenuSeparator(),
                ("settings", "设置"),
                ("wizard", "向导"),
                ("about", "关于"),
                MenuSeparator(),
                ("quit", "退出"),
            ])
            self.menu.itemClicked.connect(self.click_menu)
            self.menu.showDockMenu(mouse_x, mouse_y)
            self.set_menu_active(setting_config.get_trayicon_config("pause"))
예제 #3
0
class SystemTrayIcon(QSystemTrayIcon):
    
    showSettingView = pyqtSignal()
    
    def __init__(self, icon, parent=None):
        QSystemTrayIcon.__init__(self, icon, parent)
        self.activated.connect(self.on_activated) 
        
    @pyqtSlot(str, bool)
    def click_menu(self, menu_id, state):
        if menu_id == "quit":
            qApp.quit()
        elif menu_id == "wizard":
            pass
        elif menu_id == "about":
            pass
        elif menu_id == "settings":
            self.showSettingView.emit()
        else:
            if menu_id == "pause":
                if not state:
                    delete_selection()
                
                self.set_menu_active(state)    
                
            setting_config.update_trayicon_config(menu_id, state)
            
    def set_menu_active(self, state):
        self.menu.setItemActivity("toggle_speech", not state)
        self.menu.setItemActivity("key_trigger_ocr", not state)
        self.menu.setItemActivity("key_trigger_select", not state)
        
    def on_activated(self, reason):
        if reason in [QSystemTrayIcon.Context, QSystemTrayIcon.Trigger]:
            geometry = self.geometry()
            mouse_x = int(geometry.x() / 2 + geometry.width() / 2)
            mouse_y = int(geometry.y() / 2)
            
            self.menu = Menu([
                    CheckboxMenuItem("pause", "暂停翻译", setting_config.get_trayicon_config("pause")),
                    CheckboxMenuItem("toggle_speech", "取词后发音", setting_config.get_trayicon_config("toggle_speech")),
                    CheckboxMenuItem("key_trigger_ocr", "按Ctrl键屏幕取词", setting_config.get_trayicon_config("key_trigger_ocr")),
                    CheckboxMenuItem("key_trigger_select", "按Shift键翻译选区", setting_config.get_trayicon_config("key_trigger_select")),
                    MenuSeparator(),
                    ("settings", "设置"),
                    ("wizard", "向导"),
                    ("about", "关于"),
                    MenuSeparator(),
                    ("quit", "退出"),
                    ])
            self.menu.itemClicked.connect(self.click_menu)
            self.menu.showDockMenu(mouse_x, mouse_y)
            self.set_menu_active(setting_config.get_trayicon_config("pause"))
            
    def get_trayarea(self):
        geometry = self.geometry()
        return (geometry.y() / 2, geometry.y() / 2 + geometry.height())
예제 #4
0
    def on_activated(self, reason):
        if not self.menu_is_visible:
            if reason in [QSystemTrayIcon.Context, QSystemTrayIcon.Trigger]:
                geometry = self.geometry()
                if QT_VERSION == "5.1":
                    mouse_x = int(geometry.x() / 2 + geometry.width() / 2)
                    mouse_y = int(geometry.y() / 2)
                else:
                    mouse_x = int(geometry.x() + geometry.width() / 2)
                    mouse_y = int(geometry.y())

                self.menu = Menu([
                    CheckableMenuItem(
                        "pause", _("Pause translation"),
                        setting_config.get_trayicon_config("pause")),
                    CheckableMenuItem(
                        "toggle_speech", _("Pronounce automatically"),
                        setting_config.get_trayicon_config("toggle_speech")),
                    CheckableMenuItem(
                        "key_trigger_select",
                        _("Translate only when holding Ctrl key"),
                        setting_config.get_trayicon_config(
                            "key_trigger_select")),
                    CheckableMenuItem(
                        "local_translate", _("Offline translation"),
                        setting_config.get_trayicon_config("local_translate")),
                    MenuSeparator(),
                    CheckableMenuItem("lang",
                                      self.get_lang_value(),
                                      showCheckmark=False),
                    MenuSeparator(),
                    ("settings", _("Settings")),
                    # ("wizard", _("Wizard")),
                    MenuSeparator(),
                    ("quit", _("Exit")),
                ])

                self.menu.itemClicked.connect(self.click_menu)
                self.menu.menuDismissed.connect(self.exit_menu)
                self.set_menu_active(
                    setting_config.get_trayicon_config("pause"))
                if mouse_y > screen_height / 2:
                    self.menu.showDockMenu(mouse_x,
                                           mouse_y,
                                           cornerDirection="down")
                else:
                    self.menu.showDockMenu(mouse_x,
                                           mouse_y + geometry.height(),
                                           cornerDirection="up")

        self.menu_is_visible = not self.menu_is_visible
예제 #5
0
    def show_mode_menu(self):
        self.menu = Menu(play_sequence_sub_menu)
        self.menu.itemClicked.connect(self._menu_item_invoked)

        self.menu.getItemById("mode_group:radio:in_order").checked = \
            config.playerPlayOrderType == ORDER_TYPE_IN_ORDER
        self.menu.getItemById("mode_group:radio:random").checked = \
            config.playerPlayOrderType == ORDER_TYPE_RANDOM
        self.menu.getItemById("mode_group:radio:single").checked = \
            config.playerPlayOrderType == ORDER_TYPE_SINGLE
        self.menu.getItemById("mode_group:radio:single_cycle").checked = \
            config.playerPlayOrderType == ORDER_TYPE_SINGLE_CYCLE
        self.menu.getItemById("mode_group:radio:playlist_cycle").checked = \
            config.playerPlayOrderType == ORDER_TYPE_PLAYLIST_CYCLE

        self.menu.showRectMenu(QCursor.pos().x(), QCursor.pos().y())
예제 #6
0
 def on_activated(self, reason):
     if reason in [QSystemTrayIcon.Context, QSystemTrayIcon.Trigger]:
         geometry = self.geometry()
         mouse_x = int(geometry.x() / 2 + geometry.width() / 2)
         mouse_y = int(geometry.y() / 2)
         
         self.menu = Menu([
                 CheckboxMenuItem("pause", _("Pause translate"), 
                                  setting_config.get_trayicon_config("pause")),
                 CheckboxMenuItem("toggle_speech", _("Voice after translate"), 
                                  setting_config.get_trayicon_config("toggle_speech")),
                 CheckboxMenuItem("key_trigger_select", _("Press ctrl to translate selection"), 
                                  setting_config.get_trayicon_config("key_trigger_select")),
                 MenuSeparator(),
                 CheckboxMenuItem("lang", self.get_lang_value(), showCheckmark=False),
                 MenuSeparator(),
                 ("settings", _("Settings")),
                 ("wizard", _("Wizard")),
                 ("about", _("About")),
                 MenuSeparator(),
                 ("quit", _("Exit")),
                 ])
         self.menu.itemClicked.connect(self.click_menu)
         self.menu.showDockMenu(mouse_x, mouse_y)
         self.set_menu_active(setting_config.get_trayicon_config("pause"))
예제 #7
0
    def show_menu(self):
        self.menu = Menu(right_click_menu)

        hasVideo = movie_info.movie_file != ""
        self.menu.getItemById("_fullscreen_quit").isActive = hasVideo
        self.menu.getItemById("_mini_mode").isActive = hasVideo
        self.menu.getItemById("_play_operation_forward").isActive = hasVideo
        self.menu.getItemById("_play_operation_backward").isActive = hasVideo
        self.menu.getItemById("_frame").isActive = \
            hasVideo and self._window.getState() != Qt.WindowFullScreen
        self.menu.getItemById("_subtitle_hide").isActive = \
            hasVideo and bool(movie_info.subtitle_file)
        self.menu.getItemById("_subtitle_manual").isActive = hasVideo
        self.menu.getItemById("_subtitle_choose").isActive = \
            bool(movie_info.subtitle_file)
        self.menu.getItemById("_information").isActive = hasVideo \
            and movie_info.movie_duration != 0

        self.menu.getItemById("_on_top").checked = self._window.staysOnTop

        self.menu.getItemById("proportion:radio:_p_default").checked = \
            self._proportion == "proportion:radio:_p_default"
        self.menu.getItemById("proportion:radio:_p_4_3").checked = \
            self._proportion == "proportion:radio:_p_4_3"
        self.menu.getItemById("proportion:radio:_p_16_9").checked = \
            self._proportion == "proportion:radio:_p_16_9"
        self.menu.getItemById("proportion:radio:_p_16_10").checked = \
            self._proportion == "proportion:radio:_p_16_10"
        self.menu.getItemById("proportion:radio:_p_1_85_1").checked = \
            self._proportion == "proportion:radio:_p_1_85_1"
        self.menu.getItemById("proportion:radio:_p_2_35_1").checked = \
            self._proportion == "proportion:radio:_p_2_35_1"

        self.menu.getItemById("scale:radio:_s_0_5").checked = \
            self._scale == "scale:radio:_s_0_5"
        self.menu.getItemById("scale:radio:_s_1").checked = \
            self._scale == "scale:radio:_s_1"
        self.menu.getItemById("scale:radio:_s_1_5").checked = \
            self._scale == "scale:radio:_s_1_5"
        self.menu.getItemById("scale:radio:_s_2").checked = \
            self._scale == "scale:radio:_s_2"

        self.menu.getItemById("_sound_muted").checked = config.playerMuted

        self.menu.getItemById("_subtitle_hide").checked = \
            not self._window.subtitleVisible
        subtitles = movie_info.movie_file)
        subtitles = _subtitle_menu_items_from_files(subtitles)
        self.menu.getItemById("_subtitle_choose").setSubMenu(Menu(subtitles))

        self.menu.getItemById("_fullscreen_quit").text = _("Fullscreen") if \
            self._window.getState() != Qt.WindowFullScreen else _("Exit fullscreen")
        self.menu.getItemById("_mini_mode").text = _("Exit mini mode") if \
            self._window.miniModeState() else _("Mini mode")

        self.menu.itemClicked.connect(self._menu_item_invoked)
        self.menu.showRectMenu(QCursor.pos().x(), QCursor.pos().y())
예제 #8
0
    def show_menu(self, saveOption):
        self.preMenuShow.emit()

        self.menu = Menu(right_click_menu)
        self.menu.getItemById("_save").setSubMenu(Menu(save_sub_menu))

        self.menu.getItemById("save:radio:_op_auto_save").checked = \
            saveOption == 1
        self.menu.getItemById("save:radio:_op_save_to_desktop").checked = \
            saveOption == 0
        self.menu.getItemById("save:radio:_op_copy_to_clipboard").checked = \
            saveOption == 4
        self.menu.getItemById("save:radio:_op_save_as").checked = \
            saveOption == 2
        self.menu.getItemById("save:radio:_op_copy_and_save").checked = \
            saveOption == 3

        self.menu.itemClicked.connect(self._menu_item_invoked)
        self.menu.menuDismissed.connect(self._menu_unregistered)
        self.menu.showRectMenu(QCursor.pos().x(), QCursor.pos().y())
예제 #9
0
    def show_mode_menu(self):
        self.menu = Menu(play_sequence_sub_menu)
        self.menu.itemClicked.connect(self._menu_item_invoked)

        self.menu.getItemById("mode_group:radio:in_order").checked = \
            config.playerPlayOrderType == ORDER_TYPE_IN_ORDER
        self.menu.getItemById("mode_group:radio:random").checked = \
            config.playerPlayOrderType == ORDER_TYPE_RANDOM
        self.menu.getItemById("mode_group:radio:single").checked = \
            config.playerPlayOrderType == ORDER_TYPE_SINGLE
        self.menu.getItemById("mode_group:radio:single_cycle").checked = \
            config.playerPlayOrderType == ORDER_TYPE_SINGLE_CYCLE
        self.menu.getItemById("mode_group:radio:playlist_cycle").checked = \
            config.playerPlayOrderType == ORDER_TYPE_PLAYLIST_CYCLE

        self.menu.showRectMenu(QCursor.pos().x(), QCursor.pos().y())
예제 #10
0
    def show_menu(self, saveOption):
        self.preMenuShow.emit()

        self.menu = Menu(right_click_menu)
        self.menu.getItemById("_save").setSubMenu(Menu(save_sub_menu))

        self.menu.getItemById("save:radio:_op_save_to_desktop").checked = \
            saveOption == 0
        self.menu.getItemById("save:radio:_op_auto_save").checked = \
            saveOption == 1
        self.menu.getItemById("save:radio:_op_save_as").checked = \
            saveOption == 2
        self.menu.getItemById("save:radio:_op_copy_to_clipboard").checked = \
            saveOption == 3
        self.menu.getItemById("save:radio:_op_copy_and_save").checked = \
            saveOption == 4

        self.menu.itemClicked.connect(self._menu_item_invoked)
        self.menu.menuDismissed.connect(self._menu_unregistered)
        self.menu.showRectMenu(QCursor.pos().x(), QCursor.pos().y())
예제 #11
0
 def on_activated(self, reason):
     if reason in [QSystemTrayIcon.Context, QSystemTrayIcon.Trigger]:
         geometry = self.geometry()
         mouse_x = int(geometry.x() / 2 + geometry.width() / 2)
         mouse_y = int(geometry.y() / 2)
         
         self.menu = Menu([
                 CheckboxMenuItem("pause", "暂停翻译", setting_config.get_trayicon_config("pause")),
                 CheckboxMenuItem("toggle_speech", "取词后发音", setting_config.get_trayicon_config("toggle_speech")),
                 CheckboxMenuItem("key_trigger_ocr", "按Ctrl键屏幕取词", setting_config.get_trayicon_config("key_trigger_ocr")),
                 CheckboxMenuItem("key_trigger_select", "按Shift键翻译选区", setting_config.get_trayicon_config("key_trigger_select")),
                 MenuSeparator(),
                 ("settings", "设置"),
                 ("wizard", "向导"),
                 ("about", "关于"),
                 MenuSeparator(),
                 ("quit", "退出"),
                 ])
         self.menu.itemClicked.connect(self.click_menu)
         self.menu.showDockMenu(mouse_x, mouse_y)
         self.set_menu_active(setting_config.get_trayicon_config("pause"))
예제 #12
0
 def on_activated(self, reason):
     if not self.menu_is_visible:
         if reason in [QSystemTrayIcon.Context, QSystemTrayIcon.Trigger]:
             geometry = self.geometry()
             if QT_VERSION == "5.1":
                 mouse_x = int(geometry.x() / 2 + geometry.width() / 2)
                 mouse_y = int(geometry.y() / 2)
             else:
                 mouse_x = int(geometry.x() + geometry.width() / 2)
                 mouse_y = int(geometry.y())
             
             self.menu = Menu([
                     CheckableMenuItem("pause", _("Pause translation"), 
                                      setting_config.get_trayicon_config("pause")),
                     CheckableMenuItem("toggle_speech", _("Pronounce automatically"), 
                                      setting_config.get_trayicon_config("toggle_speech")),
                     CheckableMenuItem("key_trigger_select", _("Translate only when holding Ctrl key"), 
                                      setting_config.get_trayicon_config("key_trigger_select")),
                     CheckableMenuItem("local_translate", _("Offline translation"),
                                      setting_config.get_trayicon_config("local_translate")),
                     MenuSeparator(),
                     CheckableMenuItem("lang", self.get_lang_value(), showCheckmark=False),
                     MenuSeparator(),
                     ("settings", _("Settings")),
                     # ("wizard", _("Wizard")),
                     MenuSeparator(),
                     ("quit", _("Exit")),
                     ])
             
             self.menu.itemClicked.connect(self.click_menu)
             self.menu.menuDismissed.connect(self.exit_menu)
             self.set_menu_active(setting_config.get_trayicon_config("pause"))
             if mouse_y > screen_height / 2:
                 self.menu.showDockMenu(mouse_x, mouse_y, cornerDirection="down")
             else:
                 self.menu.showDockMenu(mouse_x, mouse_y + geometry.height(), cornerDirection="up")
         
     self.menu_is_visible = not self.menu_is_visible
예제 #13
0
    def show_playlist_menu(self, url):
        self.menu = Menu(playlist_right_menu)
        self.menu.itemClicked.connect(self._menu_item_invoked)

        self.menu.getItemById("mode_group:radio:in_order").checked = \
            config.playerPlayOrderType == ORDER_TYPE_IN_ORDER
        self.menu.getItemById("mode_group:radio:random").checked = \
            config.playerPlayOrderType == ORDER_TYPE_RANDOM
        self.menu.getItemById("mode_group:radio:single").checked = \
            config.playerPlayOrderType == ORDER_TYPE_SINGLE
        self.menu.getItemById("mode_group:radio:single_cycle").checked = \
            config.playerPlayOrderType == ORDER_TYPE_SINGLE_CYCLE
        self.menu.getItemById("mode_group:radio:playlist_cycle").checked = \
            config.playerPlayOrderType == ORDER_TYPE_PLAYLIST_CYCLE

        self.menu.getItemById("_playlist_play").isActive = url != ""
        self.menu.getItemById("_playlist_remove_item").isActive = url != ""
        self.menu.getItemById("_playlist_open_position").isActive = url != "" \
            and utils.urlIsNativeFile(url)
        self.menu.getItemById("_playlist_information").isActive = url != "" \
            and utils.fileIsValidVideo(url)

        self.menu.showRectMenu(QCursor.pos().x(), QCursor.pos().y())
예제 #14
0
class MenuController(QObject):

    toggleFullscreen = pyqtSignal()
    toggleMiniMode = pyqtSignal()
    screenShot = pyqtSignal()
    scaleChanged = pyqtSignal(float, arguments=["scale"])
    proportionChanged = pyqtSignal(float, float,
                                   arguments=["propWidth", "propHeight"])
    openDialog = pyqtSignal(str)
    staysOnTop = pyqtSignal(bool, arguments=["onTop"])
    showPreference = pyqtSignal()
    showMovieInformation = pyqtSignal()
    subtitleSelected = pyqtSignal(str, arguments=["subtitle"])
    playForward = pyqtSignal()
    playBackward = pyqtSignal()
    volumeUp = pyqtSignal()
    volumeDown = pyqtSignal()
    volumeMuted = pyqtSignal()
    showSubtitleSettings = pyqtSignal()

    def __init__(self, window):
        super(MenuController, self).__init__()
        self._window = window

        self._proportion = "proportion:radio:_p_default"
        self._scale = "scale:radio:_s_1"

    # if actions-like menu items are clicked, we should send signals to inform
    # the main controller that actions should be taken, if configs-like menu
    # items are clicked, we just change the configuration, config.py will takes
    # care of it for you .
    def _menu_item_invoked(self, _id, _checked):
        if _id == "_fullscreen_quit":
            self.toggleFullscreen.emit()
        elif _id == "_screenshot":
            self.screenShot.emit()
        elif _id == "proportion:radio:_p_default":
            self._proportion = "proportion:radio:_p_default"
            self.proportionChanged.emit(1, 1)
        elif _id == "proportion:radio:_p_4_3":
            self._proportion = "proportion:radio:_p_4_3"
            self.proportionChanged.emit(4, 3)
        elif _id == "proportion:radio:_p_16_9":
            self._proportion = "proportion:radio:_p_16_9"
            self.proportionChanged.emit(16, 9)
        elif _id == "proportion:radio:_p_16_10":
            self._proportion = "proportion:radio:_p_16_10"
            self.proportionChanged.emit(16, 10)
        elif _id == "proportion:radio:_p_1_85_1":
            self._proportion = "proportion:radio:_p_1_85_1"
            self.proportionChanged.emit(1.85, 1)
        elif _id == "proportion:radio:_p_2_35_1":
            self._proportion = "proportion:radio:_p_2_35_1"
            self.proportionChanged.emit(2.35, 1)
        elif _id == "scale:radio:_s_0_5":
            self._scale = "scale:radio:_s_0_5"
            self.scaleChanged.emit(0.5)
        elif _id == "scale:radio:_s_1":
            self._scale = "scale:radio:_s_1"
            self.scaleChanged.emit(1)
        elif _id == "scale:radio:_s_1_5":
            self._scale = "scale:radio:_s_1_5"
            self.scaleChanged.emit(1.5)
        elif _id == "scale:radio:_s_2":
            self._scale = "scale:radio:_s_2"
            self.scaleChanged.emit(2)
        elif _id == "_open_file":
            self.openDialog.emit("file")
        elif _id == "_open_url":
            self.openDialog.emit("url")
        elif _id == "_mini_mode":
            self.toggleMiniMode.emit()
        elif _id == "_on_top":
            self.staysOnTop.emit(_checked)
        elif _id == "_sound_muted":
            config.playerMuted = _checked
        elif _id == "_subtitle_hide":
            self._window.subtitleVisible = not _checked
        elif _id.startswith("_subtitles:radio"):
            self.subtitleSelected.emit(_subtitle_file_from_menu_item_id(_id))
        elif _id == "_play_operation_forward":
            self.playForward.emit()
        elif _id == "_play_operation_backward":
            self.playBackward.emit()
        elif _id == "_sound_increase":
            self.volumeUp.emit()
        elif _id == "_sound_decrease":
            self.volumeDown.emit()
        elif _id == "_sound_muted":
            self.volumeMuted.emit()
        elif _id == "_subtitle_settings":
            self.showSubtitleSettings.emit()
        elif _id == "_preferences":
            self.showPreference.emit()
        elif _id == "_information":
            self.showMovieInformation.emit()

    @pyqtSlot()
    def show_menu(self):
        self.menu = Menu(right_click_menu)

        hasVideo = movie_info.movie_file != ""
        self.menu.getItemById("_fullscreen_quit").isActive = hasVideo
        self.menu.getItemById("_mini_mode").isActive = hasVideo
        self.menu.getItemById("_play_operation_forward").isActive = hasVideo
        self.menu.getItemById("_play_operation_backward").isActive = hasVideo
        self.menu.getItemById("_frame").isActive = \
            hasVideo and self._window.getState() != Qt.WindowFullScreen
        self.menu.getItemById("_subtitle_hide").isActive = \
            hasVideo and bool(movie_info.subtitle_file)
        self.menu.getItemById("_subtitle_manual").isActive = hasVideo
        self.menu.getItemById("_subtitle_choose").isActive = \
            bool(movie_info.subtitle_file)
        self.menu.getItemById("_information").isActive = hasVideo \
            and movie_info.movie_duration != 0

        self.menu.getItemById("_on_top").checked = self._window.staysOnTop

        self.menu.getItemById("proportion:radio:_p_default").checked = \
            self._proportion == "proportion:radio:_p_default"
        self.menu.getItemById("proportion:radio:_p_4_3").checked = \
            self._proportion == "proportion:radio:_p_4_3"
        self.menu.getItemById("proportion:radio:_p_16_9").checked = \
            self._proportion == "proportion:radio:_p_16_9"
        self.menu.getItemById("proportion:radio:_p_16_10").checked = \
            self._proportion == "proportion:radio:_p_16_10"
        self.menu.getItemById("proportion:radio:_p_1_85_1").checked = \
            self._proportion == "proportion:radio:_p_1_85_1"
        self.menu.getItemById("proportion:radio:_p_2_35_1").checked = \
            self._proportion == "proportion:radio:_p_2_35_1"

        self.menu.getItemById("scale:radio:_s_0_5").checked = \
            self._scale == "scale:radio:_s_0_5"
        self.menu.getItemById("scale:radio:_s_1").checked = \
            self._scale == "scale:radio:_s_1"
        self.menu.getItemById("scale:radio:_s_1_5").checked = \
            self._scale == "scale:radio:_s_1_5"
        self.menu.getItemById("scale:radio:_s_2").checked = \
            self._scale == "scale:radio:_s_2"

        self.menu.getItemById("_sound_muted").checked = config.playerMuted

        self.menu.getItemById("_subtitle_hide").checked = \
            not self._window.subtitleVisible
        subtitles = movie_info.movie_file)
        subtitles = _subtitle_menu_items_from_files(subtitles)
        self.menu.getItemById("_subtitle_choose").setSubMenu(Menu(subtitles))

        self.menu.getItemById("_fullscreen_quit").text = _("Fullscreen") if \
            self._window.getState() != Qt.WindowFullScreen else _("Exit fullscreen")
        self.menu.getItemById("_mini_mode").text = _("Exit mini mode") if \
            self._window.miniModeState() else _("Mini mode")

        self.menu.itemClicked.connect(self._menu_item_invoked)
        self.menu.showRectMenu(QCursor.pos().x(), QCursor.pos().y())
예제 #15
0
class SystemTrayIcon(QSystemTrayIcon):
    
    showSettingView = pyqtSignal()
    
    def __init__(self, parent=None):
        QSystemTrayIcon.__init__(self, self.get_trayicon(), parent)
        self.activated.connect(self.on_activated) 
        
        self.menu_is_visible = False
        
    def set_trayicon(self):
        self.setIcon(self.get_trayicon())
        
    def get_trayicon(self):
        if is_true(setting_config.get_trayicon_config("pause")):
            icon_name = "pause_trayicon.png"
        else:
            icon_name = "trayicon.png"
            
        return QIcon(os.path.join(get_parent_dir(__file__), "image", icon_name))
    
    @pyqtSlot(str, bool)
    def click_menu(self, menu_id, state):
        if menu_id == "quit":
            qApp.quit()
        elif menu_id == "wizard":
            pass
        elif menu_id == "about":
            pass
        elif menu_id == "settings":
            self.showSettingView.emit()
        elif menu_id == "lang":
            src_lang = setting_config.get_translate_config("src_lang")
            dst_lang = setting_config.get_translate_config("dst_lang")
            setting_config.update_translate_config("src_lang", dst_lang)
            setting_config.update_translate_config("dst_lang", src_lang)
            
            self.menu.setItemText("lang", self.get_lang_value())
            
            setting_view.updateLang.emit()
        else:
            if menu_id == "pause":
                if not state:
                    delete_selection()
                
                self.set_menu_active(state)    
                
            setting_config.update_trayicon_config(menu_id, state)
            
            self.set_trayicon()
            
    def set_menu_active(self, state):
        self.menu.setItemActivity("toggle_speech", not state)
        self.menu.setItemActivity("key_trigger_select", not state)
        self.menu.setItemActivity("local_translate", not state)
        
    def get_lang_value(self):
        return (dict(LANGUAGES))[setting_config.get_translate_config("src_lang")] + " <=> " + (dict(LANGUAGES))[setting_config.get_translate_config("dst_lang")]
        
    def on_activated(self, reason):
        if not self.menu_is_visible:
            if reason in [QSystemTrayIcon.Context, QSystemTrayIcon.Trigger]:
                geometry = self.geometry()
                if QT_VERSION == "5.1":
                    mouse_x = int(geometry.x() / 2 + geometry.width() / 2)
                    mouse_y = int(geometry.y() / 2)
                else:
                    mouse_x = int(geometry.x() + geometry.width() / 2)
                    mouse_y = int(geometry.y())
                
                self.menu = Menu([
                        CheckableMenuItem("pause", _("Pause translation"), 
                                         setting_config.get_trayicon_config("pause")),
                        CheckableMenuItem("toggle_speech", _("Pronounce automatically"), 
                                         setting_config.get_trayicon_config("toggle_speech")),
                        CheckableMenuItem("key_trigger_select", _("Translate only when holding Ctrl key"), 
                                         setting_config.get_trayicon_config("key_trigger_select")),
                        CheckableMenuItem("local_translate", _("Offline translation"),
                                         setting_config.get_trayicon_config("local_translate")),
                        MenuSeparator(),
                        CheckableMenuItem("lang", self.get_lang_value(), showCheckmark=False),
                        MenuSeparator(),
                        ("settings", _("Settings")),
                        # ("wizard", _("Wizard")),
                        MenuSeparator(),
                        ("quit", _("Exit")),
                        ])
                
                self.menu.itemClicked.connect(self.click_menu)
                self.menu.menuDismissed.connect(self.exit_menu)
                self.set_menu_active(setting_config.get_trayicon_config("pause"))
                if mouse_y > screen_height / 2:
                    self.menu.showDockMenu(mouse_x, mouse_y, cornerDirection="down")
                else:
                    self.menu.showDockMenu(mouse_x, mouse_y + geometry.height(), cornerDirection="up")
            
        self.menu_is_visible = not self.menu_is_visible
        
    @pyqtSlot()    
    def exit_menu(self):
        self.menu_is_visible = False
                    
    def get_trayarea(self):
        geometry = self.geometry()
        return (geometry.y() / 2, geometry.y() / 2 + geometry.height())
예제 #16
0
    def show_add_button_menu(self):
        self.menu = Menu(playlist_add_button_menu)
        self.menu.itemClicked.connect(self._menu_item_invoked)

        self.menu.showRectMenu(QCursor.pos().x(), QCursor.pos().y())
예제 #17
0
class SystemTrayIcon(QSystemTrayIcon):
    
    showSettingView = pyqtSignal()
    
    def __init__(self, parent=None):
        QSystemTrayIcon.__init__(self, self.get_trayicon(), parent)
        self.activated.connect(self.on_activated) 
        
    def set_trayicon(self):
        self.setIcon(self.get_trayicon())
        
    def get_trayicon(self):
        if is_true(setting_config.get_trayicon_config("pause")):
            icon_name = "pause_trayicon.png"
        else:
            icon_name = "trayicon.png"
            
        return QIcon(os.path.join(get_parent_dir(__file__), "image", icon_name))
    
    @pyqtSlot(str, bool)
    def click_menu(self, menu_id, state):
        if menu_id == "quit":
            qApp.quit()
        elif menu_id == "wizard":
            pass
        elif menu_id == "about":
            pass
        elif menu_id == "settings":
            self.showSettingView.emit()
        elif menu_id == "lang":
            src_lang = setting_config.get_translate_config("src_lang")
            dst_lang = setting_config.get_translate_config("dst_lang")
            setting_config.update_translate_config("src_lang", dst_lang)
            setting_config.update_translate_config("dst_lang", src_lang)
            
            self.menu.setItemText("lang", self.get_lang_value())
            
            setting_view.updateLang.emit()
        else:
            if menu_id == "pause":
                if not state:
                    delete_selection()
                
                self.set_menu_active(state)    
                
            setting_config.update_trayicon_config(menu_id, state)
            
            self.set_trayicon()
            
    def set_menu_active(self, state):
        self.menu.setItemActivity("toggle_speech", not state)
        self.menu.setItemActivity("key_trigger_select", not state)
        
    def get_lang_value(self):
        return (dict(LANGUAGES))[setting_config.get_translate_config("src_lang")] + " -> " + (dict(LANGUAGES))[setting_config.get_translate_config("dst_lang")]
        
    def on_activated(self, reason):
        if reason in [QSystemTrayIcon.Context, QSystemTrayIcon.Trigger]:
            geometry = self.geometry()
            mouse_x = int(geometry.x() / 2 + geometry.width() / 2)
            mouse_y = int(geometry.y() / 2)
            
            self.menu = Menu([
                    CheckboxMenuItem("pause", _("Pause translate"), 
                                     setting_config.get_trayicon_config("pause")),
                    CheckboxMenuItem("toggle_speech", _("Voice after translate"), 
                                     setting_config.get_trayicon_config("toggle_speech")),
                    CheckboxMenuItem("key_trigger_select", _("Press ctrl to translate selection"), 
                                     setting_config.get_trayicon_config("key_trigger_select")),
                    MenuSeparator(),
                    CheckboxMenuItem("lang", self.get_lang_value(), showCheckmark=False),
                    MenuSeparator(),
                    ("settings", _("Settings")),
                    ("wizard", _("Wizard")),
                    ("about", _("About")),
                    MenuSeparator(),
                    ("quit", _("Exit")),
                    ])
            self.menu.itemClicked.connect(self.click_menu)
            self.menu.showDockMenu(mouse_x, mouse_y)
            self.set_menu_active(setting_config.get_trayicon_config("pause"))
            
    def get_trayarea(self):
        geometry = self.geometry()
        return (geometry.y() / 2, geometry.y() / 2 + geometry.height())
예제 #18
0
    def show_menu(self, stateInfo):
        info = json.loads(stateInfo)
        videoSource = info["videoSource"]
        hasVideo = info["hasVideo"]
        subtitleFile = info["subtitleFile"]
        subtitleVisible = info["subtitleVisible"]
        isFullscreen = info["isFullscreen"]
        isMiniMode = info["isMiniMode"]
        isOnTop = info["isOnTop"]

        self.menu = Menu(right_click_menu)

        self.menu.getItemById("_fullscreen_quit").isActive = hasVideo
        self.menu.getItemById("_mini_mode").isActive = hasVideo
        self.menu.getItemById("_play_operation_forward").isActive = hasVideo
        self.menu.getItemById("_play_operation_backward").isActive = hasVideo
        self.menu.getItemById("_frame").isActive = hasVideo and not isFullscreen
        self.menu.getItemById("_subtitle_hide").isActive = subtitleFile != ""
        self.menu.getItemById("_subtitle_manual").isActive = hasVideo
        self.menu.getItemById("_subtitle_choose").isActive = subtitleFile != ""
        self.menu.getItemById("_information").isActive = hasVideo

        self.menu.getItemById("_on_top").checked = isOnTop

        self.menu.getItemById("mode_group:radio:in_order").checked = \
            config.playerPlayOrderType == ORDER_TYPE_IN_ORDER
        self.menu.getItemById("mode_group:radio:random").checked = \
            config.playerPlayOrderType == ORDER_TYPE_RANDOM
        self.menu.getItemById("mode_group:radio:single").checked = \
            config.playerPlayOrderType == ORDER_TYPE_SINGLE
        self.menu.getItemById("mode_group:radio:single_cycle").checked = \
            config.playerPlayOrderType == ORDER_TYPE_SINGLE_CYCLE
        self.menu.getItemById("mode_group:radio:playlist_cycle").checked = \
            config.playerPlayOrderType == ORDER_TYPE_PLAYLIST_CYCLE

        self.menu.getItemById("proportion:radio:_p_default").checked = \
            self._proportion == "proportion:radio:_p_default"
        self.menu.getItemById("proportion:radio:_p_4_3").checked = \
            self._proportion == "proportion:radio:_p_4_3"
        self.menu.getItemById("proportion:radio:_p_16_9").checked = \
            self._proportion == "proportion:radio:_p_16_9"
        self.menu.getItemById("proportion:radio:_p_16_10").checked = \
            self._proportion == "proportion:radio:_p_16_10"
        self.menu.getItemById("proportion:radio:_p_1_85_1").checked = \
            self._proportion == "proportion:radio:_p_1_85_1"
        self.menu.getItemById("proportion:radio:_p_2_35_1").checked = \
            self._proportion == "proportion:radio:_p_2_35_1"

        self.menu.getItemById("scale:radio:_s_0_5").checked = \
            self._scale == "scale:radio:_s_0_5"
        self.menu.getItemById("scale:radio:_s_1").checked = \
            self._scale == "scale:radio:_s_1"
        self.menu.getItemById("scale:radio:_s_1_5").checked = \
            self._scale == "scale:radio:_s_1_5"
        self.menu.getItemById("scale:radio:_s_2").checked = \
            self._scale == "scale:radio:_s_2"

        # self.menu.getItemById("_sound_channel").isActive = hasVideo
        # self.menu.getItemById("_sound_channel").setSubMenu(
        #     Menu(sound_channel_sub_menu))
        # self.menu.getItemById("sound_channel:radio:auto").checked = \
        #     self._sound_channel == "sound_channel:radio:auto"
        # self.menu.getItemById("sound_channel:radio:mono").checked = \
        #     self._sound_channel == "sound_channel:radio:mono"
        # self.menu.getItemById("sound_channel:radio:left").checked = \
        #     self._sound_channel == "sound_channel:radio:left"
        # self.menu.getItemById("sound_channel:radio:right").checked = \
        #     self._sound_channel == "sound_channel:radio:right"
        # self.menu.getItemById("sound_channel:radio:stero").checked = \
        #     self._sound_channel == "sound_channel:radio:stero"
        self.menu.getItemById("_sound_muted").checked = config.playerMuted

        self.menu.getItemById("_subtitle_hide").checked = subtitleVisible
        subtitles = get_subtitle_from_movie(videoSource)
        subtitles = _subtitle_menu_items_from_files(subtitles, subtitleFile)
        self.menu.getItemById("_subtitle_choose").setSubMenu(Menu(subtitles))

        self.menu.getItemById("_fullscreen_quit").text = _("Fullscreen") if \
            isFullscreen else _("Exit fullscreen")
        self.menu.getItemById("_mini_mode").text = _("Exit mini mode") if \
            isMiniMode else _("Mini mode")

        self.menu.itemClicked.connect(self._menu_item_invoked)
        self.menu.showRectMenu(QCursor.pos().x(), QCursor.pos().y())
예제 #19
0
class MenuController(QObject):

    clockwiseRotate = pyqtSignal()
    antiClosewiseRotate = pyqtSignal()
    flipHorizontal = pyqtSignal()
    flipVertical = pyqtSignal()
    toggleFullscreen = pyqtSignal()
    toggleMiniMode = pyqtSignal()
    screenShot = pyqtSignal()
    scaleChanged = pyqtSignal(float,arguments=["scale"])
    proportionChanged = pyqtSignal(float,float,
        arguments=["propWidth", "propHeight"])
    openDialog = pyqtSignal(str)
    staysOnTop = pyqtSignal(bool,arguments=["onTop"])
    showPreference = pyqtSignal()
    showMovieInformation = pyqtSignal()
    openSubtitleFile = pyqtSignal()
    subtitleSelected = pyqtSignal(str,arguments=["subtitle"])
    playNext = pyqtSignal()
    playPrevious = pyqtSignal()
    playForward = pyqtSignal()
    playBackward = pyqtSignal()
    volumeUp = pyqtSignal()
    volumeDown = pyqtSignal()
    volumeMuted = pyqtSignal(bool, arguments=["muted"])
    soundChannelChanged = pyqtSignal(str, arguments=["channelLayout"])
    showSubtitleSettings = pyqtSignal()

    playlistPlay = pyqtSignal()
    addItemToPlaylist = pyqtSignal()
    addFolderToPlaylist = pyqtSignal()
    removeItemFromPlaylist = pyqtSignal()
    removeInvalidItemsFromPlaylist = pyqtSignal()
    playlistExport = pyqtSignal()
    playlistImport = pyqtSignal()
    playlistClear = pyqtSignal()
    playlistShowClickedItemInFM = pyqtSignal()
    playlistInformation = pyqtSignal()
    togglePlaylist = pyqtSignal()
    subtitleVisibleSet = pyqtSignal(bool, arguments=["visible"])

    def __init__(self):
        super(MenuController, self).__init__()

        self._proportion = "proportion:radio:_p_default"
        self._scale = "scale:radio:_s_1"
        self._sound_channel = "sound_channel:radio:auto"

    # if actions-like menu items are clicked, we should send signals to inform
    # the main controller that actions should be taken, if configs-like menu
    # items are clicked, we just change the configuration, config.py will takes
    # care of it for you .
    def _menu_item_invoked(self, _id, _checked):
        if _id == "_turn_right":
            self.clockwiseRotate.emit()
        elif _id == "_turn_left":
            self.antiClosewiseRotate.emit()
        elif _id == "_flip_horizontal":
            self.flipHorizontal.emit()
        elif _id == "_flip_vertial":
            self.flipVertical.emit()
        elif _id == "_fullscreen_quit":
            self.toggleFullscreen.emit()
        elif _id == "_screenshot":
            self.screenShot.emit()
        elif _id == "proportion:radio:_p_default":
            self._proportion = "proportion:radio:_p_default"
            self.proportionChanged.emit(1, 1)
        elif _id == "proportion:radio:_p_4_3":
            self._proportion = "proportion:radio:_p_4_3"
            self.proportionChanged.emit(4, 3)
        elif _id == "proportion:radio:_p_16_9":
            self._proportion = "proportion:radio:_p_16_9"
            self.proportionChanged.emit(16, 9)
        elif _id == "proportion:radio:_p_16_10":
            self._proportion = "proportion:radio:_p_16_10"
            self.proportionChanged.emit(16, 10)
        elif _id == "proportion:radio:_p_1_85_1":
            self._proportion = "proportion:radio:_p_1_85_1"
            self.proportionChanged.emit(1.85, 1)
        elif _id == "proportion:radio:_p_2_35_1":
            self._proportion = "proportion:radio:_p_2_35_1"
            self.proportionChanged.emit(2.35, 1)
        elif _id == "scale:radio:_s_0_5":
            self._scale = "scale:radio:_s_0_5"
            self.scaleChanged.emit(0.5)
        elif _id == "scale:radio:_s_1":
            self._scale = "scale:radio:_s_1"
            self.scaleChanged.emit(1)
        elif _id == "scale:radio:_s_1_5":
            self._scale = "scale:radio:_s_1_5"
            self.scaleChanged.emit(1.5)
        elif _id == "scale:radio:_s_2":
            self._scale = "scale:radio:_s_2"
            self.scaleChanged.emit(2)
        elif _id == "_open_file":
            self.openDialog.emit("file")
        elif _id == "_open_dir":
            self.openDialog.emit("dir")
        elif _id == "_open_url":
            self.openDialog.emit("url")
        elif _id == "_mini_mode":
            self.toggleMiniMode.emit()
        elif _id == "_on_top":
            self.staysOnTop.emit(_checked)
        elif _id == "_toggle_playlist":
            self.togglePlaylist.emit()
        elif _id == "mode_group:radio:in_order":
            config.playerPlayOrderType = ORDER_TYPE_IN_ORDER
        elif _id == "mode_group:radio:random":
            config.playerPlayOrderType = ORDER_TYPE_RANDOM
        elif _id == "mode_group:radio:single":
            config.playerPlayOrderType = ORDER_TYPE_SINGLE
        elif _id == "mode_group:radio:single_cycle":
            config.playerPlayOrderType = ORDER_TYPE_SINGLE_CYCLE
        elif _id == "mode_group:radio:playlist_cycle":
            config.playerPlayOrderType = ORDER_TYPE_PLAYLIST_CYCLE
        elif _id == "sound_channel:radio:auto":
            self._sound_channel = "sound_channel:radio:auto"
            self.soundChannelChanged.emit("auto")
        elif _id == "sound_channel:radio:mono":
            self._sound_channel = "sound_channel:radio:mono"
            self.soundChannelChanged.emit("mono")
        elif _id == "sound_channel:radio:left":
            self._sound_channel = "sound_channel:radio:left"
            self.soundChannelChanged.emit("left")
        elif _id == "sound_channel:radio:right":
            self._sound_channel = "sound_channel:radio:right"
            self.soundChannelChanged.emit("right")
        elif _id == "sound_channel:radio:stero":
            self._sound_channel = "sound_channel:radio:stero"
            self.soundChannelChanged.emit("stero")
        elif _id == "_subtitle_hide":
            self.subtitleVisibleSet.emit(not _checked)
        elif _id == "_subtitle_manual":
            self.openSubtitleFile.emit()
        elif _id.startswith("_subtitles:radio"):
            self.subtitleSelected.emit(_subtitle_file_from_menu_item_id(_id))
        elif _id == "_play_operation_forward":
            self.playForward.emit()
        elif _id == "_play_operation_backward":
            self.playBackward.emit()
        elif _id == "_play_operation_next":
            self.playNext.emit()
        elif _id == "_play_operation_previous":
            self.playPrevious.emit()
        elif _id == "_sound_increase":
            self.volumeUp.emit()
        elif _id == "_sound_decrease":
            self.volumeDown.emit()
        elif _id == "_sound_muted":
            self.volumeMuted.emit(_checked)
        elif _id == "_subtitle_settings":
            self.showSubtitleSettings.emit()
        elif _id == "_preferences":
            self.showPreference.emit()
        elif _id == "_information":
            self.showMovieInformation.emit()

        # playlist menu
        elif _id == "_playlist_play":
            self.playlistPlay.emit()
        elif _id == "_playlist_add_item":
            self.addItemToPlaylist.emit()
        elif _id == "_playlist_add_folder":
            self.addFolderToPlaylist.emit()
        elif _id == "_playlist_remove_item":
            self.removeItemFromPlaylist.emit()
        elif _id == "_playlist_remove_invalid":
            self.removeInvalidItemsFromPlaylist.emit()
        elif _id == "_playlist_clear":
            self.playlistClear.emit()
        elif _id == "_playlist_open_position":
            self.playlistShowClickedItemInFM.emit()
        elif _id == "_playlist_information":
            self.playlistInformation.emit()
        elif _id == "_playlist_export":
            self.playlistExport.emit()
        elif _id == "_playlist_import":
            self.playlistImport.emit()

    @pyqtSlot(str)
    def show_menu(self, stateInfo):
        info = json.loads(stateInfo)
        videoSource = info["videoSource"]
        hasVideo = info["hasVideo"]
        subtitleFile = info["subtitleFile"]
        subtitleVisible = info["subtitleVisible"]
        isFullscreen = info["isFullscreen"]
        isMiniMode = info["isMiniMode"]
        isOnTop = info["isOnTop"]

        self.menu = Menu(right_click_menu)

        self.menu.getItemById("_fullscreen_quit").isActive = hasVideo
        self.menu.getItemById("_mini_mode").isActive = hasVideo
        self.menu.getItemById("_play_operation_forward").isActive = hasVideo
        self.menu.getItemById("_play_operation_backward").isActive = hasVideo
        self.menu.getItemById("_frame").isActive = hasVideo and not isFullscreen
        self.menu.getItemById("_subtitle_hide").isActive = subtitleFile != ""
        self.menu.getItemById("_subtitle_manual").isActive = hasVideo
        self.menu.getItemById("_subtitle_choose").isActive = subtitleFile != ""
        self.menu.getItemById("_information").isActive = hasVideo

        self.menu.getItemById("_on_top").checked = isOnTop

        self.menu.getItemById("mode_group:radio:in_order").checked = \
            config.playerPlayOrderType == ORDER_TYPE_IN_ORDER
        self.menu.getItemById("mode_group:radio:random").checked = \
            config.playerPlayOrderType == ORDER_TYPE_RANDOM
        self.menu.getItemById("mode_group:radio:single").checked = \
            config.playerPlayOrderType == ORDER_TYPE_SINGLE
        self.menu.getItemById("mode_group:radio:single_cycle").checked = \
            config.playerPlayOrderType == ORDER_TYPE_SINGLE_CYCLE
        self.menu.getItemById("mode_group:radio:playlist_cycle").checked = \
            config.playerPlayOrderType == ORDER_TYPE_PLAYLIST_CYCLE

        self.menu.getItemById("proportion:radio:_p_default").checked = \
            self._proportion == "proportion:radio:_p_default"
        self.menu.getItemById("proportion:radio:_p_4_3").checked = \
            self._proportion == "proportion:radio:_p_4_3"
        self.menu.getItemById("proportion:radio:_p_16_9").checked = \
            self._proportion == "proportion:radio:_p_16_9"
        self.menu.getItemById("proportion:radio:_p_16_10").checked = \
            self._proportion == "proportion:radio:_p_16_10"
        self.menu.getItemById("proportion:radio:_p_1_85_1").checked = \
            self._proportion == "proportion:radio:_p_1_85_1"
        self.menu.getItemById("proportion:radio:_p_2_35_1").checked = \
            self._proportion == "proportion:radio:_p_2_35_1"

        self.menu.getItemById("scale:radio:_s_0_5").checked = \
            self._scale == "scale:radio:_s_0_5"
        self.menu.getItemById("scale:radio:_s_1").checked = \
            self._scale == "scale:radio:_s_1"
        self.menu.getItemById("scale:radio:_s_1_5").checked = \
            self._scale == "scale:radio:_s_1_5"
        self.menu.getItemById("scale:radio:_s_2").checked = \
            self._scale == "scale:radio:_s_2"

        # self.menu.getItemById("_sound_channel").isActive = hasVideo
        # self.menu.getItemById("_sound_channel").setSubMenu(
        #     Menu(sound_channel_sub_menu))
        # self.menu.getItemById("sound_channel:radio:auto").checked = \
        #     self._sound_channel == "sound_channel:radio:auto"
        # self.menu.getItemById("sound_channel:radio:mono").checked = \
        #     self._sound_channel == "sound_channel:radio:mono"
        # self.menu.getItemById("sound_channel:radio:left").checked = \
        #     self._sound_channel == "sound_channel:radio:left"
        # self.menu.getItemById("sound_channel:radio:right").checked = \
        #     self._sound_channel == "sound_channel:radio:right"
        # self.menu.getItemById("sound_channel:radio:stero").checked = \
        #     self._sound_channel == "sound_channel:radio:stero"
        self.menu.getItemById("_sound_muted").checked = config.playerMuted

        self.menu.getItemById("_subtitle_hide").checked = subtitleVisible
        subtitles = get_subtitle_from_movie(videoSource)
        subtitles = _subtitle_menu_items_from_files(subtitles, subtitleFile)
        self.menu.getItemById("_subtitle_choose").setSubMenu(Menu(subtitles))

        self.menu.getItemById("_fullscreen_quit").text = _("Fullscreen") if \
            isFullscreen else _("Exit fullscreen")
        self.menu.getItemById("_mini_mode").text = _("Exit mini mode") if \
            isMiniMode else _("Mini mode")

        self.menu.itemClicked.connect(self._menu_item_invoked)
        self.menu.showRectMenu(QCursor.pos().x(), QCursor.pos().y())

    @pyqtSlot(str, bool)
    def show_playlist_menu(self, url, playlistEmpty):
        self.menu = Menu(playlist_right_menu)
        self.menu.itemClicked.connect(self._menu_item_invoked)

        self.menu.getItemById("mode_group:radio:in_order").checked = \
            config.playerPlayOrderType == ORDER_TYPE_IN_ORDER
        self.menu.getItemById("mode_group:radio:random").checked = \
            config.playerPlayOrderType == ORDER_TYPE_RANDOM
        self.menu.getItemById("mode_group:radio:single").checked = \
            config.playerPlayOrderType == ORDER_TYPE_SINGLE
        self.menu.getItemById("mode_group:radio:single_cycle").checked = \
            config.playerPlayOrderType == ORDER_TYPE_SINGLE_CYCLE
        self.menu.getItemById("mode_group:radio:playlist_cycle").checked = \
            config.playerPlayOrderType == ORDER_TYPE_PLAYLIST_CYCLE

        self.menu.getItemById("_playlist_play").isActive = url != ""
        self.menu.getItemById("_playlist_remove_item").isActive = url != ""
        self.menu.getItemById("_playlist_open_position").isActive = url != "" \
            and utils.urlIsNativeFile(url)
        self.menu.getItemById("_playlist_information").isActive = url != "" \
            and utils.fileIsValidVideo(url)
        self.menu.getItemById("_playlist_clear").isActive = not playlistEmpty

        self.menu.showRectMenu(QCursor.pos().x(), QCursor.pos().y())

    @pyqtSlot()
    def show_mode_menu(self):
        self.menu = Menu(play_sequence_sub_menu)
        self.menu.itemClicked.connect(self._menu_item_invoked)

        self.menu.getItemById("mode_group:radio:in_order").checked = \
            config.playerPlayOrderType == ORDER_TYPE_IN_ORDER
        self.menu.getItemById("mode_group:radio:random").checked = \
            config.playerPlayOrderType == ORDER_TYPE_RANDOM
        self.menu.getItemById("mode_group:radio:single").checked = \
            config.playerPlayOrderType == ORDER_TYPE_SINGLE
        self.menu.getItemById("mode_group:radio:single_cycle").checked = \
            config.playerPlayOrderType == ORDER_TYPE_SINGLE_CYCLE
        self.menu.getItemById("mode_group:radio:playlist_cycle").checked = \
            config.playerPlayOrderType == ORDER_TYPE_PLAYLIST_CYCLE

        self.menu.showRectMenu(QCursor.pos().x(), QCursor.pos().y())

    @pyqtSlot()
    def show_add_button_menu(self):
        self.menu = Menu(playlist_add_button_menu)
        self.menu.itemClicked.connect(self._menu_item_invoked)

        self.menu.showRectMenu(QCursor.pos().x(), QCursor.pos().y())
예제 #20
0
    def show_add_button_menu(self):
        self.menu = Menu(playlist_add_button_menu)
        self.menu.itemClicked.connect(self._menu_item_invoked)

        self.menu.showRectMenu(QCursor.pos().x(), QCursor.pos().y())
예제 #21
0
class MenuController(QObject):
    toolSelected = pyqtSignal(str, arguments=["toolName"])
    saveSelected = pyqtSignal(int, arguments=["saveOption"])
    shareSelected = pyqtSignal()
    exitSelected = pyqtSignal()

    preMenuShow = pyqtSignal()
    postMenuHide = pyqtSignal()

    def __init__(self):
        super(MenuController, self).__init__()

    def _menu_unregistered(self):
        self.postMenuHide.emit()

    def _menu_item_invoked(self, _id, _checked):
        self.postMenuHide.emit()

        if _id == "_rectangle":
            self.toolSelected.emit("_rectangle")
        if _id == "_ellipse":
            self.toolSelected.emit("_ellipse")
        if _id == "_arrow":
            self.toolSelected.emit("_arrow")
        if _id == "_line":
            self.toolSelected.emit("_line")
        if _id == "_text":
            self.toolSelected.emit("_text")


        if _id == "save:radio:_op_save_to_desktop":
            self.saveSelected.emit(0)
        if _id == "save:radio:_op_auto_save":
            self.saveSelected.emit(1)
        if _id == "save:radio:_op_save_as":
            self.saveSelected.emit(2)
        if _id == "save:radio:_op_copy_to_clipboard":
            self.saveSelected.emit(3)
        if _id == "save:radio:_op_copy_and_save":
            self.saveSelected.emit(4)

        if _id == "_share":
            self.shareSelected.emit()
        if _id == "_exit":
            self.exitSelected.emit()

    @pyqtSlot(int)
    def show_menu(self, saveOption):
        self.preMenuShow.emit()

        self.menu = Menu(right_click_menu)
        self.menu.getItemById("_save").setSubMenu(Menu(save_sub_menu))

        self.menu.getItemById("save:radio:_op_save_to_desktop").checked = \
            saveOption == 0
        self.menu.getItemById("save:radio:_op_auto_save").checked = \
            saveOption == 1
        self.menu.getItemById("save:radio:_op_save_as").checked = \
            saveOption == 2
        self.menu.getItemById("save:radio:_op_copy_to_clipboard").checked = \
            saveOption == 3
        self.menu.getItemById("save:radio:_op_copy_and_save").checked = \
            saveOption == 4

        self.menu.itemClicked.connect(self._menu_item_invoked)
        self.menu.menuDismissed.connect(self._menu_unregistered)
        self.menu.showRectMenu(QCursor.pos().x(), QCursor.pos().y())
예제 #22
0
    def show_menu(self):
        self.menu = Menu(right_click_menu)

        hasVideo = movie_info.movie_file != ""
        self.menu.getItemById("_fullscreen_quit").isActive = hasVideo
        self.menu.getItemById("_mini_mode").isActive = hasVideo
        self.menu.getItemById("_play_operation_forward").isActive = hasVideo
        self.menu.getItemById("_play_operation_backward").isActive = hasVideo
        self.menu.getItemById("_frame").isActive = \
            hasVideo and self._window.getState() != Qt.WindowFullScreen
        self.menu.getItemById("_subtitle_hide").isActive = \
            hasVideo and bool(movie_info.subtitle_file)
        self.menu.getItemById("_subtitle_manual").isActive = hasVideo
        self.menu.getItemById("_subtitle_choose").isActive = \
            bool(movie_info.subtitle_file)
        self.menu.getItemById("_information").isActive = hasVideo \
            and movie_info.movie_duration != 0

        self.menu.getItemById("_on_top").checked = self._window.staysOnTop

        self.menu.getItemById("mode_group:radio:in_order").checked = \
            config.playerPlayOrderType == ORDER_TYPE_IN_ORDER
        self.menu.getItemById("mode_group:radio:random").checked = \
            config.playerPlayOrderType == ORDER_TYPE_RANDOM
        self.menu.getItemById("mode_group:radio:single").checked = \
            config.playerPlayOrderType == ORDER_TYPE_SINGLE
        self.menu.getItemById("mode_group:radio:single_cycle").checked = \
            config.playerPlayOrderType == ORDER_TYPE_SINGLE_CYCLE
        self.menu.getItemById("mode_group:radio:playlist_cycle").checked = \
            config.playerPlayOrderType == ORDER_TYPE_PLAYLIST_CYCLE

        self.menu.getItemById("proportion:radio:_p_default").checked = \
            self._proportion == "proportion:radio:_p_default"
        self.menu.getItemById("proportion:radio:_p_4_3").checked = \
            self._proportion == "proportion:radio:_p_4_3"
        self.menu.getItemById("proportion:radio:_p_16_9").checked = \
            self._proportion == "proportion:radio:_p_16_9"
        self.menu.getItemById("proportion:radio:_p_16_10").checked = \
            self._proportion == "proportion:radio:_p_16_10"
        self.menu.getItemById("proportion:radio:_p_1_85_1").checked = \
            self._proportion == "proportion:radio:_p_1_85_1"
        self.menu.getItemById("proportion:radio:_p_2_35_1").checked = \
            self._proportion == "proportion:radio:_p_2_35_1"

        self.menu.getItemById("scale:radio:_s_0_5").checked = \
            self._scale == "scale:radio:_s_0_5"
        self.menu.getItemById("scale:radio:_s_1").checked = \
            self._scale == "scale:radio:_s_1"
        self.menu.getItemById("scale:radio:_s_1_5").checked = \
            self._scale == "scale:radio:_s_1_5"
        self.menu.getItemById("scale:radio:_s_2").checked = \
            self._scale == "scale:radio:_s_2"

        self.menu.getItemById("_sound_muted").checked = config.playerMuted

        self.menu.getItemById("_subtitle_hide").checked = \
            not self._window.subtitleVisible
        subtitles = get_subtitle_from_movie(movie_info.movie_file)
        subtitles = _subtitle_menu_items_from_files(subtitles)
        self.menu.getItemById("_subtitle_choose").setSubMenu(Menu(subtitles))

        self.menu.getItemById("_fullscreen_quit").text = _("Fullscreen") if \
            self._window.getState() != Qt.WindowFullScreen else _("Exit fullscreen")
        self.menu.getItemById("_mini_mode").text = _("Exit mini mode") if \
            self._window.miniModeState() else _("Mini mode")

        self.menu.itemClicked.connect(self._menu_item_invoked)
        self.menu.showRectMenu(QCursor.pos().x(), QCursor.pos().y())
예제 #23
0
class MenuController(QObject):

    clockwiseRotate = pyqtSignal()
    antiClosewiseRotate = pyqtSignal()
    flipHorizontal = pyqtSignal()
    flipVertical = pyqtSignal()
    toggleFullscreen = pyqtSignal()
    toggleMiniMode = pyqtSignal()
    screenShot = pyqtSignal()
    scaleChanged = pyqtSignal(float,arguments=["scale"])
    proportionChanged = pyqtSignal(float,float,
        arguments=["propWidth", "propHeight"])
    openDialog = pyqtSignal(str)
    staysOnTop = pyqtSignal(bool,arguments=["onTop"])
    showPreference = pyqtSignal()
    showMovieInformation = pyqtSignal()
    openSubtitleFile = pyqtSignal()
    subtitleSelected = pyqtSignal(str,arguments=["subtitle"])
    playNext = pyqtSignal()
    playPrevious = pyqtSignal()
    playForward = pyqtSignal()
    playBackward = pyqtSignal()
    volumeUp = pyqtSignal()
    volumeDown = pyqtSignal()
    volumeMuted = pyqtSignal()
    showSubtitleSettings = pyqtSignal()

    playlistPlay = pyqtSignal()
    addItemToPlaylist = pyqtSignal()
    addFolderToPlaylist = pyqtSignal()
    removeItemFromPlaylist = pyqtSignal()
    removeInvalidItemsFromPlaylist = pyqtSignal()
    playlistExport = pyqtSignal()
    playlistImport = pyqtSignal()
    playlistClear = pyqtSignal()
    playlistShowClickedItemInFM = pyqtSignal()
    playlistInformation = pyqtSignal()
    togglePlaylist = pyqtSignal()

    def __init__(self, window):
        super(MenuController, self).__init__()
        self._window = window

        self._proportion = "proportion:radio:_p_default"
        self._scale = "scale:radio:_s_1"

    # if actions-like menu items are clicked, we should send signals to inform
    # the main controller that actions should be taken, if configs-like menu
    # items are clicked, we just change the configuration, config.py will takes
    # care of it for you .
    def _menu_item_invoked(self, _id, _checked):
        if _id == "_turn_right":
            self.clockwiseRotate.emit()
        elif _id == "_turn_left":
            self.antiClosewiseRotate.emit()
        elif _id == "_flip_horizontal":
            self.flipHorizontal.emit()
        elif _id == "_flip_vertial":
            self.flipVertical.emit()
        elif _id == "_fullscreen_quit":
            self.toggleFullscreen.emit()
        elif _id == "_screenshot":
            self.screenShot.emit()
        elif _id == "proportion:radio:_p_default":
            self._proportion = "proportion:radio:_p_default"
            self.proportionChanged.emit(1, 1)
        elif _id == "proportion:radio:_p_4_3":
            self._proportion = "proportion:radio:_p_4_3"
            self.proportionChanged.emit(4, 3)
        elif _id == "proportion:radio:_p_16_9":
            self._proportion = "proportion:radio:_p_16_9"
            self.proportionChanged.emit(16, 9)
        elif _id == "proportion:radio:_p_16_10":
            self._proportion = "proportion:radio:_p_16_10"
            self.proportionChanged.emit(16, 10)
        elif _id == "proportion:radio:_p_1_85_1":
            self._proportion = "proportion:radio:_p_1_85_1"
            self.proportionChanged.emit(1.85, 1)
        elif _id == "proportion:radio:_p_2_35_1":
            self._proportion = "proportion:radio:_p_2_35_1"
            self.proportionChanged.emit(2.35, 1)
        elif _id == "scale:radio:_s_0_5":
            self._scale = "scale:radio:_s_0_5"
            self.scaleChanged.emit(0.5)
        elif _id == "scale:radio:_s_1":
            self._scale = "scale:radio:_s_1"
            self.scaleChanged.emit(1)
        elif _id == "scale:radio:_s_1_5":
            self._scale = "scale:radio:_s_1_5"
            self.scaleChanged.emit(1.5)
        elif _id == "scale:radio:_s_2":
            self._scale = "scale:radio:_s_2"
            self.scaleChanged.emit(2)
        elif _id == "_open_file":
            self.openDialog.emit("file")
        elif _id == "_open_dir":
            self.openDialog.emit("dir")
        elif _id == "_open_url":
            self.openDialog.emit("url")
        elif _id == "_mini_mode":
            self.toggleMiniMode.emit()
        elif _id == "_on_top":
            self.staysOnTop.emit(_checked)
        elif _id == "_toggle_playlist":
        	self.togglePlaylist.emit()
        elif _id == "mode_group:radio:in_order":
            config.playerPlayOrderType = ORDER_TYPE_IN_ORDER
        elif _id == "mode_group:radio:random":
            config.playerPlayOrderType = ORDER_TYPE_RANDOM
        elif _id == "mode_group:radio:single":
            config.playerPlayOrderType = ORDER_TYPE_SINGLE
        elif _id == "mode_group:radio:single_cycle":
            config.playerPlayOrderType = ORDER_TYPE_SINGLE_CYCLE
        elif _id == "mode_group:radio:playlist_cycle":
            config.playerPlayOrderType = ORDER_TYPE_PLAYLIST_CYCLE
        elif _id == "_sound_muted":
            config.playerMuted = _checked
        elif _id == "_subtitle_hide":
            self._window.subtitleVisible = not _checked
        elif _id == "_subtitle_manual":
            self.openSubtitleFile.emit()
        elif _id.startswith("_subtitles:radio"):
            self.subtitleSelected.emit(_subtitle_file_from_menu_item_id(_id))
        elif _id == "_play_operation_forward":
            self.playForward.emit()
        elif _id == "_play_operation_backward":
            self.playBackward.emit()
        elif _id == "_play_operation_next":
            self.playNext.emit()
        elif _id == "_play_operation_previous":
            self.playPrevious.emit()
        elif _id == "_sound_increase":
            self.volumeUp.emit()
        elif _id == "_sound_decrease":
            self.volumeDown.emit()
        elif _id == "_sound_muted":
            self.volumeMuted.emit()
        elif _id == "_subtitle_settings":
            self.showSubtitleSettings.emit()
        elif _id == "_preferences":
            self.showPreference.emit()
        elif _id == "_information":
            self.showMovieInformation.emit()

        # playlist menu
        elif _id == "_playlist_play":
            self.playlistPlay.emit()
        elif _id == "_playlist_add_item":
            self.addItemToPlaylist.emit()
        elif _id == "_playlist_add_folder":
            self.addFolderToPlaylist.emit()
        elif _id == "_playlist_remove_item":
            self.removeItemFromPlaylist.emit()
        elif _id == "_playlist_remove_invalid":
            self.removeInvalidItemsFromPlaylist.emit()
        elif _id == "_playlist_clear":
            self.playlistClear.emit()
        elif _id == "_playlist_open_position":
            self.playlistShowClickedItemInFM.emit()
        elif _id == "_playlist_information":
            self.playlistInformation.emit()
        elif _id == "_playlist_export":
            self.playlistExport.emit()
        elif _id == "_playlist_import":
            self.playlistImport.emit()

    @pyqtSlot()
    def show_menu(self):
        self.menu = Menu(right_click_menu)

        hasVideo = movie_info.movie_file != ""
        self.menu.getItemById("_fullscreen_quit").isActive = hasVideo
        self.menu.getItemById("_mini_mode").isActive = hasVideo
        self.menu.getItemById("_play_operation_forward").isActive = hasVideo
        self.menu.getItemById("_play_operation_backward").isActive = hasVideo
        self.menu.getItemById("_frame").isActive = \
            hasVideo and self._window.getState() != Qt.WindowFullScreen
        self.menu.getItemById("_subtitle_hide").isActive = \
            hasVideo and bool(movie_info.subtitle_file)
        self.menu.getItemById("_subtitle_manual").isActive = hasVideo
        self.menu.getItemById("_subtitle_choose").isActive = \
            bool(movie_info.subtitle_file)
        self.menu.getItemById("_information").isActive = hasVideo \
            and movie_info.movie_duration != 0

        self.menu.getItemById("_on_top").checked = self._window.staysOnTop

        self.menu.getItemById("mode_group:radio:in_order").checked = \
            config.playerPlayOrderType == ORDER_TYPE_IN_ORDER
        self.menu.getItemById("mode_group:radio:random").checked = \
            config.playerPlayOrderType == ORDER_TYPE_RANDOM
        self.menu.getItemById("mode_group:radio:single").checked = \
            config.playerPlayOrderType == ORDER_TYPE_SINGLE
        self.menu.getItemById("mode_group:radio:single_cycle").checked = \
            config.playerPlayOrderType == ORDER_TYPE_SINGLE_CYCLE
        self.menu.getItemById("mode_group:radio:playlist_cycle").checked = \
            config.playerPlayOrderType == ORDER_TYPE_PLAYLIST_CYCLE

        self.menu.getItemById("proportion:radio:_p_default").checked = \
            self._proportion == "proportion:radio:_p_default"
        self.menu.getItemById("proportion:radio:_p_4_3").checked = \
            self._proportion == "proportion:radio:_p_4_3"
        self.menu.getItemById("proportion:radio:_p_16_9").checked = \
            self._proportion == "proportion:radio:_p_16_9"
        self.menu.getItemById("proportion:radio:_p_16_10").checked = \
            self._proportion == "proportion:radio:_p_16_10"
        self.menu.getItemById("proportion:radio:_p_1_85_1").checked = \
            self._proportion == "proportion:radio:_p_1_85_1"
        self.menu.getItemById("proportion:radio:_p_2_35_1").checked = \
            self._proportion == "proportion:radio:_p_2_35_1"

        self.menu.getItemById("scale:radio:_s_0_5").checked = \
            self._scale == "scale:radio:_s_0_5"
        self.menu.getItemById("scale:radio:_s_1").checked = \
            self._scale == "scale:radio:_s_1"
        self.menu.getItemById("scale:radio:_s_1_5").checked = \
            self._scale == "scale:radio:_s_1_5"
        self.menu.getItemById("scale:radio:_s_2").checked = \
            self._scale == "scale:radio:_s_2"

        self.menu.getItemById("_sound_muted").checked = config.playerMuted

        self.menu.getItemById("_subtitle_hide").checked = \
            not self._window.subtitleVisible
        subtitles = get_subtitle_from_movie(movie_info.movie_file)
        subtitles = _subtitle_menu_items_from_files(subtitles)
        self.menu.getItemById("_subtitle_choose").setSubMenu(Menu(subtitles))

        self.menu.getItemById("_fullscreen_quit").text = _("Fullscreen") if \
            self._window.getState() != Qt.WindowFullScreen else _("Exit fullscreen")
        self.menu.getItemById("_mini_mode").text = _("Exit mini mode") if \
            self._window.miniModeState() else _("Mini mode")

        self.menu.itemClicked.connect(self._menu_item_invoked)
        self.menu.showRectMenu(QCursor.pos().x(), QCursor.pos().y())

    @pyqtSlot(bool,str)
    def show_playlist_menu(self, isGroup, url):
        self.menu = Menu(playlist_right_menu)
        self.menu.itemClicked.connect(self._menu_item_invoked)

        self.menu.getItemById("mode_group:radio:in_order").checked = \
            config.playerPlayOrderType == ORDER_TYPE_IN_ORDER
        self.menu.getItemById("mode_group:radio:random").checked = \
            config.playerPlayOrderType == ORDER_TYPE_RANDOM
        self.menu.getItemById("mode_group:radio:single").checked = \
            config.playerPlayOrderType == ORDER_TYPE_SINGLE
        self.menu.getItemById("mode_group:radio:single_cycle").checked = \
            config.playerPlayOrderType == ORDER_TYPE_SINGLE_CYCLE
        self.menu.getItemById("mode_group:radio:playlist_cycle").checked = \
            config.playerPlayOrderType == ORDER_TYPE_PLAYLIST_CYCLE

        self.menu.getItemById("_playlist_play").isActive = url != ""
        self.menu.getItemById("_playlist_remove_item").isActive = \
            isGroup or url != ""
        self.menu.getItemById("_playlist_open_position").isActive = url != "" \
            and utils.urlIsNativeFile(url)
        self.menu.getItemById("_playlist_information").isActive = url != "" \
            and utils.fileIsValidVideo(url)

        self.menu.showRectMenu(QCursor.pos().x(), QCursor.pos().y())

    @pyqtSlot()
    def show_mode_menu(self):
        self.menu = Menu(play_sequence_sub_menu)
        self.menu.itemClicked.connect(self._menu_item_invoked)

        self.menu.getItemById("mode_group:radio:in_order").checked = \
            config.playerPlayOrderType == ORDER_TYPE_IN_ORDER
        self.menu.getItemById("mode_group:radio:random").checked = \
            config.playerPlayOrderType == ORDER_TYPE_RANDOM
        self.menu.getItemById("mode_group:radio:single").checked = \
            config.playerPlayOrderType == ORDER_TYPE_SINGLE
        self.menu.getItemById("mode_group:radio:single_cycle").checked = \
            config.playerPlayOrderType == ORDER_TYPE_SINGLE_CYCLE
        self.menu.getItemById("mode_group:radio:playlist_cycle").checked = \
            config.playerPlayOrderType == ORDER_TYPE_PLAYLIST_CYCLE

        self.menu.showRectMenu(QCursor.pos().x(), QCursor.pos().y())

    @pyqtSlot()
    def show_add_button_menu(self):
        self.menu = Menu(playlist_add_button_menu)
        self.menu.itemClicked.connect(self._menu_item_invoked)

        self.menu.showRectMenu(QCursor.pos().x(), QCursor.pos().y())
예제 #24
0
    def show_menu(self, stateInfo):
        info = json.loads(stateInfo)
        videoSource = info["videoSource"]
        hasVideo = info["hasVideo"]
        subtitleFile = info["subtitleFile"]
        subtitleVisible = info["subtitleVisible"]
        isFullscreen = info["isFullscreen"]
        isMiniMode = info["isMiniMode"]
        isOnTop = info["isOnTop"]

        self.menu = Menu(right_click_menu)

        self.menu.getItemById("_fullscreen_quit").isActive = hasVideo
        self.menu.getItemById("_mini_mode").isActive = hasVideo
        self.menu.getItemById("_play_operation_forward").isActive = hasVideo
        self.menu.getItemById("_play_operation_backward").isActive = hasVideo
        self.menu.getItemById(
            "_frame").isActive = hasVideo and not isFullscreen
        self.menu.getItemById("_subtitle_hide").isActive = subtitleFile != ""
        self.menu.getItemById("_subtitle_manual").isActive = hasVideo
        self.menu.getItemById("_information").isActive = hasVideo

        self.menu.getItemById("_on_top").checked = isOnTop

        self.menu.getItemById("mode_group:radio:in_order").checked = \
            config.playerPlayOrderType == ORDER_TYPE_IN_ORDER
        self.menu.getItemById("mode_group:radio:random").checked = \
            config.playerPlayOrderType == ORDER_TYPE_RANDOM
        self.menu.getItemById("mode_group:radio:single").checked = \
            config.playerPlayOrderType == ORDER_TYPE_SINGLE
        self.menu.getItemById("mode_group:radio:single_cycle").checked = \
            config.playerPlayOrderType == ORDER_TYPE_SINGLE_CYCLE
        self.menu.getItemById("mode_group:radio:playlist_cycle").checked = \
            config.playerPlayOrderType == ORDER_TYPE_PLAYLIST_CYCLE

        self.menu.getItemById("proportion:radio:_p_default").checked = \
            self._proportion == "proportion:radio:_p_default"
        self.menu.getItemById("proportion:radio:_p_4_3").checked = \
            self._proportion == "proportion:radio:_p_4_3"
        self.menu.getItemById("proportion:radio:_p_16_9").checked = \
            self._proportion == "proportion:radio:_p_16_9"
        self.menu.getItemById("proportion:radio:_p_16_10").checked = \
            self._proportion == "proportion:radio:_p_16_10"
        self.menu.getItemById("proportion:radio:_p_1_85_1").checked = \
            self._proportion == "proportion:radio:_p_1_85_1"
        self.menu.getItemById("proportion:radio:_p_2_35_1").checked = \
            self._proportion == "proportion:radio:_p_2_35_1"

        self.menu.getItemById("scale:radio:_s_0_5").checked = \
            self._scale == "scale:radio:_s_0_5"
        self.menu.getItemById("scale:radio:_s_1").checked = \
            self._scale == "scale:radio:_s_1"
        self.menu.getItemById("scale:radio:_s_1_5").checked = \
            self._scale == "scale:radio:_s_1_5"
        self.menu.getItemById("scale:radio:_s_2").checked = \
            self._scale == "scale:radio:_s_2"

        # self.menu.getItemById("_sound_channel").isActive = hasVideo
        # self.menu.getItemById("_sound_channel").setSubMenu(
        #     Menu(sound_channel_sub_menu))
        # self.menu.getItemById("sound_channel:radio:auto").checked = \
        #     self._sound_channel == "sound_channel:radio:auto"
        # self.menu.getItemById("sound_channel:radio:mono").checked = \
        #     self._sound_channel == "sound_channel:radio:mono"
        # self.menu.getItemById("sound_channel:radio:left").checked = \
        #     self._sound_channel == "sound_channel:radio:left"
        # self.menu.getItemById("sound_channel:radio:right").checked = \
        #     self._sound_channel == "sound_channel:radio:right"
        # self.menu.getItemById("sound_channel:radio:stero").checked = \
        #     self._sound_channel == "sound_channel:radio:stero"
        self.menu.getItemById("_sound_muted").checked = bool(
            config.playerMuted)

        self.menu.getItemById("_subtitle_hide").checked = not subtitleVisible
        subtitles = get_subtitle_from_movie(videoSource)
        subtitles = _subtitle_menu_items_from_files(subtitles, subtitleFile, \
            videoSource)
        self.menu.getItemById("_subtitle_choose").isActive = \
            len(subtitles) != 0
        self.menu.getItemById("_subtitle_choose").setSubMenu(Menu(subtitles))

        self.menu.getItemById("_fullscreen_quit").text = _("Exit fullscreen") if \
            isFullscreen else _("Fullscreen")
        self.menu.getItemById("_mini_mode").text = _("Exit mini mode") if \
            isMiniMode else _("Mini mode")

        self.menu.itemClicked.connect(self._menu_item_invoked)
        self.menu.showRectMenu(QCursor.pos().x(), QCursor.pos().y())
예제 #25
0
class SystemTrayIcon(QSystemTrayIcon):

    showSettingView = pyqtSignal()

    def __init__(self, icon, parent=None):
        QSystemTrayIcon.__init__(self, icon, parent)
        self.activated.connect(self.on_activated)

    @pyqtSlot(str, bool)
    def click_menu(self, menu_id, state):
        if menu_id == "quit":
            qApp.quit()
        elif menu_id == "wizard":
            pass
        elif menu_id == "about":
            pass
        elif menu_id == "settings":
            self.showSettingView.emit()
        else:
            if menu_id == "pause":
                if not state:
                    delete_selection()

                self.set_menu_active(state)

            setting_config.update_trayicon_config(menu_id, state)

    def set_menu_active(self, state):
        self.menu.setItemActivity("toggle_speech", not state)
        self.menu.setItemActivity("key_trigger_ocr", not state)
        self.menu.setItemActivity("key_trigger_select", not state)

    def on_activated(self, reason):
        if reason in [QSystemTrayIcon.Context, QSystemTrayIcon.Trigger]:
            geometry = self.geometry()
            mouse_x = int(geometry.x() / 2 + geometry.width() / 2)
            mouse_y = int(geometry.y() / 2)

            self.menu = Menu([
                CheckboxMenuItem("pause", "暂停翻译",
                                 setting_config.get_trayicon_config("pause")),
                CheckboxMenuItem(
                    "toggle_speech", "取词后发音",
                    setting_config.get_trayicon_config("toggle_speech")),
                CheckboxMenuItem(
                    "key_trigger_ocr", "按Ctrl键屏幕取词",
                    setting_config.get_trayicon_config("key_trigger_ocr")),
                CheckboxMenuItem(
                    "key_trigger_select", "按Shift键翻译选区",
                    setting_config.get_trayicon_config("key_trigger_select")),
                MenuSeparator(),
                ("settings", "设置"),
                ("wizard", "向导"),
                ("about", "关于"),
                MenuSeparator(),
                ("quit", "退出"),
            ])
            self.menu.itemClicked.connect(self.click_menu)
            self.menu.showDockMenu(mouse_x, mouse_y)
            self.set_menu_active(setting_config.get_trayicon_config("pause"))

    def get_trayarea(self):
        geometry = self.geometry()
        return (geometry.y() / 2, geometry.y() / 2 + geometry.height())
예제 #26
0
class SystemTrayIcon(QSystemTrayIcon):

    showSettingView = pyqtSignal()

    def __init__(self, parent=None):
        QSystemTrayIcon.__init__(self, self.get_trayicon(), parent)
        self.activated.connect(self.on_activated)

        self.menu_is_visible = False

    def set_trayicon(self):
        self.setIcon(self.get_trayicon())

    def get_trayicon(self):
        if is_true(setting_config.get_trayicon_config("pause")):
            icon_name = "pause_trayicon.png"
        else:
            icon_name = "trayicon.png"

        return QIcon(os.path.join(get_parent_dir(__file__), "image",
                                  icon_name))

    @pyqtSlot(str, bool)
    def click_menu(self, menu_id, state):
        if menu_id == "quit":
            qApp.quit()
        elif menu_id == "wizard":
            pass
        elif menu_id == "about":
            pass
        elif menu_id == "settings":
            self.showSettingView.emit()
        elif menu_id == "lang":
            src_lang = setting_config.get_translate_config("src_lang")
            dst_lang = setting_config.get_translate_config("dst_lang")
            setting_config.update_translate_config("src_lang", dst_lang)
            setting_config.update_translate_config("dst_lang", src_lang)

            self.menu.setItemText("lang", self.get_lang_value())

            setting_view.updateLang.emit()
        else:
            if menu_id == "pause":
                if not state:
                    delete_selection()

                self.set_menu_active(state)

            setting_config.update_trayicon_config(menu_id, state)

            self.set_trayicon()

    def set_menu_active(self, state):
        self.menu.setItemActivity("toggle_speech", not state)
        self.menu.setItemActivity("key_trigger_select", not state)
        self.menu.setItemActivity("local_translate", not state)

    def get_lang_value(self):
        return (dict(LANGUAGES))[setting_config.get_translate_config(
            "src_lang")] + " <=> " + (dict(LANGUAGES))[
                setting_config.get_translate_config("dst_lang")]

    def on_activated(self, reason):
        if not self.menu_is_visible:
            if reason in [QSystemTrayIcon.Context, QSystemTrayIcon.Trigger]:
                geometry = self.geometry()
                if QT_VERSION == "5.1":
                    mouse_x = int(geometry.x() / 2 + geometry.width() / 2)
                    mouse_y = int(geometry.y() / 2)
                else:
                    mouse_x = int(geometry.x() + geometry.width() / 2)
                    mouse_y = int(geometry.y())

                self.menu = Menu([
                    CheckableMenuItem(
                        "pause", _("Pause translation"),
                        setting_config.get_trayicon_config("pause")),
                    CheckableMenuItem(
                        "toggle_speech", _("Pronounce automatically"),
                        setting_config.get_trayicon_config("toggle_speech")),
                    CheckableMenuItem(
                        "key_trigger_select",
                        _("Translate only when holding Ctrl key"),
                        setting_config.get_trayicon_config(
                            "key_trigger_select")),
                    CheckableMenuItem(
                        "local_translate", _("Offline translation"),
                        setting_config.get_trayicon_config("local_translate")),
                    MenuSeparator(),
                    CheckableMenuItem("lang",
                                      self.get_lang_value(),
                                      showCheckmark=False),
                    MenuSeparator(),
                    ("settings", _("Settings")),
                    # ("wizard", _("Wizard")),
                    MenuSeparator(),
                    ("quit", _("Exit")),
                ])

                self.menu.itemClicked.connect(self.click_menu)
                self.menu.menuDismissed.connect(self.exit_menu)
                self.set_menu_active(
                    setting_config.get_trayicon_config("pause"))
                if mouse_y > screen_height / 2:
                    self.menu.showDockMenu(mouse_x,
                                           mouse_y,
                                           cornerDirection="down")
                else:
                    self.menu.showDockMenu(mouse_x,
                                           mouse_y + geometry.height(),
                                           cornerDirection="up")

        self.menu_is_visible = not self.menu_is_visible

    @pyqtSlot()
    def exit_menu(self):
        self.menu_is_visible = False

    def get_trayarea(self):
        geometry = self.geometry()
        return (geometry.y() / 2, geometry.y() / 2 + geometry.height())
예제 #27
0
class MenuController(QObject):
    toolSelected = pyqtSignal(str, arguments=["toolName"])
    saveSelected = pyqtSignal(int, arguments=["saveOption"])
    shareSelected = pyqtSignal()
    exitSelected = pyqtSignal()

    preMenuShow = pyqtSignal()
    postMenuHide = pyqtSignal()

    def __init__(self):
        super(MenuController, self).__init__()

    def _menu_unregistered(self):
        self.postMenuHide.emit()

    def _menu_item_invoked(self, _id, _checked):
        self.postMenuHide.emit()

        if _id == "_rectangle":
            self.toolSelected.emit("_rectangle")
        if _id == "_ellipse":
            self.toolSelected.emit("_ellipse")
        if _id == "_arrow":
            self.toolSelected.emit("_arrow")
        if _id == "_line":
            self.toolSelected.emit("_line")
        if _id == "_text":
            self.toolSelected.emit("_text")

        if _id == "save:radio:_op_auto_save":
            self.saveSelected.emit(1)
        if _id == "save:radio:_op_save_to_desktop":
            self.saveSelected.emit(0)
        if _id == "save:radio:_op_copy_to_clipboard":
            self.saveSelected.emit(4)
        if _id == "save:radio:_op_save_as":
            self.saveSelected.emit(2)
        if _id == "save:radio:_op_copy_and_save":
            self.saveSelected.emit(3)

        if _id == "_share":
            self.shareSelected.emit()
        if _id == "_exit":
            self.exitSelected.emit()

    @pyqtSlot(int)
    def show_menu(self, saveOption):
        self.preMenuShow.emit()

        self.menu = Menu(right_click_menu)
        self.menu.getItemById("_save").setSubMenu(Menu(save_sub_menu))

        self.menu.getItemById("save:radio:_op_auto_save").checked = \
            saveOption == 1
        self.menu.getItemById("save:radio:_op_save_to_desktop").checked = \
            saveOption == 0
        self.menu.getItemById("save:radio:_op_copy_to_clipboard").checked = \
            saveOption == 4
        self.menu.getItemById("save:radio:_op_save_as").checked = \
            saveOption == 2
        self.menu.getItemById("save:radio:_op_copy_and_save").checked = \
            saveOption == 3

        self.menu.itemClicked.connect(self._menu_item_invoked)
        self.menu.menuDismissed.connect(self._menu_unregistered)
        self.menu.showRectMenu(QCursor.pos().x(), QCursor.pos().y())