diff --git a/src/calibre/ebooks/lrf/comic/convert_from.py b/src/calibre/ebooks/lrf/comic/convert_from.py index 0569bf3733..c22f1745ae 100755 --- a/src/calibre/ebooks/lrf/comic/convert_from.py +++ b/src/calibre/ebooks/lrf/comic/convert_from.py @@ -10,11 +10,6 @@ Based on ideas from comiclrf created by FangornUK. import os, sys, shutil, traceback, textwrap from uuid import uuid4 -try: - from reportlab.pdfgen import canvas - _reportlab = True -except: - _reportlab = False @@ -396,10 +391,9 @@ def create_lrf(pages, profile, opts, thumbnail=None): def create_pdf(pages, profile, opts, thumbnail=None): width, height = PROFILES[profile] - - if not _reportlab: - raise RuntimeError('Failed to load reportlab') - + + from reportlab.pdfgen import canvas + pdf = canvas.Canvas(filename=opts.output, pagesize=(width,height+15)) pdf.setAuthor(opts.author) pdf.setTitle(opts.title) diff --git a/src/calibre/gui2/dialogs/progress.py b/src/calibre/gui2/dialogs/progress.py new file mode 100644 index 0000000000..2543cefb4d --- /dev/null +++ b/src/calibre/gui2/dialogs/progress.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python +__license__ = 'GPL v3' +__copyright__ = '2009, Kovid Goyal kovid@kovidgoyal.net' +__docformat__ = 'restructuredtext en' + +'''''' + +from PyQt4.Qt import QDialog, SIGNAL, Qt + +from calibre.gui2.dialogs.progress_ui import Ui_Dialog + +class ProgressDialog(QDialog, Ui_Dialog): + + def __init__(self, title, msg='', min=0, max=99, parent=None): + QDialog.__init__(self, parent) + self.setupUi(self) + self.setWindowTitle(title) + self.title.setText(title) + self.message.setText(msg) + self.setWindowModality(Qt.ApplicationModal) + self.set_min(min) + self.set_max(max) + self.canceled = False + + self.connect(self.button_box, SIGNAL('rejected()'), self._canceled) + + def set_msg(self, msg=''): + self.message.setText(msg) + + def set_value(self, val): + self.bar.setValue(val) + + def set_min(self, min): + self.bar.setMinimum(min) + + def set_max(self, max): + self.bar.setMaximum(max) + + def _canceled(self, *args): + self.canceled = True + self.button_box.setDisabled(True) + self.title.setText(_('Aborting...')) + + def keyPressEvent(self, ev): + if ev.key() == Qt.Key_Escape: + self._canceled() + else: + QDialog.keyPressEvent(self, ev) \ No newline at end of file diff --git a/src/calibre/gui2/dialogs/progress.ui b/src/calibre/gui2/dialogs/progress.ui new file mode 100644 index 0000000000..60488be62d --- /dev/null +++ b/src/calibre/gui2/dialogs/progress.ui @@ -0,0 +1,72 @@ + + Dialog + + + + 0 + 0 + 712 + 308 + + + + Dialog + + + + :/images/jobs.svg:/images/jobs.svg + + + + + + + 75 + true + + + + TextLabel + + + Qt::AlignCenter + + + true + + + + + + + 0 + + + + + + + TextLabel + + + Qt::AlignCenter + + + true + + + + + + + QDialogButtonBox::Abort + + + + + + + + + + diff --git a/src/calibre/gui2/library.py b/src/calibre/gui2/library.py index 792d011883..8a737fd608 100644 --- a/src/calibre/gui2/library.py +++ b/src/calibre/gui2/library.py @@ -198,13 +198,18 @@ class BooksModel(QAbstractTableModel): ''' Return list indices of all cells in index.row()''' return [ self.index(index.row(), c) for c in range(self.columnCount(None))] - def save_to_disk(self, rows, path, single_dir=False, single_format=None): + def save_to_disk(self, rows, path, single_dir=False, single_format=None, + callback=None): rows = [row.row() for row in rows] if single_format is None: - return self.db.export_to_dir(path, rows, self.sorted_on[0] == 'authors', - single_dir=single_dir) + return self.db.export_to_dir(path, rows, + self.sorted_on[0] == 'authors', + single_dir=single_dir, + callback=callback) else: - return self.db.export_single_format_to_dir(path, rows, single_format) + return self.db.export_single_format_to_dir(path, rows, + single_format, + callback=callback) def delete_books(self, indices): diff --git a/src/calibre/gui2/main.py b/src/calibre/gui2/main.py index 6ff5df412d..b04ad18c97 100644 --- a/src/calibre/gui2/main.py +++ b/src/calibre/gui2/main.py @@ -28,6 +28,7 @@ from calibre.gui2.cover_flow import CoverFlow, DatabaseImages, pictureflowerror from calibre.library.database import LibraryDatabase from calibre.gui2.dialogs.scheduler import Scheduler from calibre.gui2.update import CheckForUpdates +from calibre.gui2.dialogs.progress import ProgressDialog from calibre.gui2.main_window import MainWindow, option_parser as _option_parser from calibre.gui2.main_ui import Ui_MainWindow from calibre.gui2.device import DeviceManager @@ -598,29 +599,26 @@ class Main(MainWindow, Ui_MainWindow): root = choose_dir(self, 'recursive book import root dir dialog', 'Select root folder') if not root: return - progress = QProgressDialog('', '&'+_('Stop'), - 0, 0, self) - progress.setWindowModality(Qt.ApplicationModal) - progress.setWindowTitle(_('Adding books recursively...')) + progress = ProgressDialog(_('Adding books recursively...'), + min=0, max=0, parent=self) progress.show() def callback(msg): if msg != '.': - progress.setLabelText((_('Added ')+msg) if msg else _('Searching...')) - stop = progress.wasCanceled() + progress.set_msg((_('Added ')+msg) if msg else _('Searching...')) QApplication.processEvents() QApplication.sendPostedEvents() QApplication.flush() - return stop + return progress.canceled try: duplicates = self.library_view.model().db.recursive_import(root, single, callback=callback) finally: - progress.hide() - progress.close() + progress.hide() if duplicates: files = _('

Books with the same title as the following already exist in the database. Add them anyway?

', self) + d = WarningDialog(_('Duplicates found!'), _('Duplicates found!'), + files+'

', self) if d.exec_() == QDialog.Accepted: for mi, formats in duplicates: self.library_view.model().db.import_book(mi, formats ) @@ -686,15 +684,13 @@ class Main(MainWindow, Ui_MainWindow): return # Get format and metadata information formats, metadata, names, infos = [], [], [], [] - progress = QProgressDialog(_('Reading metadata...'), _('Stop'), 0, len(paths), self) - progress.setWindowTitle(_('Adding books...')) - progress.setWindowModality(Qt.ApplicationModal) - progress.setLabelText(_('Reading metadata...')) + progress = ProgressDialog(_('Adding books...'), _('Reading metadata...'), + min=0, max=len(paths), parent=self) progress.show() try: for c, book in enumerate(paths): - progress.setValue(c) - if progress.wasCanceled(): + progress.set_value(c) + if progress.canceled: return format = os.path.splitext(book)[1] format = format[1:] if format else None @@ -713,15 +709,14 @@ class Main(MainWindow, Ui_MainWindow): infos.append({'title':mi.title, 'authors':', '.join(mi.authors), 'cover':self.default_thumbnail, 'tags':[]}) title = mi.title if isinstance(mi.title, unicode) else mi.title.decode(preferred_encoding, 'replace') - progress.setLabelText(_('Read metadata from ')+title) + progress.set_msg(_('Read metadata from ')+title) if not to_device: - progress.setLabelText(_('Adding books to database...')) + progress.set_msg(_('Adding books to database...')) model = self.library_view.model() paths = list(paths) duplicates, number_added = model.add_books(paths, formats, metadata) - progress.cancel() if duplicates: files = _('

Books with the same title as the following already exist in the database. Add them anyway?