Example #1
0
    def __initContextMenu(self):
        self._contextMenu = QMenu(self)
        self.setContextMenuPolicy(Qt.CustomContextMenu)
        af = ActionFactory(self)

        insertSub = af.create(title = _("&Insert subtitle"), icon = "list-add",
            connection = self.insertNewSubtitle)
        self._contextMenu.addAction(insertSub)

        insertSub = af.create(title = _("&Add subtitle"), icon = "list-add",
            connection = self.addNewSubtitle)
        self._contextMenu.addAction(insertSub)

        removeSub = af.create(title = _("&Remove subtitles"), icon = "list-remove",
            connection = self.removeSelectedSubtitles)
        self._contextMenu.addAction(removeSub)
Example #2
0
    def __initActions(self):
        self._actions = {}
        af = ActionFactory(self)

        # open / save
        self._actions["openFile"] = af.create(
            "document-open", _("&Open"), _("Open subtitle file."), "ctrl+o", self.openFile)
        self._actions["saveFile"] = af.create(
            "document-save", _("&Save"), _("Save current file."), "ctrl+s", self.saveFile)
        self._actions["saveFileAs"] = af.create(
            "document-save-as",_("S&ave as..."), _("Save current file as..."), "ctrl++shift+s",
            self.saveFileAs)
        self._actions["saveAllFiles"] = af.create(
            "document-save", _("Sa&ve all"), _("Save all opened files."), None, self.saveAll)

        # app exit
        self._actions["exit"] = af.create(
            "application-exit", _("&Exit"), _("Exit Subconvert."), None, qApp.quit)

        # tab management
        self._actions["nextTab"] = af.create(
            None, None, None, "ctrl+tab", self.nextTab)
        self._actions["previousTab"] = af.create(
            None, None, None, "ctrl+shift+tab", self.previousTab)
        self._actions["closeTab"] = af.create(
            None, None, None, "ctrl+w", self.closeTab)

        # Subtitles
        self._actions["undo"] = af.create(
            "undo", _("&Undo"), None, "ctrl+z", self.undo)
        self._actions["redo"] = af.create(
            "redo", _("&Redo"), None, "ctrl+shift+z", self.redo)

        for fps in FPS_VALUES:
            fpsStr = str(fps)
            self._actions[fpsStr] = af.create(
                None, fpsStr, None, None, lambda _, fps=fps: self.changeFps(fps))

        for encoding in ALL_ENCODINGS:
            self._actions["in_%s" % encoding] = af.create(
                None, encoding, None, None,
                lambda _, enc = encoding: self.changeInputEncoding(enc))

            self._actions["out_%s" % encoding] = af.create(
                None, encoding, None, None,
                lambda _, enc = encoding: self.changeOutputEncoding(enc))

        for fmt in self._subtitleData.supportedFormats:
            self._actions[fmt.NAME] = af.create(
                None, fmt.NAME, None, None, lambda _, fmt = fmt: self.changeSubFormat(fmt))

        self._actions["linkVideo"] = af.create(
            None, _("&Link video"), None, "ctrl+l", self.linkVideo)

        self._actions["unlinkVideo"] = af.create(
            None, _("U&nlink video"), None, "ctrl+u", lambda: self._setVideoLink(None))

        self._actions["fpsFromMovie"] = af.create(
            None, _("&Get FPS"), None, "ctrl+g", self.getFpsFromMovie)

        self._actions["insertSub"] = af.create(
            "list-add", _("&Insert subtitle"), None, "insert",
            connection = lambda: self._tabs.currentPage().insertNewSubtitle())

        self._actions["addSub"] = af.create(
            "list-add", _("&Add subtitle"), None, "alt+insert",
            connection = lambda: self._tabs.currentPage().addNewSubtitle())

        self._actions["offset"] = af.create(
            None, _("&Offset"), None, None, self.offset)

        self._actions["removeSub"] = af.create(
            "list-remove", _("&Remove subtitles"), None, "delete",
            connection = lambda: self._tabs.currentPage().removeSelectedSubtitles())

        self._actions["findSub"] = af.create(
            "edit-find", _("&Find..."), None, "ctrl+f",
            connection = lambda: self._tabs.currentPage().highlight())

        # Video
        self._videoRatios = [(4, 3), (14, 9), (14, 10), (16, 9), (16, 10)]
        self._actions["openVideo"] = af.create(
            "document-open", _("&Open video"), None, "ctrl+m", self.openVideo)
        self._actions["togglePlayback"] = af.create(
            "media-playback-start", _("&Play/pause"), _("Toggle video playback"), "space",
            self._videoWidget.togglePlayback)
        self._actions["forward"] = af.create(
            "media-skip-forward", _("&Forward"), None, "ctrl+right", self._videoWidget.forward)
        self._actions["rewind"] = af.create(
            "media-skip-backward", _("&Rewind"), None, "ctrl+left", self._videoWidget.rewind)
        self._actions["frameStep"] = af.create(
            None, _("Next &frame"), _("Go to the next frame in a video"), ".",
            self._videoWidget.nextFrame)

        for ratio in self._videoRatios:
            self._actions["changeRatio_%d_%d" % ratio] = af.create(
                None, "%d:%d" % ratio, None, None,
                lambda _, r=ratio: self._videoWidget.changePlayerAspectRatio(r[0], r[1]))

        self._actions["changeRatio_fill"] = af.create(
            None, _("Fill"), None, None, self._videoWidget.fillPlayer)

        self._actions["videoJump"] = af.create(
            None, _("&Jump to subtitle"), None, "ctrl+j", self.jumpToSelectedSubtitle)

        # SPF editor
        self._actions["spfEditor"] = af.create(
            "accessories-text-editor", _("Subtitle &Properties Editor"), None, None, self.openPropertyEditor)

        # View
        self._actions["togglePlayer"] = af.create(
            None, _("&Video player"), _("Show or hide video player"), "F3", self.togglePlayer)
        self._actions["togglePanel"] = af.create(
            None, _("Side &panel"), _("Show or hide left panel"), "F4", self._tabs.togglePanel)

        # Help
        self._actions["helpPage"] = af.create(
            "help-contents", _("&Help"), _("Open &help page"), "F1", self.openHelp)
        self._actions["aboutSubconvert"] = af.create(
            "help-about", _("&About Subconvert"), None, None, self.openAboutDialog)
