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:
args = sys.argv[:1]
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]
self.pi = plugins['progress_indicator'][0]
QApplication.__init__(self, qargs)
@ -1131,9 +1132,11 @@ def ensure_app():
with _ea_lock:
if _store_app is None and QApplication.instance() is None:
args = sys.argv[:1]
if islinux or isbsd:
headless = islinux or isbsd
if headless:
args += ['-platformpluginpath', sys.extensions_location, '-platform', 'headless']
_store_app = QApplication(args)
_store_app.headless = headless
import traceback
# This is needed because as of PyQt 5.4 if sys.execpthook ==
# sys.__excepthook__ PyQt will abort the application on an

View File

@ -13,7 +13,8 @@ from threading import current_thread
from PyQt5.QtWebKit import QWebSettings, QWebElement
from PyQt5.QtWebKitWidgets import QWebPage, QWebView
from PyQt5.Qt import (QObject, QNetworkAccessManager, QNetworkDiskCache,
from PyQt5.Qt import (
QObject, QNetworkAccessManager, QNetworkDiskCache, QCoreApplication,
QNetworkProxy, QNetworkProxyFactory, QEventLoop, QUrl, pyqtSignal,
QDialog, QVBoxLayout, QSize, QNetworkCookieJar, Qt, pyqtSlot, QPixmap)
@ -681,6 +682,8 @@ class Browser(QObject, FormsMixin):
'''
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.exec_()