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,17 +307,47 @@ class DocumentView(QWebView):
def goto_bookmark(self, bm):
self.document.goto_bookmark(bm)
def all_content(self):
book_content = ''
if self.manager is not None:
for path in self.manager.iterator.spine:
html = open(path, 'rb').read().decode(path.encoding)
book_content += EntityDeclarationProcessor(html).processed_html
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_preview(self):
print_view = QWebView()
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 *)'), self.print_)
self.connect(previewDialog, SIGNAL('paintRequested(QPrinter *)'), print_view.print_)
previewDialog.exec_()
self.disconnect(previewDialog, SIGNAL('paintRequested(QPrinter *)'), self.print_)
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)
def print_book(self):
print_view = QWebView()
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)
@ -326,7 +356,11 @@ class DocumentView(QWebView):
printDialog.exec_()
if printDialog.result() == QDialog.Accepted:
self.print_(printer)
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):
self.document.do_config(parent)