Have show_browser() check for headless and complain

This commit is contained in:
Kovid Goyal 2014-10-15 10:50:49 +05:30
parent 3fef8ee45f
commit dd1df1cf4f
2 changed files with 10 additions and 4 deletions

View File

@ -891,6 +891,7 @@ class Application(QApplication):
if not args: if not args:
args = sys.argv[:1] args = sys.argv[:1]
args.extend(['-platformpluginpath', sys.extensions_location, '-platform', 'headless']) args.extend(['-platformpluginpath', sys.extensions_location, '-platform', 'headless'])
self.headless = headless
qargs = [i.encode('utf-8') if isinstance(i, unicode) else i for i in args] qargs = [i.encode('utf-8') if isinstance(i, unicode) else i for i in args]
self.pi = plugins['progress_indicator'][0] self.pi = plugins['progress_indicator'][0]
QApplication.__init__(self, qargs) QApplication.__init__(self, qargs)
@ -1131,9 +1132,11 @@ def ensure_app():
with _ea_lock: with _ea_lock:
if _store_app is None and QApplication.instance() is None: if _store_app is None and QApplication.instance() is None:
args = sys.argv[:1] args = sys.argv[:1]
if islinux or isbsd: headless = islinux or isbsd
if headless:
args += ['-platformpluginpath', sys.extensions_location, '-platform', 'headless'] args += ['-platformpluginpath', sys.extensions_location, '-platform', 'headless']
_store_app = QApplication(args) _store_app = QApplication(args)
_store_app.headless = headless
import traceback import traceback
# This is needed because as of PyQt 5.4 if sys.execpthook == # This is needed because as of PyQt 5.4 if sys.execpthook ==
# sys.__excepthook__ PyQt will abort the application on an # sys.__excepthook__ PyQt will abort the application on an

View File

@ -13,9 +13,10 @@ from threading import current_thread
from PyQt5.QtWebKit import QWebSettings, QWebElement from PyQt5.QtWebKit import QWebSettings, QWebElement
from PyQt5.QtWebKitWidgets import QWebPage, QWebView from PyQt5.QtWebKitWidgets import QWebPage, QWebView
from PyQt5.Qt import (QObject, QNetworkAccessManager, QNetworkDiskCache, from PyQt5.Qt import (
QNetworkProxy, QNetworkProxyFactory, QEventLoop, QUrl, pyqtSignal, QObject, QNetworkAccessManager, QNetworkDiskCache, QCoreApplication,
QDialog, QVBoxLayout, QSize, QNetworkCookieJar, Qt, pyqtSlot, QPixmap) QNetworkProxy, QNetworkProxyFactory, QEventLoop, QUrl, pyqtSignal,
QDialog, QVBoxLayout, QSize, QNetworkCookieJar, Qt, pyqtSlot, QPixmap)
from calibre import USER_AGENT, prints, get_proxies, get_proxy_info, prepare_string_for_xml from calibre import USER_AGENT, prints, get_proxies, get_proxy_info, prepare_string_for_xml
from calibre.constants import ispy3, cache_dir from calibre.constants import ispy3, cache_dir
@ -681,6 +682,8 @@ class Browser(QObject, FormsMixin):
''' '''
Show the currently loaded web page in a window. Useful for debugging. Show the currently loaded web page in a window. Useful for debugging.
''' '''
if getattr(QCoreApplication.instance(), 'headless', False):
raise RuntimeError('Cannot show browser when running in a headless Qt application')
view = BrowserView(self.page) view = BrowserView(self.page)
view.exec_() view.exec_()