def refresh(): lpath = Config.value(Config.LIBRARY) # book location MODEL.clear() MODEL.setHorizontalHeaderLabels(['Book/Language/Chapter', '']) bookfiles = glob.glob(lpath+"/*.json") for bookf in bookfiles: bi = model.BookInfo.fromJsonFile(bookf) book_node = QtGui.QStandardItem(res.book_icon, bi.bookid) book_node.setData(bi) MODEL.appendRow(book_node) for tr in bi.translations: # Create Language Node lang_node = QtGui.QStandardItem(res.lang_icon, tr.language) lang_node.setData(tr) book_node.appendRow(lang_node) for chapter in tr.chapters: # Create Chapter Node chnum = chapter.idx chapter_title = model.CHAPTER_CAPTION[tr.language] + ' %04d' % chnum ch_icon = res.play_icon if chapter.downloaded else res.dl_icon chapter_node = QtGui.QStandardItem(ch_icon, chapter_title) chapter.treeNode = chapter_node chapter_node.setData(chapter) lang_node.appendRow(chapter_node) # adjust column sizes on the tree view TREE_VIEW.resizeColumnToContents(0) TREE_VIEW.resizeColumnToContents(1)
def __init__(self, parent=None): super(ReaderWidget, self).__init__(parent) self._autoScroll = Config.value(Config.AUTO_SCROLL) self.readerPane = ReaderPane(parent=parent, autoScroll=self._autoScroll) self.readerPane.setReadOnly(True) readerPaneLayout = QtWidgets.QVBoxLayout() readerPaneLayout.addWidget(self.readerPane) self.setLayout(readerPaneLayout)
def __init__(self, book_info, lang, title, content_url): """Initialize information on a book""" cpath = Config.value(Config.CONTENT) # book contents self.book = book_info # identifier of the book self.book_path = os.path.join(cpath, book_info.bookid, lang) # root path of the book self.book_file = os.path.join(self.book_path, BOOK_FILE) # path to the local file self.language = lang # Language self.title = title # Title self.content_url = content_url # URL of the content self.chapters = [] # List of chapters self.book.addTranslation(self) self.updateStatus() # update download status
def showSearch(parent): dialog = SearchDialog(parent) result = dialog.exec_() if result == QtWidgets.QDialog.Accepted: for i in range(dialog.model.rowCount()): itm = dialog.model.item(i) if itm.checkState() == Qt.Checked: book_id = itm.text() # selected book identifier book_def = book_manager.getNetBook(book_id) # get the book configuration lpath = Config.value(Config.LIBRARY) # save location os.makedirs(lpath, exist_ok=True) fname = os.path.join(lpath, book_id + ".json") with open(fname, 'w') as f: f.write(book_def) parent.updateLibrary()
def setupUi(self, MainWindow): MainWindow.resize(1280, 800) self.player = player.Player(MainWindow, Config.value( Config.SKIP_INTRO)) # Medi palyer self.downloadManager = dl_manager.DownloadManager( MainWindow) # download manager # main gui window self.centralwidget = QtWidgets.QWidget(MainWindow) MainWindow.setCentralWidget(self.centralwidget) self.mainLayout = QtWidgets.QHBoxLayout( self.centralwidget) # horizontal layout for the browser/reader # flexible splitter for the browser/reader separator self.horizontalSplitter = QtWidgets.QSplitter(QtCore.Qt.Horizontal) self.mainLayout.addWidget(self.horizontalSplitter) # widget for the navigator tree self.navigatorWidget = QtWidgets.QWidget(self.centralwidget) self.horizontalSplitter.addWidget(self.navigatorWidget) self.navigatorLayout = QtWidgets.QVBoxLayout( ) # vertical box for the tree/download progress indicator self.navigatorWidget.setLayout(self.navigatorLayout) # tree view label self.lblBooks = QtWidgets.QLabel(self.centralwidget) self.navigatorLayout.addWidget(self.lblBooks) # tree view for the books self.bookList = QtWidgets.QTreeView(self.centralwidget) self.navigatorLayout.addWidget(self.bookList) # download label self.lblDownload = QtWidgets.QLabel(self.centralwidget) self.navigatorLayout.addWidget(self.lblDownload) self.lblDownload.hide() # download progress bar self.downloadProgress = QtWidgets.QProgressBar(self.centralwidget) self.downloadProgress.setProperty("value", 0) self.navigatorLayout.addWidget(self.downloadProgress) self.downloadProgress.hide() # layout for the selected content and its positions self.progressLayout = QtWidgets.QVBoxLayout() # widget for the selected content self.contentWidget = QtWidgets.QWidget() self.contentWidget.setLayout(self.progressLayout) # selected content self.selectedContent = QtWidgets.QLabel("Selected Content: None") self.progressLayout.addWidget(self.selectedContent) # position in the content self.chapterSlider = QtWidgets.QSlider(QtCore.Qt.Horizontal, self.centralwidget) self.progressLayout.addWidget(self.chapterSlider) self.chapterSlider.sliderMoved.connect(self.player.setPosition) # split content for the two reader panes self.contentPane = QtWidgets.QWidget(self.centralwidget) self.contentLayout = QtWidgets.QVBoxLayout() self.contentPane.setLayout(self.contentLayout) # splitter for the two rreaders self.readerSplitter = QtWidgets.QSplitter(QtCore.Qt.Vertical) # add the reader pane to the horizontal splitter self.contentLayout.addWidget(self.contentWidget) self.contentLayout.addWidget(self.readerSplitter) self.horizontalSplitter.addWidget(self.contentPane) self.horizontalSplitter.setStretchFactor(1, 1) # reader for the 1st language self.readerWidget = ReaderWidget() self.readerSplitter.addWidget(self.readerWidget) # reader for the 2nd language self.foreignReaderWidget = ReaderWidget() self.readerSplitter.addWidget(self.foreignReaderWidget) self.readerSplitter.setStretchFactor(2, 1) # status bar self.statusbar = QtWidgets.QStatusBar(MainWindow) MainWindow.setStatusBar(self.statusbar) # create the toolbar self.createToolbar(MainWindow) self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow)
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)