diff --git a/src/calibre/utils/serve_coffee.py b/src/calibre/utils/serve_coffee.py index e85d102376..6548fec637 100644 --- a/src/calibre/utils/serve_coffee.py +++ b/src/calibre/utils/serve_coffee.py @@ -22,8 +22,7 @@ import time, BaseHTTPServer, os, sys, re, SocketServer from threading import Lock from SimpleHTTPServer import SimpleHTTPRequestHandler -from PyQt4.QtWebKit import QWebPage -from PyQt4.Qt import QThread, QApplication +from PyQt4.Qt import QCoreApplication, QScriptEngine, QScriptValue # Infrastructure {{{ def import_from_calibre(mod): @@ -35,23 +34,6 @@ def import_from_calibre(mod): return importlib.import_module(mod) _store_app = gui_thread = None -def check_qt(): - global gui_thread, _store_app - _plat = sys.platform.lower() - iswindows = 'win32' in _plat or 'win64' in _plat - isosx = 'darwin' in _plat - islinux = not (iswindows or isosx) - - if islinux and ':' not in os.environ.get('DISPLAY', ''): - raise RuntimeError('X server required. If you are running on a' - ' headless machine, use xvfb') - if _store_app is None and QApplication.instance() is None: - _store_app = QApplication([]) - if gui_thread is None: - gui_thread = QThread.currentThread() - if gui_thread is not QThread.currentThread(): - raise RuntimeError('Cannot use Qt in non GUI thread') - def fork_job(*args, **kwargs): try: return import_from_calibre('calibre.utils.ipc.simple_worker').fork_job(*args, @@ -77,48 +59,33 @@ def fork_job(*args, **kwargs): # }}} -class Compiler(QWebPage): # {{{ - - ''' - Never use this class in anything except the main thread. If you want to use - it from other threads, use the forked_compile method instead. - ''' +class Compiler(QScriptEngine): # {{{ def __init__(self): - check_qt() - QWebPage.__init__(self) - self.frame = self.mainFrame() - self.filename = self._src = '' - self.frame.evaluateJavaScript(CS_JS) - self.frame.addToJavaScriptWindowObject("cs_compiler", self) - self.errors = [] + if QCoreApplication.instance() is None: + self.__app_ = QCoreApplication([]) - def shouldInterruptJavaScript(self): - return True - - def javaScriptConsoleMessage(self, msg, lineno, sourceid): - sourceid = sourceid or self.filename or '