Example #3
0
    def __initContextMenu(self):
        if self._contextMenu is not None:
            self._contextMenu.deleteLater()
            self._contextMenu = None

        self._contextMenu = QMenu()
        af = ActionFactory(self)

        selectedItems = self.__fileList.selectedItems()
        anyItemSelected = len(selectedItems) > 0

        # Open in tab

        actionOpenInTab = af.create(
            icon = "window-new", title = _("&Open in tab"), connection = self.requestOpeningSelectedFiles)
        actionOpenInTab.setEnabled(anyItemSelected)
        self._contextMenu.addAction(actionOpenInTab)

        self._contextMenu.addSeparator()

        # Property Files

        pfileMenu = self._contextMenu.addMenu(_("Use Subtitle &Properties"))
        pfileMenu.setEnabled(anyItemSelected)
        for pfile in self._settings.getLatestPropertyFiles():
            # A hacky way to store pfile in lambda
            action = af.create(
                title = pfile,
                connection = lambda _, pfile=pfile: self._useSubProperties(pfile)
            )
            pfileMenu.addAction(action)
        pfileMenu.addSeparator()
        pfileMenu.addAction(af.create(
            title = _("Open file"), connection = self._chooseSubProperties))

        self._contextMenu.addSeparator()

        # Single properties

        fpsMenu = self._contextMenu.addMenu(_("&Frames per second"))
        fpsMenu.setEnabled(anyItemSelected)
        for fps in FPS_VALUES:
            fpsStr = str(fps)
            action = af.create(
                title = fpsStr,
                connection = lambda _, fps=fps: self.changeSelectedFilesFps(fps))
            fpsMenu.addAction(action)

        formatsMenu = self._contextMenu.addMenu(_("Subtitles forma&t"))
        formatsMenu.setEnabled(anyItemSelected)
        for fmt in self._subtitleData.supportedFormats:
            action = af.create(
                title = fmt.NAME,
                connection = lambda _, fmt=fmt: self.changeSelectedFilesFormat(fmt)
            )
            formatsMenu.addAction(action)

        inputEncodingsMenu = self._contextMenu.addMenu(_("Input &encoding"))
        inputEncodingsMenu.setEnabled(anyItemSelected)
        outputEncodingsMenu = self._contextMenu.addMenu(_("&Output encoding"))
        outputEncodingsMenu.setEnabled(anyItemSelected)
        for encoding in ALL_ENCODINGS:
            outAction = af.create(
                title = encoding,
                connection = lambda _, enc=encoding: self.changeSelectedFilesOutputEncoding(enc)
            )
            outputEncodingsMenu.addAction(outAction)

            inAction = af.create(
                title = encoding,
                connection = lambda _, enc=encoding: self.changeSelectedFilesInputEncoding(enc)
            )
            inputEncodingsMenu.addAction(inAction)

        offset = af.create(None, _("&Offset"), None, None, self._offsetDialog)
        offset.setEnabled(anyItemSelected)
        self._contextMenu.addAction(offset)

        self._contextMenu.addSeparator()

        # Link/unlink video
        actionLink = af.create(None, _("&Link video"), None, None, self.linkVideo)
        actionLink.setEnabled(anyItemSelected)
        self._contextMenu.addAction(actionLink)

        actionLink = af.create(
            None, _("U&nlink video"), None, None, lambda: self.changeSelectedFilesVideoPath(None))
        actionLink.setEnabled(anyItemSelected)
        self._contextMenu.addAction(actionLink)

        actionLink = af.create(None, _("&Get FPS"), None, None, self.detectSelectedFilesFps)
        actionLink.setEnabled(anyItemSelected)
        self._contextMenu.addAction(actionLink)

        self._contextMenu.addSeparator()


        # Show/Remove files

        # Key shortcuts are actually only a hack to provide some kind of info to user that he can
        # use "enter/return" and "delete" to open/close subtitles. Keyboard is handled via
        # keyPressed -> _handleKeyPress. This is because __fileList has focus most of time anyway
        # (I think...)
        actionOpen = af.create(
            None, _("&Show subtitles"), None, "Enter", lambda: self._handleKeyPress(Qt.Key_Enter))
        actionOpen.setEnabled(anyItemSelected)
        self._contextMenu.addAction(actionOpen)

        actionClose = af.create(
            None, _("&Close subtitles"), None, "Delete", lambda: self._handleKeyPress(Qt.Key_Delete))
        actionClose.setEnabled(anyItemSelected)
        self._contextMenu.addAction(actionClose)

        self._contextMenu.addSeparator()

        # Undo/redo

        actionUndo = af.create("undo", _("&Undo"), None, None, self.undoSelectedFiles)
        actionUndo.setEnabled(anyItemSelected)
        self._contextMenu.addAction(actionUndo)

        actionRedo = af.create("redo", _("&Redo"), None, None, self.redoSelectedFiles)
        actionRedo.setEnabled(anyItemSelected)
        self._contextMenu.addAction(actionRedo)