Arthur-Milchior / anki-keep-model-in-add-cards

The model in «new» window is fixed, unless you change it explicitly
GNU General Public License v3.0
2 stars 0 forks source link

'NoneType' object has no attribute 'evalWithCallback' #4

Closed ijgnd closed 4 years ago

ijgnd commented 4 years ago

Thanks for keeping this add-on alive!

Your most recent update fixes #2 but now I get an error when I try to close an Add window. See the screencast/gif below.

I tried with the packaged version 2.1.25 for linux from apps.ankiweb and your add-ons Opening the same window multiple time and Keep model of add cards that I installed today into a new profile. I've looked into this for about an hour now and still don't have a solution. So I posted this issue.

The full error message is:

Anki 2.1.25 (898801eb) Python 3.8.1 Qt 5.14.1 PyQt 5.14.1
Platform: Linux
Flags: frz=True ao=True sv=1
Add-ons, last update check: 2020-05-02 14:17:57
Add-ons possibly involved: ⁨Keep model of add cards⁩

Caught exception:
Traceback (most recent call last):
File "aqt/webview.py", line 464, in handler
File "aqt/editor.py", line 475, in <lambda>
File "aqt/addcards.py", line 248, in afterSave
File "aqt/addcards.py", line 237, in _reject
File "aqt/main.py", line 688, in maybeReset
File "aqt/main.py", line 669, in reset
File "aqt/gui_hooks.py", line 1838, in __call__
File "../Anki2/addons21/424778276/addCards.py", line 57, in onReset
    self.setAndFocusNote(note)
File "aqt/addcards.py", line 92, in setAndFocusNote
File "aqt/editor.py", line 425, in setNote
File "aqt/editor.py", line 460, in loadNote
AttributeError: 'NoneType' object has no attribute 'evalWithCallback'

Before I made this problem description that documents the steps I took I also ran into these errors when trying to close an add window where I didn't document exactly on how to reproduce them. Maybe these are also useful for you.

Caught exception:
Traceback (most recent call last):
File "aqt/webview.py", line 464, in handler
File "aqt/editor.py", line 475, in <lambda>
File "aqt/addcards.py", line 248, in afterSave
File "aqt/addcards.py", line 237, in _reject
File "aqt/main.py", line 688, in maybeReset
File "aqt/main.py", line 669, in reset
File "aqt/gui_hooks.py", line 1838, in __call__
File ../Anki2/addons21/424778276/addCards.py", line 62, in onResetSameModel
    return self.onReset(model=self.editor.note._model, keep=keep)
File "../Anki2/addons21/424778276/addCards.py", line 57, in onReset
    self.setAndFocusNote(note)
File "aqt/addcards.py", line 92, in setAndFocusNote
File "aqt/editor.py", line 425, in setNote
File "aqt/editor.py", line 441, in loadNote
RuntimeError: wrapped C/C++ object of type QWidget has been deleted

and this (this occured after a note type change in the add window):

Caught exception:
Traceback (most recent call last):
File "aqt/webview.py", line 464, in handler
File "aqt/editor.py", line 475, in <lambda>
File "aqt/addcards.py", line 244, in afterSave
File "aqt/editor.py", line 503, in fieldsAreBlank
IndexError: list index out of range

Once more: Thanks for creating and maintaining these essential add-ons!

Arthur-Milchior commented 4 years ago

Thank you for this exhaustive report. I'm surprised that the second error is new. There is very little I can do, because it's related to the way anki deal with windows. I'm hacking the system which is made for a single window in order to open multiple window. Doing it correctly without error about "Wrapped C/C++" would require to rewrite far too much things.

The first error should be corrected now. I've no idea yet for the last one. It's probably related to the current add-on, but I have no precise idea

Arthur-Milchior commented 4 years ago

Please update and let me know whether it got better: first problem should have disappeared

ijgnd commented 4 years ago

Thank you so much for this update. I'm not sure how long I would have taken me to figure this out (if ever). Now it mostly works for me. I could produce this error when closing a dialog.

Caught exception:
Traceback (most recent call last):
File "aqt/webview.py", line 464, in handler
File "aqt/editor.py", line 475, in <lambda>
File "aqt/addcards.py", line 248, in afterSave
File "aqt/addcards.py", line 237, in _reject
File "aqt/main.py", line 688, in maybeReset
File "aqt/main.py", line 669, in reset
File "aqt/gui_hooks.py", line 1838, in __call__
File "../Anki2/addons21/424778276/addCards.py", line 64, in onResetSameModel
    return self.onReset(model=self.editor.note._model, keep=keep)
AttributeError: 'NoneType' object has no attribute '_model'

At the moment I'm trying out this minimal change to onResetSameModel and so far it seems to work:

from

return self.onReset(model=self.editor.note._model, keep=keep)

to:

model = None
if self.editor.note:
    model = self.editor.note._model
return self.onReset(model=model, keep=keep)

btw: for creating the gifs I use peek.

Arthur-Milchior commented 4 years ago

please update. Not perfect, but should be better already

ijgnd commented 4 years ago

works now for me. Thanks for the quick fix.