Anki-Night-Mode icon indicating copy to clipboard operation
Anki-Night-Mode copied to clipboard

Compatibility issue with Arthur-Milchior/anki-fast-note-type-editor

Open Arthur-Milchior opened this issue 5 years ago • 3 comments

Problem description

Hi,

I'm the developper of the above-mentionned add-on. I received a bug report https://github.com/Arthur-Milchior/anki-fast-note-type-editor/issues/1 and the user realized it's a compatibility problem between your add-on and mine. I understand that the trouble is that, when night mode is turned on, aqt.clayout.CardLayout.init is redefined. We both redefine it, and of course, it starts to create trouble. However, I must admit I don't understand your code and would love to have an explanation about how it works. Then, I may hopefully either do a pull request to you, or change my code. My trouble is that I don't understand how aqt.clayout.CardLayout.init is changed. It seems that CardLayout is only used in CardLayoutStyler, which itself is never used anyone in your code.

Information about your Anki Setup

Version 2.1.7 (a6c34fd7) Qt 5.12.0 PyQt 5.11.3

Night Mode 2.2.3 OS: Ubuntu

If you have a compatibility problem with a specific add-on or add-ons, please paste the add-on page links below:

Backtrace (if any)

Caught exception:
File "C:\Users\John Smith\AppData\Roaming\Anki2\addons21\802285486\clayout.py", line 107, in reject
self.mm.save(self.model, templates=True, oldModel = self.originalModel, newTemplatesData = self.newTemplatesData)
<class 'AttributeError'>: 'CardLayout' object has no attribute 'originalModel'```

</details>

Arthur-Milchior avatar Feb 15 '19 15:02 Arthur-Milchior

Hi @Arthur-Milchior, thanks for letting me know! Just quickly:

  • my wraps are implemented in internals.py.
  • the conficting styler is CardLayoutStyler (we both owerride CardLayout.init):

https://github.com/krassowski/Anki-Night-Mode/blob/a127d60493dae9bad55830421cf7735d13e6f701/night_mode/stylers.py#L697-L723

  • the CardLayoutStyler is managed by a metaclass from internals (linked above) - a cool concept in advanced Python, though I am afraid that studying it may not help solving this problem
  • disabling CardLayout by View → Night Mode → Choose what to style may supress the issue
  • I think that ultimately it comes down to which addon gets loaded first - possibly making your add-on load before mine would solve the issue, but I have no idea how to force it
  • or you could try to re-wrap with CardLayout.__init__ from another function (like in run-time), or possibly hacking a way around and moving the logic elsewhere.

Please, let me know if it helps - I am happy to assist you with finding a solution (though this month is though, expect delayed responses).

PS. I've just moved contents in your post around as originally the main text was collapsed in the "Details" section and therefore invisible.

krassowski avatar Feb 17 '19 17:02 krassowski

There is a simple and dirty way to force the sorting. I can force my add-on to change the number of its folder, since the loading order is simply decided by the id of the add-on. But I prefer to avoid doing this, it may quickly become far too complicated for what it's worth.

The other solution would be to modify each class calling CardLayout(). Which means that the add-on may become incompatible in yet other way with other add-on, so I don't believe it's such a good idea. Thus, I guess I'll just let the add-on be incompatible and write a message on the Readme page.

I've never heard of metaclass. I've not yet read the whole python documentation. Thanks for letting me know it exists.

Arthur-Milchior avatar Feb 17 '19 18:02 Arthur-Milchior

Thus, I guess I'll just let the add-on be incompatible and write a message on the Readme page.

Just out of curiosity, did disabling Card Layout in View → Night Mode → Choose what to style help?

krassowski avatar Feb 17 '19 18:02 krassowski