def __init__(self, db: MyDb, book: Book, parent=None): super(EditDataDialog, self).__init__(parent) self.db = db self.book = book self.form = QFormLayout() self.nameLabel = QLabel("书名") self.nameInput = QLineEdit() if book.name: self.nameInput.setText(book.name) self.authorLabel = QLabel("作者") self.authorInput = QLineEdit() if book.authors: self.authorInput.setText(strListToString(book.authors)) self.pub_dateLabel = QLabel("出版日期") self.pub_dateInput = QDateEdit() if book.pub_date: date = QDate() self.pub_dateInput.setDate( date.fromString(book.pub_date, 'yyyyMMdd')) self.publisherLabel = QLabel("出版社") self.publisherInput = QLineEdit() if book.publisher: self.publisherInput.setText(book.publisher) self.isbnLabel = QLabel("ISBN") self.isbnInput = QLineEdit() if book.isbn: self.isbnInput.setText(book.isbn) self.languageLabel = QLabel("语言") self.languageInput = QLineEdit() if book.language: self.languageInput.setText(book.language) self.ratingLabel = QLabel("评分") self.ratingInput = QLineEdit() self.ratingInput.setValidator(QIntValidator(0, 5)) if book.rating: self.ratingInput.setText(str(book.rating)) self.tagsLabel = QLabel("标签") self.tagsInput = QLineEdit() if book.tags: self.tagsInput.setText(strListToString(book.tags)) self.booklistLabel = QLabel("书单") self.booklistInput = QLineEdit() if book.bookLists: self.booklistInput.setText(strListToString(book.bookLists)) self.okButton = QPushButton("保存并退出") self.cancleButton = QPushButton("不保存退出") self.form.addRow(self.nameLabel, self.nameInput) self.form.addRow(self.authorLabel, self.authorInput) self.form.addRow(self.pub_dateLabel, self.pub_dateInput) self.form.addRow(self.publisherLabel, self.publisherInput) self.form.addRow(self.isbnLabel, self.isbnInput) self.form.addRow(self.languageLabel, self.languageInput) self.form.addRow(self.ratingLabel, self.ratingInput) self.form.addRow(self.tagsLabel, self.tagsInput) self.form.addRow(self.booklistLabel, self.booklistInput) self.form.addRow(self.okButton, self.cancleButton) self.setLayout(self.form) self.okButton.clicked.connect(self.onOK) self.cancleButton.clicked.connect(self.onCancle)
def addBook(self, book): self.connect() self.cursor.execute("insert into %s values(%s, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' ," "'%s')" % ( self.book_table, book.ID, book.name, strListToString(book.authors), book.pub_date, book.publisher, book.isbn, book.language, book.cover_path, book.rating, book.file_path, strListToString(book.tags), strListToString(book.bookLists))) self.close()
def updateBook(self, book): self.connect() self.cursor.execute( "update %s set name='%s', authors='%s', pub_date='%s', publisher='%s', isbn='%s', language='%s'," " cover_path='%s', rating=%s, file_path='%s', tags='%s', booklists='%s' where ID=%s" % ( self.book_table, book.name, strListToString(book.authors), book.pub_date, book.publisher, book.isbn, book.language, book.cover_path, book.rating, book.file_path, strListToString(book.tags), strListToString(book.bookLists), book.ID)) self.close()
def setMetadata(self): data = self.getMetadata() data['author'] = strListToString(self.authors) data['title'] = self.name doc = fitz.open(self.file_path) doc.setMetadata(data) doc.save(doc.name, incremental=True, encryption=fitz.PDF_ENCRYPT_KEEP)
def updateView(self, books: Books): self.deleteAll() self.lastActive = None if not books: return total = len(books) cols = 3 rows = ceil(total / cols) points = [(i, j) for i in range(rows) for j in range(cols)] tempWid = QWidget() for point, book in zip(points, books): tempLabel = MenuLabel(self.db, book.ID) tempLabel.changeCoverSignal.connect(self.onChangeCover) tempLabel.addTagSignal.connect(self.onAddTag) tempLabel.addToBooklistSignal.connect(self.onAddToBooklist) tempLabel.sendKindleSignal.connect(self.onToKindle) tempLabel.editDataSignal.connect(self.onEditData) tempLabel.setPixmap( QPixmap(book.cover_path).scaled(self.itemWidth, self.itemHeight)) tempLabel.setScaledContents(True) if book.name: tempLabel.setToolTip("书名: " + book.name + '\n' + "作者: " + strListToString(book.authors)) tempLabel.clicked.connect(self.onItemClicked) self.dict[tempLabel] = book.ID self.addWidget(tempLabel, *point) tempWid.setLayout(self) self.scrollarea.setWidget(tempWid) self.father = tempWid
def updateView(self, book: Book): if book.cover_path: self.picLabel.setPixmap(QPixmap(book.cover_path).scaled(365, 458)) else: self.picLabel.setPixmap( QPixmap('img/default-pic.png').scaled(365, 458)) if book.name: self.name.setText(book.name) else: self.name.setText("未知") if book.authors: self.authors.setText(strListToString(book.authors)) else: self.authors.setText("未知") if book.file_path: self.bookPath = book.file_path self.path.setText("<a style='color: blue'>打开</a>") self.format.setText("<a style='color: blue'>PDF</a>") self.format.clicked.connect(self.openFile) self.path.clicked.connect(self.openPath) else: self.bookPath = None self.path.setText("无") self.format.setText("无") if book.tags: self.tags.setText(strListToString(book.tags)) else: self.tags.setText("无") if book.bookLists: self.booklists.setText(strListToString(book.bookLists)) else: self.booklists.setText("无") temp = QWidget() temp.setFont(QFont("", 14)) temp.setLayout(self.form) self.scrollarea.setWidget(temp)
def setMetadata(self): data = self.getMetadata() data['author'] = strListToString(self.authors) data['title'] = self.name