add option to webview to skip external browser open
This commit is contained in:
parent
1f4f5b8c45
commit
72609bee18
@ -26,6 +26,7 @@ class AnkiWebPage(QWebEnginePage):
|
|||||||
QWebEnginePage.__init__(self)
|
QWebEnginePage.__init__(self)
|
||||||
self._onBridgeCmd = onBridgeCmd
|
self._onBridgeCmd = onBridgeCmd
|
||||||
self._setupBridge()
|
self._setupBridge()
|
||||||
|
self.open_links_externally = True
|
||||||
|
|
||||||
def _setupBridge(self):
|
def _setupBridge(self):
|
||||||
class Bridge(QObject):
|
class Bridge(QObject):
|
||||||
@ -98,6 +99,9 @@ class AnkiWebPage(QWebEnginePage):
|
|||||||
sys.stdout.write(buf)
|
sys.stdout.write(buf)
|
||||||
|
|
||||||
def acceptNavigationRequest(self, url, navType, isMainFrame):
|
def acceptNavigationRequest(self, url, navType, isMainFrame):
|
||||||
|
if not self.open_links_externally:
|
||||||
|
return super().acceptNavigationRequest(url, navType, isMainFrame)
|
||||||
|
|
||||||
if not isMainFrame:
|
if not isMainFrame:
|
||||||
return True
|
return True
|
||||||
# data: links generated by setHtml()
|
# data: links generated by setHtml()
|
||||||
@ -238,6 +242,9 @@ class AnkiWebView(QWebEngineView):
|
|||||||
return False
|
return False
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def set_open_links_externally(self, enable: bool) -> None:
|
||||||
|
self._page.open_links_externally = enable
|
||||||
|
|
||||||
def onEsc(self):
|
def onEsc(self):
|
||||||
w = self.parent()
|
w = self.parent()
|
||||||
while w:
|
while w:
|
||||||
|
Loading…
Reference in New Issue
Block a user