def process_duplicates(self): duplicates = self.db_adder.duplicates if not duplicates: return self.duplicates_processed() self.pd.hide() files = [ _('%(title)s by %(author)s') % dict(title=x[0].title, author=x[0].format_field('authors')[1]) for x in duplicates ] if question_dialog( self._parent, _('Duplicates found!'), _('Books with the same title as the following already ' 'exist in the database. Add them anyway?'), '\n'.join(files)): pd = QProgressDialog(_('Adding duplicates...'), '', 0, len(duplicates), self._parent) pd.setCancelButton(None) pd.setValue(0) pd.show() self.__p_d = pd self.__d_a = DuplicatesAdder(self._parent, self.db, duplicates, self.db_adder) self.__d_a.added.connect(pd.setValue) self.__d_a.adding_done.connect(self.duplicates_processed) else: return self.duplicates_processed()
def process_duplicates(self): duplicates = self.db_adder.duplicates if not duplicates: return self.duplicates_processed() self.pd.hide() from calibre.gui2.dialogs.duplicates import DuplicatesQuestion self.__d_q = d = DuplicatesQuestion(self.db, duplicates, self._parent) duplicates = tuple(d.duplicates) if duplicates: pd = QProgressDialog(_("Adding duplicates..."), "", 0, len(duplicates), self._parent) pd.setCancelButton(None) pd.setValue(0) pd.show() self.__p_d = pd self.__d_a = DuplicatesAdder(self._parent, self.db, duplicates, self.db_adder) self.__d_a.added.connect(pd.setValue) self.__d_a.adding_done.connect(self.duplicates_processed) else: return self.duplicates_processed()
def process_duplicates(self): duplicates = self.db_adder.duplicates if not duplicates: return self.duplicates_processed() self.pd.hide() from calibre.gui2.dialogs.duplicates import DuplicatesQuestion self.__d_q = d = DuplicatesQuestion(self.db, duplicates, self._parent) duplicates = tuple(d.duplicates) if duplicates: pd = QProgressDialog(_('Adding duplicates...'), '', 0, len(duplicates), self._parent) pd.setCancelButton(None) pd.setValue(0) pd.show() self.__p_d = pd self.__d_a = DuplicatesAdder(self._parent, self.db, duplicates, self.db_adder) self.__d_a.added.connect(pd.setValue) self.__d_a.adding_done.connect(self.duplicates_processed) else: return self.duplicates_processed()
def process_duplicates(self): duplicates = self.db_adder.duplicates if not duplicates: return self.duplicates_processed() self.pd.hide() files = [_('%(title)s by %(author)s')%dict(title=x[0].title, author=x[0].format_field('authors')[1]) for x in duplicates] if question_dialog(self._parent, _('Duplicates found!'), _('Books with the same title as the following already ' 'exist in the database. Add them anyway?'), '\n'.join(files)): pd = QProgressDialog(_('Adding duplicates...'), '', 0, len(duplicates), self._parent) pd.setCancelButton(None) pd.setValue(0) pd.show() self.__p_d = pd self.__d_a = DuplicatesAdder(self._parent, self.db, duplicates, self.db_adder) self.__d_a.added.connect(pd.setValue) self.__d_a.adding_done.connect(self.duplicates_processed) else: return self.duplicates_processed()
def process_duplicates(self): duplicates = self.db_adder.duplicates if not duplicates: return self.duplicates_processed() self.pd.hide() duplicate_message = [] for x in duplicates: duplicate_message.append(_("Already in calibre:")) matching_books = self.db.books_with_same_title(x[0]) for book_id in matching_books: aut = [a.replace("|", ",") for a in (self.db.authors(book_id, index_is_id=True) or "").split(",")] duplicate_message.append( "\t" + _("%(title)s by %(author)s") % dict(title=self.db.title(book_id, index_is_id=True), author=authors_to_string(aut)) ) duplicate_message.append(_("You are trying to add:")) duplicate_message.append( "\t" + _("%(title)s by %(author)s") % dict(title=x[0].title, author=x[0].format_field("authors")[1]) ) duplicate_message.append("") if question_dialog( self._parent, _("Duplicates found!"), _("Books with the same title as the following already " "exist in calibre. Add them anyway?"), "\n".join(duplicate_message), ): pd = QProgressDialog(_("Adding duplicates..."), "", 0, len(duplicates), self._parent) pd.setCancelButton(None) pd.setValue(0) pd.show() self.__p_d = pd self.__d_a = DuplicatesAdder(self._parent, self.db, duplicates, self.db_adder) self.__d_a.added.connect(pd.setValue) self.__d_a.adding_done.connect(self.duplicates_processed) else: return self.duplicates_processed()
def process_duplicates(self): duplicates = self.db_adder.duplicates if not duplicates: return self.duplicates_processed() self.pd.hide() duplicate_message = [] for x in duplicates: duplicate_message.append(_('Already in calibre:')) matching_books = self.db.books_with_same_title(x[0]) for book_id in matching_books: aut = [a.replace('|', ',') for a in (self.db.authors(book_id, index_is_id=True) or '').split(',')] duplicate_message.append('\t'+ _('%(title)s by %(author)s')% dict(title=self.db.title(book_id, index_is_id=True), author=authors_to_string(aut))) duplicate_message.append(_('You are trying to add:')) duplicate_message.append('\t'+_('%(title)s by %(author)s')% dict(title=x[0].title, author=x[0].format_field('authors')[1])) duplicate_message.append('') if question_dialog(self._parent, _('Duplicates found!'), _('Books with the same title as the following already ' 'exist in calibre. Add them anyway?'), '\n'.join(duplicate_message)): pd = QProgressDialog(_('Adding duplicates...'), '', 0, len(duplicates), self._parent) pd.setCancelButton(None) pd.setValue(0) pd.show() self.__p_d = pd self.__d_a = DuplicatesAdder(self._parent, self.db, duplicates, self.db_adder) self.__d_a.added.connect(pd.setValue) self.__d_a.adding_done.connect(self.duplicates_processed) else: return self.duplicates_processed()
def download_button_clicked(self): tags = str(self.custom_tags.text()) # url_id = self.recipes.model.data(1, QtCore.Qt.UserRole) # TODO: 获得选中的recipes url_id = str(self.row_clicked(self.recipes.currentIndex())) if url_id == 'None': QtGui.QMessageBox.information(self, u"Error", u"选择需要爬取的网站!") return readlist_content = self.plainTextEdit.toPlainText() if readlist_content == '': QtGui.QMessageBox.information(self, u"Error", u"请在文本框中输入网址") return read_list_path = Path.read_list_path readList_file = open(read_list_path, 'w') readList_file.write(readlist_content) readList_file.close() game = EEBook(recipe_kind=url_id) progress_dlg = QProgressDialog(self) # TODO: 设置大小, 区域 progress_dlg.setWindowModality(Qt.WindowModal) progress_dlg.setMinimumDuration(5) progress_dlg.setWindowTitle(u"请等待") progress_dlg.setLabelText(u"制作中...请稍候") progress_dlg.setCancelButtonText(u"取消") progress_dlg.resize(350, 250) progress_dlg.show() progress_dlg.setRange(0, 20) for i in range(0, 15): progress_dlg.setValue(i) QThread.msleep(100) for i in range(15, 20): progress_dlg.setValue(i) QThread.msleep(100) if progress_dlg.wasCanceled(): QtGui.QMessageBox.information(self, u"Error", u"电子书制作失败, 请重新操作") return try: filename = game.begin() # TODO: 一次只能生成一本书 except TypeError: QtGui.QMessageBox.information(self, u"Error", u"第一次使用请登录") progress_dlg.close() return progress_dlg.close() info_filename = ','.join(filename) QtGui.QMessageBox.information(self, u"info", u"电子书"+str(info_filename)+u"制作成功") for item in filename: file_path = EPUBSTOR_DIR + '/' + item Path.copy(str(file_path+'.epub'), LIBRARY_DIR) file_name = os.path.basename(str(file_path)) book_id = file_name.split('.epub')[0] Path.mkdir(LIBRARY_DIR + book_id) shutil.move(LIBRARY_DIR+book_id+'.epub', LIBRARY_DIR+book_id) book = Book(str(book_id)) book.date = time.strftime(ISOTIMEFORMAT, time.localtime()) book.tags += tags.replace(' ', '') book.tags += ','+str(self.now_url) if self.add_title_tag.isChecked(): book.tags += ','+str(book.title) insert_library(book) return
def download_button_clicked(self): tags = str(self.custom_tags.text()) # url_id = self.recipes.model.data(1, QtCore.Qt.UserRole) # TODO: 获得选中的recipes url_id = str(self.row_clicked(self.recipes.currentIndex())) if url_id == 'None': QtGui.QMessageBox.information(self, u"Error", u"选择需要爬取的网站!") return readlist_content = self.plainTextEdit.toPlainText() if readlist_content == '': QtGui.QMessageBox.information(self, u"Error", u"请在文本框中输入网址") return read_list_path = Path.read_list_path readList_file = open(read_list_path, 'w') readList_file.write(readlist_content) readList_file.close() game = EEBook(recipe_kind=url_id) progress_dlg = QProgressDialog(self) # TODO: 设置大小, 区域 progress_dlg.setWindowModality(Qt.WindowModal) progress_dlg.setMinimumDuration(5) progress_dlg.setWindowTitle(u"请等待") progress_dlg.setLabelText(u"制作中...请稍候") progress_dlg.setCancelButtonText(u"取消") progress_dlg.resize(350, 250) progress_dlg.show() progress_dlg.setRange(0, 20) for i in range(0, 15): progress_dlg.setValue(i) QThread.msleep(100) for i in range(15, 20): progress_dlg.setValue(i) QThread.msleep(100) if progress_dlg.wasCanceled(): QtGui.QMessageBox.information(self, u"Error", u"电子书制作失败, 请重新操作") return try: filename = game.begin() # TODO: 一次只能生成一本书 except TypeError: QtGui.QMessageBox.information(self, u"Error", u"第一次使用请登录") progress_dlg.close() return progress_dlg.close() info_filename = ','.join(filename) QtGui.QMessageBox.information( self, u"info", u"电子书" + str(info_filename) + u"制作成功") for item in filename: file_path = EPUBSTOR_DIR + '/' + item Path.copy(str(file_path + '.epub'), LIBRARY_DIR) file_name = os.path.basename(str(file_path)) book_id = file_name.split('.epub')[0] Path.mkdir(LIBRARY_DIR + book_id) shutil.move(LIBRARY_DIR + book_id + '.epub', LIBRARY_DIR + book_id) book = Book(str(book_id)) book.date = time.strftime(ISOTIMEFORMAT, time.localtime()) book.tags += tags.replace(' ', '') book.tags += ',' + str(self.now_url) if self.add_title_tag.isChecked(): book.tags += ',' + str(book.title) insert_library(book) return