add option to webview to skip external browser open

This commit is contained in:
Damien Elmes 2020-06-29 13:49:35 +10:00
parent 1f4f5b8c45
commit 72609bee18

View File

@ -26,6 +26,7 @@ class AnkiWebPage(QWebEnginePage):
QWebEnginePage.__init__(self)
self._onBridgeCmd = onBridgeCmd
self._setupBridge()
self.open_links_externally = True
def _setupBridge(self):
class Bridge(QObject):
@ -98,6 +99,9 @@ class AnkiWebPage(QWebEnginePage):
sys.stdout.write(buf)
def acceptNavigationRequest(self, url, navType, isMainFrame):
if not self.open_links_externally:
return super().acceptNavigationRequest(url, navType, isMainFrame)
if not isMainFrame:
return True
# data: links generated by setHtml()
@ -238,6 +242,9 @@ class AnkiWebView(QWebEngineView):
return False
return False
def set_open_links_externally(self, enable: bool) -> None:
self._page.open_links_externally = enable
def onEsc(self):
w = self.parent()
while w: