mirror of
git://github.com/kovidgoyal/calibre.git
synced 2026-05-09 01:43:26 +02:00
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:
parent
67903b743a
commit
0d7d575f29
1 changed files with 10 additions and 2 deletions
|
|
@ -12,7 +12,7 @@
|
|||
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 @@ def __init__(self, opts, log):
|
|||
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 @@ def javaScriptConsoleMessage(self, msg, lineno, msgid):
|
|||
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 @@ def do_paged_render(self):
|
|||
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()
|
||||
|
|
|
|||
Loading…
Reference in a new issue