mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Have show_browser() check for headless and complain
This commit is contained in:
parent
3fef8ee45f
commit
dd1df1cf4f
@ -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
|
||||||
|
@ -13,7 +13,8 @@ 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 (
|
||||||
|
QObject, QNetworkAccessManager, QNetworkDiskCache, QCoreApplication,
|
||||||
QNetworkProxy, QNetworkProxyFactory, QEventLoop, QUrl, pyqtSignal,
|
QNetworkProxy, QNetworkProxyFactory, QEventLoop, QUrl, pyqtSignal,
|
||||||
QDialog, QVBoxLayout, QSize, QNetworkCookieJar, Qt, pyqtSlot, QPixmap)
|
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.
|
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_()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user