mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
avoid errors caused by calling setHtml() before previous page loaded
This commit is contained in:
parent
0543a4533b
commit
cd76281695
1 changed files with 10 additions and 2 deletions
|
@ -6,7 +6,7 @@ import sys
|
||||||
from anki.hooks import runHook
|
from anki.hooks import runHook
|
||||||
from aqt.qt import *
|
from aqt.qt import *
|
||||||
from aqt.utils import openLink
|
from aqt.utils import openLink
|
||||||
from anki.utils import isMac, isWin
|
from anki.utils import isMac, isWin, devMode
|
||||||
|
|
||||||
# Page for debug messages
|
# Page for debug messages
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
@ -74,7 +74,7 @@ class AnkiWebView(QWebEngineView):
|
||||||
self.title = "default"
|
self.title = "default"
|
||||||
self._page = AnkiWebPage(self._onBridgeCmd)
|
self._page = AnkiWebPage(self._onBridgeCmd)
|
||||||
|
|
||||||
self._loadFinishedCB = None
|
self._domDone = True
|
||||||
self.setPage(self._page)
|
self.setPage(self._page)
|
||||||
|
|
||||||
self._page.profile().setHttpCacheType(QWebEngineProfile.NoCache)
|
self._page.profile().setHttpCacheType(QWebEngineProfile.NoCache)
|
||||||
|
@ -138,8 +138,15 @@ class AnkiWebView(QWebEngineView):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def setHtml(self, html):
|
def setHtml(self, html):
|
||||||
|
if not self._domDone:
|
||||||
|
if devMode:
|
||||||
|
import traceback
|
||||||
|
print("ignoring setHtml() called before DOM ready")
|
||||||
|
print("caller was", traceback.format_stack()[-3])
|
||||||
|
return
|
||||||
app = QApplication.instance()
|
app = QApplication.instance()
|
||||||
oldFocus = app.focusWidget()
|
oldFocus = app.focusWidget()
|
||||||
|
self._domDone = False
|
||||||
self._page.setHtml(html)
|
self._page.setHtml(html)
|
||||||
# work around webengine stealing focus on setHtml()
|
# work around webengine stealing focus on setHtml()
|
||||||
if oldFocus:
|
if oldFocus:
|
||||||
|
@ -227,6 +234,7 @@ document.addEventListener("keydown", function(evt) {
|
||||||
|
|
||||||
def _onBridgeCmd(self, cmd):
|
def _onBridgeCmd(self, cmd):
|
||||||
if cmd == "domDone":
|
if cmd == "domDone":
|
||||||
|
self._domDone = True
|
||||||
self.onLoadFinished()
|
self.onLoadFinished()
|
||||||
else:
|
else:
|
||||||
self.onBridgeCmd(cmd)
|
self.onBridgeCmd(cmd)
|
||||||
|
|
Loading…
Reference in a new issue