def on_pushButton_Add_clicked(self): logging.debug('on_pushButton_Add_clicked') book = Audiobook.getInstance() self.mask = MaskWidget(self.mainWindow) self.mask.show() self.afw = AttachFromWidgetWithoutURL( False, self._translate("ReadingOrderWidget", 'Open file'), (ReadingOrderWidget.str_LastOpenedDirectory, book.getBookDir() + '/')[ReadingOrderWidget.str_LastOpenedDirectory is None], "Audio files (*.mp3);; Wav files (*.wav)") self.afw.move( self.mainWindow.geometry().x() + self.mainWindow.geometry().width() / 2 - self.afw.geometry().width() / 2, self.mainWindow.geometry().y() + self.mainWindow.geometry().height() / 2 - self.afw.geometry().height() / 2) result = self.afw.exec_() filenames = self.afw.getURLs() self.mask.close() if result == QDialog.Accepted and filenames: self.getAttachFromWidgetResult(False, filenames) else: return
def save(self): supplementalList = [] for i in range(self.ui.listWidget.count()): item = self.ui.listWidget.itemWidget(self.ui.listWidget.item(i)) url = item.getFullFilename() # item.ui.lineEdit.text() if url == "": continue book = Audiobook.getInstance() # kind = filetype.guess(book.getBookDir() + '/' + url) mime, encoding = mimetypes.guess_type(url, strict=False) if mime is None: logging.warning('Cannot guess file type!') supplementalList.append({ "url": (url.replace(book.getBookDir() + "/", ""), url)[url.startswith('http')] }) else: extension = mimetypes.guess_extension(mime) logging.debug('File extension: %s' % extension) logging.debug('File MIME type: %s' % mime) supplementalList.append({ "url": url.replace(book.getBookDir() + "/", ""), "encodingFormat": mime }) return supplementalList
def on_pushButton_Add_clicked(self): logging.debug('on_pushButton_Add_clicked') if self._isEmpty: self.ui.label_NoItem.setVisible(False) self.ui.listWidget.setEnabled(True) self._isEmpty = False book = Audiobook.getInstance() self.mask = MaskWidget(self.mainWindow) self.mask.show() self.afw = AttachFromWidgetWithoutURL(False, 'Open files', ( SupplementalListWidgetWithWidgets.str_LastOpenedDirectory, book.getBookDir() + '/' )[SupplementalListWidgetWithWidgets.str_LastOpenedDirectory is None], "Any file(*.*)") self.afw.move( self.mainWindow.geometry().x() + self.mainWindow.geometry().width() / 2 - self.afw.geometry().width() / 2, self.mainWindow.geometry().y() + self.mainWindow.geometry().height() / 2 - self.afw.geometry().height() / 2) result = self.afw.exec_() filenames = self.afw.getURLs() self.mask.close() if result == QDialog.Accepted and filenames: self.getAttachFromWidgetResult(False, filenames) else: return
def changeEvent(self, event): """Handle LanguageChange event""" if event.type() == QEvent.LanguageChange: logging.debug("Language changed") book = Audiobook.getInstance() self.ui.retranslateUi(self) self.ui.pushButton_Remove.setToolTip( "<p style=\"color:#FFFFFF;font-family: Noto Sans;font-style: normal;" "font-weight: 400;font-size: 14px;line-height: 20px;\">" + self._translate("ReadingOrderItem", "Remove this item") + "</p>") self.ui.pushButton_Add.setToolTip( "<p style=\"color:#FFFFFF;font-family: Noto Sans;font-style: normal;" "font-weight: 400;font-size: 14px;line-height: 20px;\">" + self._translate("ReadingOrderItem", "Add this item to TOC") + "</p>") self.ui.pushButton_Play.setToolTip( "<p style=\"color:#FFFFFF;font-family: Noto Sans;font-style: normal;" "font-weight: 400;font-size: 14px;line-height: 20px;\">" + self._translate("ReadingOrderItem", "Play voice!") + "</p>") self.ui.label_Href.setText( self._fullFilename.replace(book.getBookDir() + '/', "")) super().changeEvent(event)
def _pack(self): book = Audiobook.getInstance() try: self._save(flag_Pack=True) book.on_action_Pack_triggered(self) except Exception as ex: logging.debug("{0}".format(ex))
def getAttachFromWidgetResult(self, bool_Result, list_Result): logging.debug(str(bool_Result) + ' ' + ";".join(list_Result)) book = Audiobook.getInstance() set_url = book.getCheckSet(self.mainWindow) filenames = [] if not bool_Result: filenames = list_Result book.checkAttachedFile(filenames, set_url, ReadingOrderWidget, self)
def __init__(self, sList, mainWindow=None, width=240, height=46): super(SupplementalListWidgetWithWidgets, self).__init__() self.mainWindow = mainWindow self.ui = Ui_SupplementalListWidgetWithWidgets() self.ui.setupUi(self) self.ui.gridLayout.setContentsMargins(0, 0, 0, 0) self.ui.verticalLayout.setContentsMargins(0, 0, 0, 0) if len(sList) > 0: self.ui.label_NoItem.setVisible(False) self.ui.listWidget.setEnabled(True) self._isEmpty = False else: self.ui.label_NoItem.setVisible(True) self.ui.listWidget.setEnabled(False) self._isEmpty = True self._listWidgetItemSerialNo = 0 # Unique index for # self.ui.listWidget.setDragDropMode(QAbstractItemView.InternalMove) # self.ui.listWidget.setContextMenuPolicy(Qt.CustomContextMenu) # self.ui.listWidget.customContextMenuRequested[QPoint].connect(self.on_SupplementalListWidgetContextMenu_triggered) self._itemWidth = width self._itemHeight = height self._translate = QCoreApplication.translate self.ui.pushButton_Add.setToolTip( "<p style=\"color:#FFFFFF;font-family: Noto Sans;font-style: normal;" "font-weight: 400;font-size: 14px;line-height: 20px;border: 0px;\">" + self._translate("SupplementalListWidgetWithWidgets", "Add more files") + "</p>") self.mask = None self.afw = None self.alert = None self.alertwithbuttons = None book = Audiobook.getInstance() for s in sList: url = s.get("url", "") if url != "": item = QListWidgetItem() # item.setText(str(self.ui.listWidget.count())) item.setSizeHint(self.getItemSize()) roi = SupplementalListWidgetItem( (book.getBookDir() + '/' + url, url)[url.startswith('http')], item, self.getSerialNo()) self.ui.listWidget.addItem(item) self.ui.listWidget.setItemWidget(item, roi) self._listWidgetItemSerialNo += 1
def changeEvent(self, event): """Handle LanguageChange event""" if event.type() == QEvent.LanguageChange: logging.debug("Language changed") book = Audiobook.getInstance() self.ui.retranslateUi(self) self.ui.pushButton_Remove.setToolTip("<p style=\"color:#FFFFFF;font-family: Noto Sans;font-style: normal;" "font-weight: 400;font-size: 14px;line-height: 20px;\">" + self._translate("TOCListWidgetItem", "Remove this item") + "</p>") self.ui.lineEdit_Title.setText(self._title) self.ui.label_Href.setText((self._fullFilename.replace(book.getBookDir() + '/', ""), self._fullFilename)[self._fullFilename.startswith('http')]) super().changeEvent(event)
def save(self): readingOrderList = [] seconds_Duration = 0.0 for i in range(self.ui.listWidget.count()): # item = self.listWidget.item(i) item = self.ui.listWidget.itemWidget(self.ui.listWidget.item(i)) # url = item.ui.label_Href.text() url = item.getFullFilename() if url == "*.mp3": continue mime, encoding = mimetypes.guess_type(url, strict=False) extension = mimetypes.guess_extension(mime, strict=False) # kind = filetype.guess(url) book = Audiobook.getInstance() # kind = filetype.guess(bookDir + r'/' + url) if mime is None: logging.warning('Cannot guess file type!') readingOrderList.append({ "url": (url.replace(book.getBookDir() + "/", ""), url)[url.startswith('http')] }) else: logging.debug('File extension: %s' % extension) logging.debug('File MIME type: %s' % mime) if extension == ".mp3" and mime.startswith("audio"): seconds_Duration += item.getDuration() # _seconds logging.debug("url = " + url) readingOrderList.append({ "url": (url.replace(book.getBookDir() + "/", ""), url)[url.startswith('http')], "encodingFormat": mime, "name": item.ui.lineEdit.text(), "duration": "PT" + str(item.getDuration()) + "S" }) return readingOrderList
def on_pushButton_clicked(self, sender): book = Audiobook.getInstance() if sender.objectName() == "pushButton_AddCover": logging.debug('button_AddCover is clicked') filename, _ = QFileDialog.getOpenFileName( self, self._translate("CoverPreviewWidget", 'Open file'), book.getBookDir() + '/', "JPG Files (*.jpg);;PNG Files (*.png)") # result, filename = self._getOpenFilename(False, # 'Open file', # book.getBookDir() + '/', # "JPG Files (*.jpg);;PNG Files (*.png)") if filename: self.getAttachFromWidgetResult(False, filename) else: return elif sender.objectName() == 'pushButton_Remove': logging.debug('button_Remove is clicked') bool_removed = QFile.remove(self.href) self.ui.label_Cover.setFixedSize(120, 120) self.ui.label_Cover.setPixmap( QPixmap(":/SVG/svg/icon/cover-preview-empty.svg")) self.href = '' self.ui.pushButton_Remove.setVisible(False) self.ui.pushButton_Replace.setVisible(False) self.ui.pushButton_AddCover.setVisible(True) elif sender.objectName() == 'pushButton_Replace': logging.debug('button_Replace is clicked') filename, _ = QFileDialog.getOpenFileName( self, self._translate("CoverPreviewWidget", 'Open file'), book.getBookDir() + '/', "JPG Files (*.jpg);;PNG Files (*.png)") if filename: self.getAttachFromWidgetResult(False, filename) else: return
def save(self): book = Audiobook.getInstance() # kind = filetype.guess(self.href) mime, _ = mimetypes.guess_type(self.href) extension = mimetypes.guess_extension(self.href) if mime is not None: dict_cover = { "url": self.href.replace(book.getBookDir() + "/", ""), "encodingFormat": mime, "name": "Cover", "rel": "cover" } else: dict_cover = { "url": "", "encodingFormat": "", "name": "Cover", "rel": "cover" } return dict_cover
def __init__(self, fullFilename, item, serialNo, title): super(TOCListWidgetItem, self).__init__() self.ui = Ui_TOCListWidgetItem() self.ui.setupUi(self) self._translate = QCoreApplication.translate self._serialNo = serialNo self._listWidgetItem = item self._fullFilename = fullFilename self._title = title book = Audiobook.getInstance() mime, encoding = mimetypes.guess_type(fullFilename) extension = mimetypes.guess_extension(fullFilename) if mime and mime.startswith("audio"): self.ui.timeEdit_Start.setEnabled(True) self.ui.timeEdit_Start.setVisible(True) else: self.ui.timeEdit_Start.setEnabled(False) self.ui.timeEdit_Start.setVisible(False) self.ui.label_Href.setText((fullFilename.replace(book.getBookDir() + '/', ""), fullFilename)[fullFilename.startswith('http')]) self.ui.label_Href.setToolTip("<p style=\"color:#FFFFFF;font-family: Noto Sans;font-style: normal;" "font-weight: 400;font-size: 14px;line-height: 20px;\">" + fullFilename + "</p>") self.ui.pushButton_Remove.setToolTip("<p style=\"color:#FFFFFF;font-family: Noto Sans;font-style: normal;" "font-weight: 400;font-size: 14px;line-height: 20px;\">" + self._translate("TOCListWidgetItem", "Remove this item") + "</p>") self.ui.lineEdit_Title.setText(title)
def show_MainWindow(self, item): logging.debug("show_MainWindow for str = " + item) if item == "": return self.startingPanel.close() self.book = Audiobook.getInstance(item) self.mainWindow = MainWindow(self.book) self.mainWindow.setStatusBar(None) self.mainWindow.signal_exit.connect(self.exit) self.mainWindow.signal_close.connect(self.close) self.mainWindow.signal_new.connect(self.new) self.mainWindow.signal_open.connect(self.open) self.mainWindow.move(QApplication.instance().desktop().screenGeometry(DISPLAY_ON_SCREEN).center().x() - self.mainWindow.size().width() / 2, QApplication.instance().desktop().screenGeometry(DISPLAY_ON_SCREEN).center().y() - self.mainWindow.size().height() / 2) self.mainWindow.show()
def show_MainWindow(self, dict_New): logging.debug("show_MainWindow for dict") if dict_New == {}: self.show_StartingPanel() else: self.book = Audiobook.getInstance(dict_New) logging.debug(dict_New) self.mainWindow = MainWindow(dict_New) self.mainWindow.setStatusBar(None) self.mainWindow.signal_exit.connect(self.exit) self.mainWindow.signal_close.connect(self.close) self.mainWindow.signal_new.connect(self.new) self.mainWindow.signal_open.connect(self.open) if hasattr(self, 'createNewWizard'): self.createNewWizard.close() self.mainWindow.move(QApplication.instance().desktop().screenGeometry(DISPLAY_ON_SCREEN).center().x() - self.mainWindow.size().width() / 2, QApplication.instance().desktop().screenGeometry(DISPLAY_ON_SCREEN).center().y() - self.mainWindow.size().height() / 2) self.mainWindow.show()
def on_generateListWidgetItemAction_triggered(self, data, root=None): logging.debug('TOCListWidget : on_generateListWidgetItemAction_triggered') self.ui.listWidget.clear() book = Audiobook.getInstance() def addChildItem(data, level, parentItem): children = data['children'] if children: return for i in range(len(children)): child = children[i] lvl = child['level'] if lvl == level: item = QListWidgetItem(parentItem) item.setSizeHint(self.getItemSize()) roi = TOCListWidgetItem(item, self.getSerialNo()) roi.ui.lineEdit_Title.setText(dict_TOC['title']) href = dict_TOC["href"] indexOfSharpSign = href.find('#t=') if indexOfSharpSign == -1: # Not in roi.ui.label_Href.setText(href) else: timeStamp = href[indexOfSharpSign + 3:] [startTime, endTime] = timeStamp.split(',') roi.ui.timeEdit_Start.setTime(QTime.fromString(startTime, "hh:mm:ss.zzz")) # roi.ui.lineEdit_End.setText(endTime) self._listWidgetItemSerialNo += 1 addChildItem(child, level + 1, item) if isinstance(data, list): logging.debug('isinstance(data, list)') if len(data) > 0: if self._isEmpty: logging.debug('self.ui.widget_NoItem.setVisible(False)') self.ui.widget_NoItem.setVisible(False) self.ui.listWidget.setEnabled(True) self._isEmpty = False for i in range(len(data)): dict_TOC = data[i] level = dict_TOC["level"] if level == 0: item = QListWidgetItem() # item.setText(str(self.ui.listWidget.count())) item.setSizeHint(self.getItemSize()) href = dict_TOC["href"] indexOfSharpSign = href.find('#t=') timeStamp = '' if indexOfSharpSign == -1: fullFilename = (book.getBookDir() + '/' + href, href)[href.startswith('http')] roi = TOCListWidgetItem(fullFilename, item, self.getSerialNo(), dict_TOC['title']) # roi.ui.lineEdit_Title.setText(dict_TOC['title']) else: timeStamp = href[indexOfSharpSign + 3:] fullFilename = (book.getBookDir() + '/' + href[0: indexOfSharpSign], href[0: indexOfSharpSign])[href.startswith('http')] roi = TOCListWidgetItem(fullFilename, item, self.getSerialNo(), dict_TOC['title']) # roi.ui.lineEdit_Title.setText(dict_TOC['title']) if timeStamp.find(',') == -1: startTime = timeStamp startTimeFloat = float(startTime) hh = int(startTimeFloat // 3600) startTimeFloat -= hh * 3600 mm = int(startTimeFloat // 60) startTimeFloat -= mm * 60 ss = int(startTimeFloat) startTimeFloat -= ss zzz = startTimeFloat startTimeString = "{:02d}".format(hh) + \ ":{:02d}".format(mm) + \ ":{:02d}".format(ss) + \ str("{:.3f}".format(zzz))[1: 5] roi.ui.timeEdit_Start.setTime(QTime.fromString(startTimeString, "hh:mm:ss.zzz")) else: # To-Do: start- & end-time both exist [startTime, endTime] = timeStamp.split(',') startTimeFloat = float(startTime) endTimeFloat = float(endTime) hh = int(startTimeFloat // 3600) startTimeFloat -= hh * 3600 mm = int(startTimeFloat // 60) startTimeFloat -= mm * 60 ss = int(startTimeFloat) startTimeFloat -= ss zzz = startTimeFloat startTimeString = "{:02d}".format(hh) + \ ":{:02d}".format(mm) + \ ":{:02d}".format(ss) + \ str("{:.3f}".format(zzz))[1: 5] hh = int(endTimeFloat // 3600) endTimeFloat -= hh * 3600 mm = int(endTimeFloat // 60) endTimeFloat -= mm * 60 ss = int(endTimeFloat) endTimeFloat -= ss zzz = endTimeFloat endTimeString = "{:02d}".format(hh) + \ ":{:02d}".format(mm) + \ ":{:02d}".format(ss) + \ str("{:.3f}".format(zzz))[1: 5] roi.ui.timeEdit_Start.setTime(QTime.fromString(startTimeString, "hh:mm:ss.zzz")) pass self.ui.listWidget.addItem(item) self.ui.listWidget.setItemWidget(item, roi) self._listWidgetItemSerialNo += 1 # if dict_TOC['children'] != []: addChildItem(dict_TOC, level + 1, item) self.roiList.append(roi) self.ui.listWidget.setEnabled(True)
def __init__(self, fullFilename, item, serialNo=-1): logging.debug('@dispatch(str, QListWidgetItem, int)') super(SupplementalListWidgetItem, self).__init__() self.ui = Ui_SupplementalListWidgetItem() self.ui.setupUi(self) self._fullFilename = fullFilename mime, encoding = mimetypes.guess_type(fullFilename) # kind = filetype.guess(fullFilename) if mime is None: logging.warning('Cannot guess file type!') else: extension = mimetypes.guess_extension(mime) logging.debug('File extension: %s' % extension) logging.debug('File MIME type: %s' % mime) if mime.startswith('image'): self.ui.label_Filetype.setPixmap( QPixmap(":/SVG/svg/icon/resource-image.svg")) elif mime.startswith('audio'): self.ui.label_Filetype.setPixmap( QPixmap(":/SVG/svg/icon/resource-audio.svg")) elif mime == 'application/pdf': self.ui.label_Filetype.setPixmap( QPixmap(":/SVG/svg/icon/resource-pdf.svg")) logging.debug(fullFilename) ''' filename, file_extension = os.path.splitext(item_Open) if file_extension == '.lpf': ''' book = Audiobook.getInstance() logging.debug((fullFilename.replace(book.getBookDir() + '/', ""), fullFilename)[fullFilename.startswith('http')]) shortFilename = (fullFilename.replace(book.getBookDir() + '/', ""), fullFilename)[fullFilename.startswith('http')] displayFilename = shortFilename if mime is not None: if len(shortFilename) >= 8: displayFilename = shortFilename[0:5] + ".." + extension else: if len(shortFilename) >= 8: # src = QFile(fullFilename) info = QFileInfo(fullFilename) displayFilename = shortFilename[0:5] + ".." + info.suffix() logging.debug("displayFilename = " + displayFilename) self.ui.lineEdit.setText(displayFilename) # self.ui.lineEdit.setText(fullFilename.replace(book.getBookDir() + '/', "")) self._serialNo = serialNo self._listItem = item self._translate = QCoreApplication.translate self.ui.lineEdit.setToolTip( "<p style=\"color:#FFFFFF;font-family: Noto Sans;font-style: normal;" "font-weight: 400;font-size: 14px;line-height: 20px;\">" + fullFilename + "</p>") self.ui.pushButton_Remove.setToolTip( "<p style=\"color:#FFFFFF;font-family: Noto Sans;font-style: normal;" "font-weight: 400;font-size: 14px;line-height: 20px;\">" + self._translate("SupplementalListWidgetItem", "Remove this item") + "</p>") self.ui.pushButton_Add.setToolTip( "<p style=\"color:#FFFFFF;font-family: Noto Sans;font-style: normal;" "font-weight: 400;font-size: 14px;line-height: 20px;\">" + self._translate("SupplementalListWidgetItem", "Add this item to TOC") + "</p>")
def getAttachFromWidgetResult(self, bool_Result, str_Result): logging.debug(str(bool_Result) + ' ' + str_Result) book = Audiobook.getInstance() option, list_compulsory = book.determineOption() url_compulsory = [ book.getBookDir() + '/' + f for f in list_compulsory if not f.startswith('http') ] url_orderingOrder = [ book.getBookDir() + '/' + f["url"] for f in self.mainWindow.readingOrderWidget.save() if not f["url"].startswith('http') ] url_toc = [ book.getBookDir() + '/' + f["href"] for f in self.mainWindow.tocWidget.save(True) if not f["href"].startswith('http') ] url_cover = [ book.getBookDir() + '/' + f["url"] for f in [self.save()] if not f["url"].startswith('http') ] url_supplemental = [ book.getBookDir() + '/' + f["url"] for f in self.mainWindow.supplementalListWidget.save() if not f["url"].startswith('http') ] set_url = set(url_compulsory + url_orderingOrder + url_toc + url_cover + url_supplemental) filename = "" if not bool_Result: filename = str_Result file_folder, file_name = os.path.split(filename) if filename in set_url: logging.debug( "You have chosen one file already in this audiobook") self._openAlertWindow( self._translate( "CoverPreviewWidget", 'You have chosen one file already in this audiobook!'), self._translate("CoverPreviewWidget", "Warning")) filename = "" return elif book.getBookDir() + '/' + file_name in set_url: logging.debug( "One file with the same name is already in this audiobook") result = self._openAlertWithButtonsWindow( self._translate( "CoverPreviewWidget", 'One file with the same name is already ' 'in this audiobook! ' 'Do you want to overwrite ' 'that original file?'), self._translate("CoverPreviewWidget", "Warning")) if result: try: shutil.copyfile(filename, book.getBookDir() + '/' + file_name) filename = book.getBookDir() + '/' + file_name except Exception as ex: logging.critical(ex) self._openAlertWindow( self._translate( "CoverPreviewWidget", 'Sorry, we couldn\'t overwrite the original file!' ), self._translate("CoverPreviewWidget", "Warning")) return else: filename = "" return elif file_folder == book.getBookDir(): pass else: pass src = QFile(filename) # info = QFileInfo(filename) if file_folder != book.getBookDir(): try: shutil.copyfile(filename, book.getBookDir() + '/' + file_name) filename = book.getBookDir() + '/' + file_name except Exception as ex: logging.critical(ex) self._openAlertWindow( self._translate( "CoverPreviewWidget", 'Sorry, we couldn\'t copy this file ' 'to the audiobook folder!'), self._translate("CoverPreviewWidget", "Warning")) return else: filename = book.getBookDir() + '/' + file_name img = QPixmap(filename) w, h = img.size().width(), img.size().height() img = img.scaledToWidth(120, Qt.SmoothTransformation) \ if w > h else img.scaledToHeight(120, Qt.SmoothTransformation) # self.ui.label_Cover.setFixedSize(img.size()) # self.ui.label_Cover.setPixmap(img) if self.href: bool_Removed = QFile.remove(self.href) if not bool_Removed: self._openAlertWindow( self._translate( "CoverPreviewWidget", 'We couldn\'t remove the old cover for you!'), self._translate("CoverPreviewWidget", "Warning")) # return self.ui.label_Cover.setFixedSize(img.size()) self.ui.label_Cover.setPixmap(img) self.href = filename self.ui.pushButton_Remove.setVisible(True) self.ui.pushButton_Replace.setVisible(True) self.ui.pushButton_AddCover.setVisible(False)
def __init__(self, rList, bookDir, mainWindow=None, width=420, height=78): super(ReadingOrderWidget, self).__init__() self.mainWindow = mainWindow self.ui = Ui_ReadingOrderWidget() self.ui.setupUi(self) self._translate = QCoreApplication.translate self.ui.gridLayout.setContentsMargins(0, 0, 0, 0) self.ui.verticalLayout.setContentsMargins(0, 0, 0, 0) self.ui.listWidget.model().rowsMoved.connect(self.afterDrop) self.ui.pushButton_Add.setToolTip( "<p style=\"color:#FFFFFF;font-family: Noto Sans;font-style: normal;" "font-weight: 400;font-size: 14px;line-height: 20px;border: 0px;\">" + self._translate("ReadingOrderWidget", "Add voice to Reading Order") + "</p>") # self.ui.listWidget.setAcceptDrops(True) self.ui.listWidget.setDragDropMode(QAbstractItemView.InternalMove) self.ui.listWidget.setDefaultDropAction(Qt.MoveAction) self.ui.listWidget.installEventFilter(self) if len(rList) > 0: for i in range(self.ui.verticalLayout.count()): item = self.ui.verticalLayout.itemAt(i) if isinstance(item, QSpacerItem): logging.debug("QSpacerItem is at pos " + str(i)) one = self.ui.verticalLayout.takeAt(i) del one break self.ui.verticalLayout.removeWidget(self.ui.widget_Board) self.ui.verticalLayout.removeWidget(self.ui.label_Book) self.ui.widget_Board.setVisible(False) self.ui.label_Book.setVisible(False) # self.ui.verticalLayout.removeItem(self.spacerItem) self.ui.verticalLayout.addWidget(self.ui.listWidget, 1) self.ui.listWidget.show() logging.debug(self.ui.verticalLayout.count()) self._isEmpty = False else: self.ui.verticalLayout.removeWidget(self.ui.listWidget) self.ui.listWidget.hide() self.ui.verticalLayout.setAlignment(self.ui.widget, Qt.AlignTop) self.ui.verticalLayout.removeWidget(self.ui.label_Book) self.ui.verticalLayout.addSpacerItem( QSpacerItem(420, 10, QSizePolicy.Fixed, QSizePolicy.Expanding)) self.ui.verticalLayout.addWidget(self.ui.label_Book) self.ui.verticalLayout.setAlignment(self.ui.label_Book, Qt.AlignBottom) self._isEmpty = True self._listWidgetItemSerialNo = 0 self._itemWidth = width self._itemHeight = height self._seconds_Duration = 0.0 self.roiList = [] book = Audiobook.getInstance() if len(rList) > 0: self._isEmpty = False for r in rList: logging.debug(r) if isinstance(r, dict): url = r.get("url", "") item = QListWidgetItem() # item.setText(str(self.ui.listWidget.count())) item.setSizeHint(self.getItemSize()) roi = ReadingOrderItem((book.getBookDir() + '/' + url, url)[url.startswith("http")], item, self.getSerialNo()) roi.ui.lineEdit.setText(r.get("name", "")) self.ui.listWidget.addItem(item) self.ui.listWidget.setItemWidget(item, roi) self._listWidgetItemSerialNo += 1 self.roiList.append(roi) elif isinstance(r, str): logging.debug("isinstance(r, str)") url = r if url.startswith("http"): # http(s) link pass else: item = QListWidgetItem() # item.setText(str(self.ui.listWidget.count())) item.setSizeHint(self.getItemSize()) roi = ReadingOrderItem((book.getBookDir() + '/' + url, url)[url.startswith("http")], item, self.getSerialNo()) self.ui.listWidget.addItem(item) self.ui.listWidget.setItemWidget(item, roi) self._listWidgetItemSerialNo += 1 self.roiList.append(roi) logging.warning("ROL has initialized") logging.debug(self._seconds_Duration) self.resortItems() self.getDuration() self.mask = None self.afw = None self.alert = None self.alertwithbuttons = None self._afterDrop = False
def __init__(self, dict_New): super(MainWindow, self).__init__() self.ui = Ui_MainWindow() self.ui.setupUi(self) self._translate = QCoreApplication.translate # MenuBar CSS self.ui.menubar.setStyleSheet( 'QMenuBar::item { color: #FFFFFF } QMenuBar::item::selected { background: #383838; color: #FFFFFF } ' 'QMenu::item { color: #FFFFFF } QMenu::item::selected { background: #383838; color: #FFFFFF }' ) # MainWindow Title self.setWindowTitle('Audiobook Editor') # Set Window Icon # self.setWindowIcon(QIcon(':/pic/icon/audiobook-editor-logo.ico')) # Hide Minimize & Maximize buttons # self.setWindowFlags(self.windowFlags() & ~Qt.WindowMaximizeButtonHint) # WindowMinMaxButtonsHint) # Magic to make title bar disappear self.ui.dockWidget_Left.setTitleBarWidget(QWidget(None)) self.ui.dockWidget_CoverPreviewWidget.setTitleBarWidget(QWidget(None)) self.ui.dockWidget_SupplementalList.setTitleBarWidget(QWidget(None)) # self.ui.action_Qt.triggered.connect(self.on_action_Qt_triggered) self.book = Audiobook.getInstance() layout = QVBoxLayout(self.ui.tab_Metadata) layout.setContentsMargins(0, 0, 0, 0) layout.setAlignment(Qt.AlignTop | Qt.AlignLeft) self.metadataWidget = MetadataWidget(self, dict_New) layout.addWidget(self.metadataWidget) # Magic to make title bar disappear self.ui.dockWidget_Left.setTitleBarWidget(QWidget(None)) self.ui.dockWidget_CoverPreviewWidget.setTitleBarWidget(QWidget(None)) self.ui.dockWidget_SupplementalList.setTitleBarWidget(QWidget(None)) layout = QVBoxLayout(self.ui.dockWidgetContents) layout.setContentsMargins(0, 0, 0, 0) self.coverPreviewWidget = CoverPreviewWidget(self) layout.addWidget(self.coverPreviewWidget) w = QWidget() layout = QHBoxLayout(w) layout.setContentsMargins(0, 0, 0, 0) self.readingOrderWidget = ReadingOrderWidget(self) layout.addWidget(self.readingOrderWidget) # layout.addStretch(0) self.setCentralWidget(w) layout = QVBoxLayout(self.ui.tab_TOC) self.tocWidget = TOCListWidget(self) layout.addWidget(self.tocWidget) self.readingOrderWidget.signal_Add_Resource_to_TOC.connect( self.tocWidget.add_Resource_to_TOC_triggered) self.readingOrderWidget.signal_Duration_Changed.connect( self.metadataWidget.onDurationChanged) layout = QVBoxLayout(self.ui.dockWidgetContents_2) layout.setContentsMargins(0, 0, 0, 0) self.supplementalListWidget = SupplementalListWidgetWithWidgets(self) layout.addWidget(self.supplementalListWidget) self.supplementalListWidget.signal_Add_Resource_to_TOC.connect( self.tocWidget.add_Resource_to_TOC_triggered) # self.supplementalListWidget.addItems(1) self.ui.action_New.triggered.connect(self._new) self.ui.action_Open.triggered.connect(self._open) self.ui.action_Exit.triggered.connect(self._exit) self.ui.action_Save.triggered.connect(self._save) self.ui.action_Close.triggered.connect(self._close) self.ui.action_Validate.triggered.connect(self._validate) self.ui.action_Pack.triggered.connect(self._pack) self.settings = QSettings() self.recentFilesOrDirectoriesInSettings = '' self.ui.action_EN.triggered.connect( lambda: self.changeUILanguage('EN', self.ui.action_EN)) self.ui.action_TC.triggered.connect( lambda: self.changeUILanguage('TC', self.ui.action_TC)) app = QApplication.instance() for action in self.ui.menu_Language.actions(): if action.objectName() == 'action_' + app.ui_Language: action.setChecked(True) else: action.setChecked(False)
def __init__(self, fullFilename, item, serialNo=-1): logging.debug('@dispatch(str, QListWidgetItem, int)') super(ReadingOrderItem, self).__init__() self.ui = Ui_ReadingOrderItem() self.ui.setupUi(self) self.player = QMediaPlayer() self._fullFilename = fullFilename self._translate = QCoreApplication.translate mime, encoding = mimetypes.guess_type(fullFilename) extension = mimetypes.guess_extension(fullFilename) logging.debug(fullFilename) book = Audiobook.getInstance() if fullFilename.startswith('http'): logging.debug(fullFilename) self.ui.label_Href.setText(fullFilename) self.ui.label_Href.setToolTip("<p style=\"color:#FFFFFF\">" + fullFilename + "</p>") duration = Helper.getMP3Duration(fullFilename) self.ui.label_Duration.setText( "{:02d}".format(int(duration // 3600)) + ":{:02d}".format(int(duration // 60)) + ":{:02d}".format(int(duration % 60))) self.ui.progressBar.setMaximum(int(duration)) self.ui.progressBar.setValue(0) self._seconds = duration else: logging.debug(fullFilename.replace(book.getBookDir() + '/', "")) self.ui.label_Href.setText( fullFilename.replace(book.getBookDir() + '/', "")) self.ui.label_Href.setToolTip("<p style=\"color:#FFFFFF\">" + fullFilename + "</p>") duration = Helper.getMP3Duration(fullFilename) self.ui.label_Duration.setText( "{:02d}".format(int(duration // 3600)) + ":{:02d}".format(int(duration // 60)) + ":{:02d}".format(int(duration % 60))) self.ui.progressBar.setMaximum(int(duration)) self.ui.progressBar.setValue(0) self._seconds = duration self._listItem = item self._serialNo = serialNo self.ui.pushButton_Remove.setToolTip( "<p style=\"color:#FFFFFF;font-family: Noto Sans;font-style: normal;" "font-weight: 400;font-size: 14px;line-height: 20px;\">" + self._translate("ReadingOrderItem", "Remove this item") + "</p>") self.ui.pushButton_Add.setToolTip( "<p style=\"color:#FFFFFF;font-family: Noto Sans;font-style: normal;" "font-weight: 400;font-size: 14px;line-height: 20px;\">" + self._translate("ReadingOrderItem", "Add this item to TOC") + "</p>") self.ui.pushButton_Play.setToolTip( "<p style=\"color:#FFFFFF;font-family: Noto Sans;font-style: normal;" "font-weight: 400;font-size: 14px;line-height: 20px;\">" + self._translate("ReadingOrderItem", "Play voice!") + "</p>")