mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04: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
@ -12,7 +12,7 @@ from future_builtins import map
|
|||||||
from math import floor
|
from math import floor
|
||||||
|
|
||||||
from PyQt4.Qt import (QObject, QPainter, Qt, QSize, QString, QTimer,
|
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 PyQt4.QtWebKit import QWebView, QWebPage, QWebSettings
|
||||||
|
|
||||||
from calibre import fit_image
|
from calibre import fit_image
|
||||||
@ -82,6 +82,7 @@ class Page(QWebPage): # {{{
|
|||||||
opts.pdf_sans_family)
|
opts.pdf_sans_family)
|
||||||
if opts.pdf_mono_family:
|
if opts.pdf_mono_family:
|
||||||
settings.setFontFamily(QWebSettings.FixedFont, opts.pdf_mono_family)
|
settings.setFontFamily(QWebSettings.FixedFont, opts.pdf_mono_family)
|
||||||
|
self.longjs_counter = 0
|
||||||
|
|
||||||
def javaScriptConsoleMessage(self, msg, lineno, msgid):
|
def javaScriptConsoleMessage(self, msg, lineno, msgid):
|
||||||
self.log.debug(u'JS:', unicode(msg))
|
self.log.debug(u'JS:', unicode(msg))
|
||||||
@ -89,8 +90,14 @@ class Page(QWebPage): # {{{
|
|||||||
def javaScriptAlert(self, frame, msg):
|
def javaScriptAlert(self, frame, msg):
|
||||||
self.log(unicode(msg))
|
self.log(unicode(msg))
|
||||||
|
|
||||||
|
@pyqtSlot(result=bool)
|
||||||
def shouldInterruptJavaScript(self):
|
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.paged_js += cc('ebooks.oeb.display.mathjax')
|
||||||
|
|
||||||
self.view.page().mainFrame().addToJavaScriptWindowObject("py_bridge", self)
|
self.view.page().mainFrame().addToJavaScriptWindowObject("py_bridge", self)
|
||||||
|
self.view.page().longjs_counter = 0
|
||||||
evaljs = self.view.page().mainFrame().evaluateJavaScript
|
evaljs = self.view.page().mainFrame().evaluateJavaScript
|
||||||
evaljs(self.paged_js)
|
evaljs(self.paged_js)
|
||||||
self.load_mathjax()
|
self.load_mathjax()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user