Ebook Viewer: Support for printing entire book

This commit is contained in:
John Schember 2009-02-02 19:07:57 -05:00
parent 3a3a05be79
commit 38c92339bb

View File

@ -307,26 +307,60 @@ class DocumentView(QWebView):
def goto_bookmark(self, bm): def goto_bookmark(self, bm):
self.document.goto_bookmark(bm) self.document.goto_bookmark(bm)
def print_preview(self): def all_content(self):
printer = QPrinter(QPrinter.HighResolution) book_content = ''
printer.setPageMargins(1, 1, 1, 1, QPrinter.Inch)
previewDialog = QPrintPreviewDialog(printer, self) if self.manager is not None:
for path in self.manager.iterator.spine:
self.connect(previewDialog, SIGNAL('paintRequested(QPrinter *)'), self.print_) html = open(path, 'rb').read().decode(path.encoding)
previewDialog.exec_() book_content += EntityDeclarationProcessor(html).processed_html
self.disconnect(previewDialog, SIGNAL('paintRequested(QPrinter *)'), self.print_) base_url = QUrl.fromLocalFile(self.manager.iterator.spine[0])
else:
book_content = self.page().mainFrame().toHtml()
base_url = QUrl.fromLocalFile(self.path())
return (book_content, base_url)
def print_book(self): def print_preview(self):
printer = QPrinter(QPrinter.HighResolution) print_view = QWebView()
printer.setPageMargins(1, 1, 1, 1, QPrinter.Inch) book_content, base_url = self.all_content()
print_view.setHtml(book_content, base_url)
print_view.setTextSizeMultiplier(self.textSizeMultiplier())
def finished(ok):
printer = QPrinter(QPrinter.HighResolution)
printer.setPageMargins(1, 1, 1, 1, QPrinter.Inch)
previewDialog = QPrintPreviewDialog(printer, self)
self.connect(previewDialog, SIGNAL('paintRequested(QPrinter *)'), print_view.print_)
previewDialog.exec_()
self.disconnect(previewDialog, SIGNAL('paintRequested(QPrinter *)'), print_view.print_)
self.disconnect(print_view, SIGNAL('loadFinished(bool)'), finished)
self.connect(print_view, SIGNAL('loadFinished(bool)'), finished)
printDialog = QPrintDialog(printer, self) def print_book(self):
printDialog.setWindowTitle(_("Print eBook")) print_view = QWebView()
book_content, base_url = self.all_content()
printDialog.exec_() print_view.setHtml(book_content, base_url)
if printDialog.result() == QDialog.Accepted: print_view.setTextSizeMultiplier(self.textSizeMultiplier())
self.print_(printer)
def finished(ok):
printer = QPrinter(QPrinter.HighResolution)
printer.setPageMargins(1, 1, 1, 1, QPrinter.Inch)
printDialog = QPrintDialog(printer, self)
printDialog.setWindowTitle(_("Print eBook"))
printDialog.exec_()
if printDialog.result() == QDialog.Accepted:
print_view.print_(printer)
self.disconnect(print_view, SIGNAL('loadFinished(bool)'), finished)
self.connect(print_view, SIGNAL('loadFinished(bool)'), finished)
def config(self, parent=None): def config(self, parent=None):
self.document.do_config(parent) self.document.do_config(parent)