hgiesel / closet

The Web Framework for Flashcards
https://closetengine.com
GNU General Public License v3.0
65 stars 6 forks source link

doesn't work with Arthur's "Opening the same window multiple time" #59

Open ijgnd opened 3 years ago

ijgnd commented 3 years ago

It occures in 2.1.43 (binary from ankiweb) on linux (but I also had it with older anki versions, too).

When I just have "Closet" and Arthur's Opening the same window multiple time in my profile and I try to add a note in the add window I get the following error when clicking the "add" button:

Anki 2.1.43 (0fbae6bc) Python 3.8.1 Qt 5.15.1 PyQt 5.15.1
Platform: Linux
Flags: frz=True ao=True sv=2
Add-ons, last update check: 2021-04-11 23:27:19
Add-ons possibly involved: ⁨Closet For Anki⁩

Caught exception:
Traceback (most recent call last):
File "aqt/webview.py", line 526, in handler
File "aqt/editor.py", line 534, in <lambda>
File "aqt/addcards.py", line 193, in _addCards
File "aqt/addcards.py", line 172, in addNote
File "aqt/hooks_gen.py", line 103, in __call__
File "../addons21/272311064/src/addcards.py", line 18, in check_if_occlusion_editor_open
    if addcards.editor.occlusion_editor_active
AttributeError: 'NoneType' object has no attribute 'editor'

Your functions here uses the built in dict dialogs._dialogs whereas Arthur's add-on leaves this dict unused so that the first list index is always None (which triggers the error message) - instead Arthur uses a list of all open dialog in his dialogs._openDialogs. I guess a proper fix would be on Arthur's side but I have assumed so far that adjusting his add-on would be more complicated than creating a short function to detect Arthur's add-on.

 

 

Or maybe Anki should be modified?

Though the gui_hook "add_cards_will_add_note" was renamed and added about a year ago ago it's hardly used. I found it only in:

I guess you and Arthur could easily adjust your add-ons so just breaking compatibility alone should not rule out this change.

This hooks assumes that the note is coming from addCards window according to the description in genhooks_gui.py. So whenever Anki runs this hook there's an instance of addcards that could be passed to this hook. Maybe having this instance is useful for future add-ons (e.g. other add-ons could also create dialogs) so that a general solution that does not depend on the current implentation of the dialog manager would be useful?

hgiesel commented 3 years ago

I don't really like to add workarounds for other addons into mine, as it increases the complexity, and I typically won't know when the workaround will break.

@Arthur-Milchior I think the dialog_manager could use a get_active_dialog(name_of_dialog) kind of method, that could also have a hook for deciding which dialog to return. Maybe that's a way forward.

Arthur-Milchior commented 3 years ago

I've not looked at this for a long time, so I've no idea what you're talking about exactly. Can you please let me know whether you are suggesting me a change to my add-on, in which case I'd appreicate greatly if you can create an issue on it (or @ijgnd maybe ) or if it's a different way for anki to deal with opening window

I'm not really fan of the way windows are managed in anki but I don't really intend to do the change myself