minimal_webkit_testbrowser: Add WebEngine support.
This commit is contained in:
parent
ca5a78dfc7
commit
a3776e361b
@ -28,6 +28,12 @@ from PyQt5.QtWidgets import QApplication
|
|||||||
from PyQt5.QtWebKit import QWebSettings
|
from PyQt5.QtWebKit import QWebSettings
|
||||||
from PyQt5.QtWebKitWidgets import QWebView
|
from PyQt5.QtWebKitWidgets import QWebView
|
||||||
|
|
||||||
|
try:
|
||||||
|
from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEngineSettings
|
||||||
|
WEBENGINE = True
|
||||||
|
except ImportError:
|
||||||
|
WEBENGINE = False
|
||||||
|
|
||||||
|
|
||||||
def parse_args():
|
def parse_args():
|
||||||
"""Parse commandline arguments."""
|
"""Parse commandline arguments."""
|
||||||
@ -35,6 +41,9 @@ def parse_args():
|
|||||||
parser.add_argument('url', help='The URL to open')
|
parser.add_argument('url', help='The URL to open')
|
||||||
parser.add_argument('--plugins', '-p', help='Enable plugins',
|
parser.add_argument('--plugins', '-p', help='Enable plugins',
|
||||||
default=False, action='store_true')
|
default=False, action='store_true')
|
||||||
|
if WEBENGINE:
|
||||||
|
parser.add_argument('--webengine', help='Use QtWebEngine',
|
||||||
|
default=False, action='store_true')
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
@ -42,12 +51,16 @@ if __name__ == '__main__':
|
|||||||
args = parse_args()
|
args = parse_args()
|
||||||
app = QApplication(sys.argv)
|
app = QApplication(sys.argv)
|
||||||
|
|
||||||
wv = QWebView()
|
if WEBENGINE and args.webengine:
|
||||||
|
wv = QWebEngineView()
|
||||||
|
else:
|
||||||
|
wv = QWebView()
|
||||||
|
|
||||||
wv.loadStarted.connect(lambda: print("Loading started"))
|
wv.loadStarted.connect(lambda: print("Loading started"))
|
||||||
wv.loadProgress.connect(lambda p: print("Loading progress: {}%".format(p)))
|
wv.loadProgress.connect(lambda p: print("Loading progress: {}%".format(p)))
|
||||||
wv.loadFinished.connect(lambda: print("Loading finished"))
|
wv.loadFinished.connect(lambda: print("Loading finished"))
|
||||||
|
|
||||||
if args.plugins:
|
if args.plugins and not WEBENGINE:
|
||||||
wv.settings().setAttribute(QWebSettings.PluginsEnabled, True)
|
wv.settings().setAttribute(QWebSettings.PluginsEnabled, True)
|
||||||
|
|
||||||
wv.load(QUrl.fromUserInput(args.url))
|
wv.load(QUrl.fromUserInput(args.url))
|
||||||
|
Loading…
Reference in New Issue
Block a user