Ejemplo n.º 1
0
    def createToolbar(self, MainWindow):
        # toolbar
        self.toolBar = QtWidgets.QToolBar(MainWindow)
        MainWindow.addToolBar(QtCore.Qt.TopToolBarArea, self.toolBar)
        # play
        self.actionPlay = QtWidgets.QAction(MainWindow)
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap(os.path.join(ICONS, "play.svg")),
                       QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.actionPlay.setIcon(icon)
        # pause
        self.actionPause = QtWidgets.QAction(MainWindow)
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap(os.path.join(ICONS, "pause.svg")),
                       QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.actionPause.setIcon(icon)
        # stop
        self.actionStop = QtWidgets.QAction(MainWindow)
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap(os.path.join(ICONS, "stop.svg")),
                       QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.actionStop.setIcon(icon)
        # prvious sentence
        self.actionPrevSent = QtWidgets.QAction(MainWindow)
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap(os.path.join(ICONS, "first.svg")),
                       QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.actionPrevSent.setIcon(icon)
        self.actionPrevSent.triggered.connect(
            lambda _: self.player.playRelativeBead(-1))
        # next sentence
        self.actionNextSent = QtWidgets.QAction(MainWindow)
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap(os.path.join(ICONS, "last.svg")),
                       QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.actionNextSent.setIcon(icon)
        self.actionNextSent.triggered.connect(
            lambda _: self.player.playRelativeBead(1))
        # previous chapter
        self.actionPrevChapter = QtWidgets.QAction(MainWindow)
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap(os.path.join(ICONS, "skip_prev.svg")),
                       QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.actionPrevChapter.setIcon(icon)
        # next chapter
        self.actionNextChapter = QtWidgets.QAction(MainWindow)
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap(os.path.join(ICONS, "skip_next.svg")),
                       QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.actionNextChapter.setIcon(icon)
        # quit
        self.actionQuit = QtWidgets.QAction(MainWindow)
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap(os.path.join(ICONS, "exit.svg")),
                       QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.actionQuit.setIcon(icon)
        # add
        self.actionAdd = QtWidgets.QAction(MainWindow)
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap(os.path.join(ICONS, "add.svg")),
                       QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.actionAdd.setIcon(icon)
        # remove
        self.actionRemove = QtWidgets.QAction(MainWindow)
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap(os.path.join(ICONS, "remove.svg")),
                       QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.actionRemove.setIcon(icon)
        # download
        self.actionDownload = QtWidgets.QAction(MainWindow)
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap(os.path.join(ICONS, "download.svg")),
                       QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.actionDownload.setIcon(icon)
        # settings
        self.actionSettings = QtWidgets.QAction(MainWindow)
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap(os.path.join(ICONS, "settings.svg")),
                       QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.actionSettings.setIcon(icon)
        # zoom in
        self.actionZoomIn = QtWidgets.QAction(MainWindow)
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap(os.path.join(ICONS, "zoomin.svg")),
                       QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.actionZoomIn.setIcon(icon)
        # zoom out
        self.actionZoomOut = QtWidgets.QAction(MainWindow)
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap(os.path.join(ICONS, "zoomout.svg")),
                       QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.actionZoomOut.setIcon(icon)

        # build the toolbar
        # actions
        self.toolBar.addAction(self.actionAdd)
        self.toolBar.addAction(self.actionRemove)
        self.toolBar.addAction(self.actionDownload)
        self.toolBar.addSeparator()
        self.toolBar.addAction(self.actionPlay)
        self.toolBar.addAction(self.actionPause)
        self.toolBar.addAction(self.actionStop)
        self.toolBar.addSeparator()
        self.toolBar.addAction(self.actionPrevChapter)
        self.toolBar.addAction(self.actionPrevSent)
        self.toolBar.addAction(self.actionNextSent)
        self.toolBar.addAction(self.actionNextChapter)
        self.toolBar.addSeparator()
        self.toolBar.addAction(self.actionZoomIn)
        self.toolBar.addAction(self.actionZoomOut)
        self.toolBar.addSeparator()
        self.toolBar.addAction(self.actionSettings)
        self.toolBar.addAction(self.actionQuit)
        # volume
        self.volumeSlider = QtWidgets.QSlider(QtCore.Qt.Horizontal)
        self.volumeSlider.setRange(0, 200)
        self.volumeSlider.setValue(70)
        self.toolBar.addSeparator()
        self.toolBar.addWidget(QtWidgets.QLabel("Volume: "))
        self.toolBar.addWidget(self.volumeSlider)
        self.volumeSlider.sliderMoved.connect(
            self.player.setVolume)  # connect to the player
        # translation selector
        self.toolBar.addSeparator()
        self.transLanguage = QtWidgets.QComboBox()
        selected_lang = Config.value(Config.TRANS_LANG)
        for idx, (code, label) in enumerate(LANGUAGES.items()):
            self.transLanguage.addItem(label, code)
            if code == selected_lang:
                self.transLanguage.setCurrentIndex(idx)
        self.toolBar.addWidget(QtWidgets.QLabel("Translate to: "))
        self.toolBar.addWidget(self.transLanguage)