delay setHtml() until previous page has fully loaded

based on 0241eb70dc
This commit is contained in:
Damien Elmes 2017-08-07 15:15:31 +10:00
parent b0213b9fd7
commit 9c63714e80

View file

@ -76,6 +76,7 @@ class AnkiWebView(QWebEngineView):
self._page = AnkiWebPage(self._onBridgeCmd) self._page = AnkiWebPage(self._onBridgeCmd)
self._domDone = True self._domDone = True
self._pendingJS = []
self.setPage(self._page) self.setPage(self._page)
self._page.profile().setHttpCacheType(QWebEngineProfile.NoCache) self._page.profile().setHttpCacheType(QWebEngineProfile.NoCache)
@ -139,11 +140,12 @@ class AnkiWebView(QWebEngineView):
pass pass
def setHtml(self, html): def setHtml(self, html):
if not self._domDone: if not self._domDone or self._pendingJS:
# defer update until previous page has initialized
if devMode: if devMode:
import traceback print("deferring setHtml() until page is ready")
print("ignoring setHtml() called before DOM ready") from aqt import mw
print("caller was", traceback.format_stack()[-3]) mw.progress.timer(25, lambda: self.setHtml(html), False)
return return
app = QApplication.instance() app = QApplication.instance()
oldFocus = app.focusWidget() oldFocus = app.focusWidget()