From f78166cda2c409d2f7bd32e3c4924f1340e34e76 Mon Sep 17 00:00:00 2001 From: evandrocoan Date: Wed, 27 May 2020 14:40:36 -0300 Subject: [PATCH] Fixed previewer.py::render_card() being called twice in row Related to: https://github.com/ankitects/anki/pull 529 Ensuring "setNote" is called only once during changing of note type After debugging the code, every time the cards changes, there are two stacktraces generated and triggered when note cards change: calling 1590591251.4621403 File "qt/runanki", line 4, in File "F:\anki\qt\aqt\__init__.py", line 365, in run _run() File "F:\anki\qt\aqt\__init__.py", line 515, in _run app.exec() File "F:\anki\qt\aqt\webview.py", line 467, in handler cb(val) File "F:\anki\qt\aqt\editor.py", line 477, in self.web.evalWithCallback("saveNow(%d)" % keepFocus, lambda res: callback()) File "F:\anki\qt\aqt\browser.py", line 858, in self.editor.saveNow(lambda: self._onRowChanged(current, previous)) File "F:\anki\qt\aqt\browser.py", line 880, in _onRowChanged self._renderPreview(True) File "F:\anki\qt\aqt\browser.py", line 1576, in _renderPreview self._previewer.render_card(cardChanged) File "F:\anki\qt\aqt\previewer.py", line 136, in render_card print('calling', time.time(), "\n", "".join( traceback.format_stack() ) ) calling 1590591251.4766161 File "qt/runanki", line 4, in File "F:\anki\qt\aqt\__init__.py", line 365, in run _run() File "F:\anki\qt\aqt\__init__.py", line 515, in _run app.exec() File "F:\anki\qt\aqt\webview.py", line 467, in handler cb(val) File "F:\anki\qt\aqt\editor.py", line 453, in oncallback gui_hooks.editor_did_load_note(self) File "F:\anki\qt\aqt\gui_hooks.py", line 1168, in __call__ hook(editor) File "F:\anki\qt\aqt\browser.py", line 887, in onLoadNote self.refreshCurrentCard(editor.note) File "F:\anki\qt\aqt\browser.py", line 884, in refreshCurrentCard self._renderPreview(False) File "F:\anki\qt\aqt\browser.py", line 1576, in _renderPreview self._previewer.render_card(cardChanged) File "F:\anki\qt\aqt\previewer.py", line 136, in render_card print('calling', time.time(), "\n", "".join( traceback.format_stack() ) ) --- qt/aqt/browser.py | 1 - 1 file changed, 1 deletion(-) diff --git a/qt/aqt/browser.py b/qt/aqt/browser.py index 4cf2b5bd0..5d6affd47 100644 --- a/qt/aqt/browser.py +++ b/qt/aqt/browser.py @@ -880,7 +880,6 @@ QTableView {{ gridline-color: {grid} }} def refreshCurrentCard(self, note: Note) -> None: self.model.refreshNote(note) - self._renderPreview(False) def onLoadNote(self, editor): self.refreshCurrentCard(editor.note)