PDF Output: Fix javascript dialog box popping up in the middle on converting very long documents. Fixes #1154948 (JavaScript Problem while generating PDF in 0.9.22)

This commit is contained in:
Kovid Goyal 2013-03-14 12:01:15 +05:30
parent 67903b743a
commit 0d7d575f29

View File

@ -12,7 +12,7 @@ from future_builtins import map
from math import floor
from PyQt4.Qt import (QObject, QPainter, Qt, QSize, QString, QTimer,
pyqtProperty, QEventLoop, QPixmap, QRect)
pyqtProperty, QEventLoop, QPixmap, QRect, pyqtSlot)
from PyQt4.QtWebKit import QWebView, QWebPage, QWebSettings
from calibre import fit_image
@ -82,6 +82,7 @@ class Page(QWebPage): # {{{
opts.pdf_sans_family)
if opts.pdf_mono_family:
settings.setFontFamily(QWebSettings.FixedFont, opts.pdf_mono_family)
self.longjs_counter = 0
def javaScriptConsoleMessage(self, msg, lineno, msgid):
self.log.debug(u'JS:', unicode(msg))
@ -89,8 +90,14 @@ class Page(QWebPage): # {{{
def javaScriptAlert(self, frame, msg):
self.log(unicode(msg))
@pyqtSlot(result=bool)
def shouldInterruptJavaScript(self):
return False
if self.longjs_counter < 5:
self.log('Long running javascript, letting it proceed')
self.longjs_counter += 1
return False
self.log.warn('Long running javascript, aborting it')
return True
# }}}
@ -275,6 +282,7 @@ class PDFWriter(QObject):
self.paged_js += cc('ebooks.oeb.display.mathjax')
self.view.page().mainFrame().addToJavaScriptWindowObject("py_bridge", self)
self.view.page().longjs_counter = 0
evaljs = self.view.page().mainFrame().evaluateJavaScript
evaljs(self.paged_js)
self.load_mathjax()