Make testbrowser.py run without QtWebKit
This commit is contained in:
parent
7592345b6e
commit
c503c2953d
@ -25,14 +25,16 @@ import argparse
|
||||
|
||||
from PyQt5.QtCore import QUrl
|
||||
from PyQt5.QtWidgets import QApplication
|
||||
from PyQt5.QtWebKit import QWebSettings
|
||||
from PyQt5.QtWebKitWidgets import QWebView
|
||||
|
||||
try:
|
||||
from PyQt5.QtWebKitWidgets import QWebView
|
||||
except ImportError:
|
||||
QWebView = None
|
||||
|
||||
try:
|
||||
from PyQt5.QtWebEngineWidgets import QWebEngineView
|
||||
WEBENGINE = True
|
||||
except ImportError:
|
||||
WEBENGINE = False
|
||||
QWebEngineView = None
|
||||
|
||||
|
||||
def parse_args():
|
||||
@ -41,7 +43,7 @@ def parse_args():
|
||||
parser.add_argument('url', help='The URL to open')
|
||||
parser.add_argument('--plugins', '-p', help='Enable plugins',
|
||||
default=False, action='store_true')
|
||||
if WEBENGINE:
|
||||
if QWebEngineView is not None:
|
||||
parser.add_argument('--webengine', help='Use QtWebEngine',
|
||||
default=False, action='store_true')
|
||||
return parser.parse_args()
|
||||
@ -51,16 +53,29 @@ if __name__ == '__main__':
|
||||
args = parse_args()
|
||||
app = QApplication(sys.argv)
|
||||
|
||||
if WEBENGINE and args.webengine:
|
||||
if QWebView is None and QWebEngineView is None:
|
||||
print("Found no suitable backend to run with!")
|
||||
sys.exit(1)
|
||||
elif QWebView is None and not args.webengine:
|
||||
print("Using QtWebEngine because QtWebKit is unavailable")
|
||||
wv = QWebEngineView()
|
||||
using_webengine = True
|
||||
elif args.webengine:
|
||||
if QWebEngineView is None:
|
||||
print("Requested QtWebEngine, but it could not be imported!")
|
||||
sys.exit(1)
|
||||
wv = QWebEngineView()
|
||||
using_webengine = True
|
||||
else:
|
||||
wv = QWebView()
|
||||
using_webengine = False
|
||||
|
||||
wv.loadStarted.connect(lambda: print("Loading started"))
|
||||
wv.loadProgress.connect(lambda p: print("Loading progress: {}%".format(p)))
|
||||
wv.loadFinished.connect(lambda: print("Loading finished"))
|
||||
|
||||
if args.plugins and not WEBENGINE:
|
||||
if args.plugins and not using_webengine:
|
||||
from PyQt5.QtWebKit import QWebSettings
|
||||
wv.settings().setAttribute(QWebSettings.PluginsEnabled, True)
|
||||
|
||||
wv.load(QUrl.fromUserInput(args.url))
|
||||
|
Loading…
Reference in New Issue
Block a user