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:
|
||||
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
|
||||
|
@ -13,9 +13,10 @@ from threading import current_thread
|
||||
|
||||
from PyQt5.QtWebKit import QWebSettings, QWebElement
|
||||
from PyQt5.QtWebKitWidgets import QWebPage, QWebView
|
||||
from PyQt5.Qt import (QObject, QNetworkAccessManager, QNetworkDiskCache,
|
||||
QNetworkProxy, QNetworkProxyFactory, QEventLoop, QUrl, pyqtSignal,
|
||||
QDialog, QVBoxLayout, QSize, QNetworkCookieJar, Qt, pyqtSlot, QPixmap)
|
||||
from PyQt5.Qt import (
|
||||
QObject, QNetworkAccessManager, QNetworkDiskCache, QCoreApplication,
|
||||
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.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.
|
||||
'''
|
||||
if getattr(QCoreApplication.instance(), 'headless', False):
|
||||
raise RuntimeError('Cannot show browser when running in a headless Qt application')
|
||||
view = BrowserView(self.page)
|
||||
view.exec_()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user