glutanimate / image-occlusion-enhanced

Anki add-on that transforms images into cloze tests
https://ankiweb.net/shared/info/1374772155
Other
398 stars 41 forks source link

breaks other add-ons that use gui_hooks.editor_will_show_context_menu #151

Closed ijgnd closed 4 years ago

ijgnd commented 4 years ago

Problem description

IO overwrites the Anki Editor context menu and does not use the new style hooks. An add-on of mine uses gui_hooks.editor_will_show_context_menu.append(add_to_context). When combined with IO this hook never is executed. My temporary fix for IO.

Checklist

Please replace the space inside the brackets with an x if the following items apply:

Information about your Anki set-up

Anki 2.1.26 (70784154) Python 3.8.1 Qt 5.14.1 PyQt 5.14.1
Platform: Linux
Flags: frz=True ao=True sv=2
Add-ons, last update check: 2020-05-27 10:46:07

===Add-ons (active)===
(add-on provided name [Add-on folder, installed at, version, is config changed])
Image Occlusion Enhanced for Anki 21 alpha ['1374772155', 2020-04-28T04:21, 'None', '']
preview card or edit note in extra window linked from the reviewer ['1423933177', 2020-05-27T14:31, 'None', '']

===IDs of active AnkiWeb add-ons===
1374772155 1423933177

===Add-ons (inactive)===
(add-on provided name [Add-on folder, installed at, version, is config changed])
glutanimate commented 4 years ago

Good catch, thanks! Looks like addon-run hooks is one area where forwards compatibility doesn't really work.

Would you like to submit a PR for this? (it would have to maintain backwards compatibility, though) I'd be happy to push a quick fix otherwise.

ijgnd commented 4 years ago

It's better if you fix this: It's quicker and you know which level of backward compatibility you want (c.f. 2.0 compatibility which is still included in your contributing guidelines).

glutanimate commented 4 years ago

I can see that, yeah.

I've just pushed pushed a change to master that should address the context menu collision. If you could give it a try and let me know if it works for you, I'd really appreciate it. N.B.: There will likely be some follow-up commits migrating other parts of the add-on to the new hook system, so if you want to test this change specifically you might want to check out 0b74f69 directly.

Regarding the add-on compatibility level and contribution guidelines: Thanks for the reminder! I've added a note to update the guidelines and remove all references to Anki 2.0. I will work towards making this clearer in the future, but generally speaking: For most add-ons I'm targeting a compatibility level of 2.1.15+ (where 2.1.15+ compat generally also results in 2.1.10+ compat since few things changed in between).

Once I've reworked aab and other parts of my tooling it will hopefully be much clearer which compat level I'm targeting for each add-on.

ijgnd commented 4 years ago

Thanks.

I can test in the coming days.

As far as I see you can remove the custom context menu and rely on hooks only because the hooks were added in 2013 so that they are in each Anki 2.1 version. this is the line from the version that's tagged as 2.1.0 on github.

glutanimate commented 4 years ago

I faintly remember that the old-style hooks in that area were quite old, but I didn't bother checking. So thanks!

And now that you mention it, I must have been aware of the existence of the hook back when I implemented this, seeing how I did call the hook in the monkey-patched context menu. I can't remember why I went with this route exactly, but it might have been to avoid conflicts with other add-ons that do overwrite contextMenuEvent. So, ironically, it's possible that 0b74f69 will reintroduce this very issue for IO.

I'll have to canvas other add-ons to see if there are any conflicts left in this area. Since IO has to take some level of precedence due its widespread use, I might have to go back to patching contextMenuEvent, albeit with the adjusted call to gui_hooks.editor_will_show_context_menu on newer releases.

ijgnd commented 4 years ago

The original problem/motivation you had might no longer exist in 2.1: I ran rg -g '*.py' contextMenuEvent over the add-ons I have downloaded. In this folder I should have virtually all add-ons that are on ankiweb at the moment. These unfiltered results are at [1]. From skimming them it looks to me that only "Review Hotmouse" (1928346827) wraps or modifies contextMenuEvent. But "Review Hotmouse" should only affect the reviewer. So my guess is that todays' commit won't reintroduce the original issue.


[1]:

2018-01-01__775418273___Word Query/prepare.py
94:    anki.hooks.addHook('EditorWebView.contextMenuEvent', on_setup_menus)

2020-01-23__1899278645___editor apply font color background color custom class custom style/color_style_class_buttons.py
320:        addHook("EditorWebView.contextMenuEvent", add_to_context)

2020-04-17__864545277___Web Browser - Search terms Import texts and images automatically/review_controller.py
68:        addHook('AnkiWebView.contextMenuEvent', self.onReviewerHandle)

2020-04-17__864545277___Web Browser - Search terms Import texts and images automatically/browser_context_menu.py
47:    def contextMenuEvent(self, evt):

2020-04-17__864545277___Web Browser - Search terms Import texts and images automatically/editor_controller.py
35:        addHook('EditorWebView.contextMenuEvent', self.onEditorHandle)

2020-04-17__864545277___Web Browser - Search terms Import texts and images automatically/browser.py
238:        browser.contextMenuEvent = self._menuDelegator.contextMenuEvent

2020-04-07__1655992655___MIA Dictionary/main.py
1013:addHook("EditorWebView.contextMenuEvent", addToContextMenu)
1014:addHook("AnkiWebView.contextMenuEvent", addToContextMenu)

2020-04-07__1655992655___MIA Dictionary/cardExporter.py
21:    def contextMenuEvent(self, event):
40:    def contextMenuEvent(self, event):

2019-11-14__879473266___Open linked pdf docx epub audiovideo etc. in external Program/open_in_external.py
119:addHook("EditorWebView.contextMenuEvent", add_to_context)

2020-05-26__1928346827___Review Hotmouse/__init__.py
75:    "context_menu": lambda x="hotmouse_review": mw.web.contextMenuEvent(x),
205:def new_contextMenuEvent(self, i, _old):
242:    AnkiWebView.contextMenuEvent = wrap(
243:        AnkiWebView.contextMenuEvent, new_contextMenuEvent, "around"
249:addHook("AnkiWebView.contextMenuEvent", addTurnonAddon)

2019-11-14__422526650___Anki Browser Context Menu Search/browser_search.py
30:addHook("AnkiWebView.contextMenuEvent", add_lookup_action)
31:addHook("EditorWebView.contextMenuEvent", add_lookup_action)

2020-03-03__1410276506___Spelling Police/spellpopo.py
64:addHook("EditorWebView.contextMenuEvent", onContextMenuEvent)
65:addHook("AnkiWebView.contextMenuEvent", onContextMenuEvent)

2020-05-16__1765712663___editor paste raw unfiltered full html/__init__.py
92:addHook('EditorWebView.contextMenuEvent', editorContextMenu)

2018-11-10__233599752___Cronholio Cron Task Scheduler Beta2/cronholio.py
36:        addHook("Reviewer.contextMenuEvent", self.showContextMenu)

2020-02-27__880824023___Slackers Delight (PostponeDefer Button)/main.py
51:        addHook("Reviewer.contextMenuEvent", self.showContextMenu)

2020-03-05__278530045___MIA Japanese/gui.py
133:        self.ui.rulesTable.contextMenuEvent = self.customContextMenu

2020-03-05__278530045___MIA Japanese/main.py
233:addHook("EditorWebView.contextMenuEvent", addToContextMenu)

2019-02-11__359618071___Reviewer Context Menu Search/reviewer_context_search.py
82:addHook("AnkiWebView.contextMenuEvent", add_lookup_action)
83:addHook("EditorWebView.contextMenuEvent", add_lookup_action)

2020-04-05__1560623518___OpenInExternalEditorRenameDuplicate for ImageAudioVideo/edit_insert_rename_duplicate.py
157:addHook("EditorWebView.contextMenuEvent", add_to_context)
176:    addHook('AnkiWebView.contextMenuEvent', _reviewerContextMenu)

2020-04-29__1259478414___Markdown Support - With Batch n Preview/controller.py
134:        addHook('EditorWebView.contextMenuEvent', self._setupContextMenu)

2020-05-04__673114053___deck and card info sidebar during review/sidebar_base.py
70:                # def contextMenuEvent(self, evt):

2018-12-22__199420347___ReviewSymbols/__init__.py
50:addHook('AnkiWebView.contextMenuEvent', _reviewerContextMenu)

2019-01-13__427598962___AwesomeTTS for Anki 2.1 updated/awesometts/__init__.py
786:    anki.hooks.addHook('AnkiWebView.contextMenuEvent', on_context_menu)
787:    anki.hooks.addHook('EditorWebView.contextMenuEvent', on_context_menu)
788:    anki.hooks.addHook('Reviewer.contextMenuEvent',

2019-10-13__759018284___copy note contents to new Add window (from Browser Reviewer Add EditCurrent)/copycurrent.py
121:        addHook("AnkiWebView.contextMenuEvent", ReviewerContextMenu)
123:        addHook("EditorWebView.contextMenuEvent", EditorContextMenu)

2020-04-26__1049863218___No Distractions Full Screen Clean review interface  TabletTouch support/__init__.py
586:addHook("AnkiWebView.contextMenuEvent", on_context_menu_event)

2019-05-31__96435883___Export preview to HTML/__init__.py
7:def contextMenuEvent(webview, menu):
26:addHook('AnkiWebView.contextMenuEvent', contextMenuEvent)

2019-05-03__31746032___AnkiWebView Inspector/inspector.py
40:        addHook('AnkiWebView.contextMenuEvent', self.on_context_menu_event)
41:        addHook('EditorWebView.contextMenuEvent', self.on_context_menu_event)

2020-04-27__1135507717___Extended Tag AddEdit Dialog/__init__.py
237:addHook("EditorWebView.contextMenuEvent", EditorContextMenu)
287:addHook("AnkiWebView.contextMenuEvent", ReviewerContextMenu)

2020-05-25__319501851___pdf viewer/pdfjs.py
194:addHook("EditorWebView.contextMenuEvent", add_to_context)

2020-05-17__277081964___Quick note and deck change menus/new_change_notetype_deck.py
185:addHook('EditorWebView.contextMenuEvent', EditorContextMenu)

2020-05-17__277081964___Quick note and deck change menus/old_change_notetype_deck.py
176:addHook('EditorWebView.contextMenuEvent', EditorContextMenu)

2020-05-11__2028179508___remove linebreaks  do word wrap (fork for 2.1)/remove_linebreaks.py
118:    addHook("EditorWebView.contextMenuEvent", add_to_context)

2018-11-19__900455869___AwesomeTTS for Anki 2.1/__init__.py
777:    anki.hooks.addHook('AnkiWebView.contextMenuEvent', on_context_menu)
778:    anki.hooks.addHook('EditorWebView.contextMenuEvent', on_context_menu)
779:    anki.hooks.addHook('Reviewer.contextMenuEvent',

2019-06-23__1807206748___Fast Word Query Multi-threaded queries for words from local or web dictionaries/common.py
263:    addHook('EditorWebView.contextMenuEvent', on_setup_menus)

2018-10-27__580930132___Schedule Priority (customize intervals)/controller.py
24:        hooks.addHook('EditorWebView.contextMenuEvent', PriorityCardUiHandler.onEditorCtxMenu)
25:        hooks.addHook('AnkiWebView.contextMenuEvent', PriorityCardUiHandler.onReviewCtxMenu)
26:        hooks.addHook('Reviewer.contextMenuEvent', PriorityCardUiHandler.onReviewCtxMenu)

2018-08-31__281854631___Reviewer Context Menu/__init__.py
36:addHook('AnkiWebView.contextMenuEvent', _reviewerContextMenu)

2020-02-28__107041104___paste plainunformatted text/__init__.py
71:addHook('EditorWebView.contextMenuEvent', editorContextMenu)

2020-05-14__1972239816___Syntax Highlighting (Enhanced Fork)/syntax_highlighting.py
453:addHook('EditorWebView.contextMenuEvent', editorContextMenu)

2020-04-28__1043915942___extended editor for templates (with save and diff) and html source of fields/codemirror.py
344:        self.web.contextMenuEvent = self.contextMenuEvent

2018-05-12__907064139___Japanese Automatic Flashcard Creation (from Jisho.org) - Anki 2.1 port/__init__.py
361:addHook('EditorWebView.contextMenuEvent', nryContextMenuEvent)

2020-03-06__1593969147___Image Style Editor/__init__.py
26:EditorWebView.contextMenuEvent, profileLoaded
582:addHook("EditorWebView.contextMenuEvent", addToContextMenu)

2020-01-07__1095648795___CutCopy from editor to new note or add window (with scheduling)/shortcuts_menus.py
523:addHook('EditorWebView.contextMenuEvent', editorContextMenu)

2020-04-28__1374772155___Image Occlusion Enhanced for Anki 2.1 (alpha)/main.py
133:def contextMenuEvent(self, evt):
160:    runHook("EditorWebView.contextMenuEvent", self, m)
262:EditorWebView.contextMenuEvent = contextMenuEvent

2019-04-11__2006291407___rename image/rename_images_in_editor.py
81:addHook("EditorWebView.contextMenuEvent", add_to_context)

2020-06-04__805891399___extended editor for field (for tables searchreplace ...)/external_js_editor_for_field.py
217:        self.web.contextMenuEvent = self.contextMenuEvent

2020-06-01__814349176___AwesomeTTS (Google Cloud Text-to-Speech) unofficial/awesometts/__init__.py
793:    anki.hooks.addHook('AnkiWebView.contextMenuEvent', on_context_menu)
794:    anki.hooks.addHook('EditorWebView.contextMenuEvent', on_context_menu)
795:    anki.hooks.addHook('Reviewer.contextMenuEvent',

2019-06-12__2139632824___AwesomeTTS for Anki 2.1 updated again/awesometts/__init__.py
777:    anki.hooks.addHook('AnkiWebView.contextMenuEvent', on_context_menu)
778:    anki.hooks.addHook('EditorWebView.contextMenuEvent', on_context_menu)
779:    anki.hooks.addHook('Reviewer.contextMenuEvent',

2019-05-08__627484806___Web Query ()/WebQuery.py
261:    def contextMenuEvent(self, evt):
267:                super(_WebView, self).contextMenuEvent(evt)

2018-08-25__2099968349___Le Petit Debugger/hooktest.py
42:        # 'RCME':[False,'Reviewer.contextMenuEvent'],

2020-05-07__90397199___Preview Slideshow/slideshow_media_window.py
161:    def contextMenuEvent(self, event):

2019-11-18__829533913___Echelon - Improved Hierarchical Tags for Anki 2.1/echelon.py
113:    self.sidebarTree.contextMenuEvent = lambda x: customMenuEvent(self, x)

2019-04-11__333221628___editor - remove all formatting for selection (headings hyperlinks ...)/remove_all.py
36:    addHook("EditorWebView.contextMenuEvent", add_to_context)

2019-10-17__930944997___modified reviewer context search with browser search/reviewer_context_search.py
95:addHook("AnkiWebView.contextMenuEvent", add_lookup_action)
96:addHook("EditorWebView.contextMenuEvent", add_lookup_action)

2019-05-27__2059332871___Mac OSX Dictionary Lookup/__init__.py
46:addHook("AnkiWebView.contextMenuEvent", osx_dict.lookup_osx_action)

2018-09-17__1022577188___TagSelectorV2/__init__.py
767:    addHook("EditorWebView.contextMenuEvent",addShowDialogMenuItemInContextMenu)

2020-05-06__2107899486___Alternative Dialog for ReMemorize (Touch-Friendly)/alt_dialog_remem.py
57:    addHook('AnkiWebView.contextMenuEvent', reviewer_context_menu)

2019-01-01__2088508994___Toggle Tags via ReviewerEditorBrowser Context Menu/toggle_tags_via_context_menu.py
70:def ankiWebView_and_reviewer_contextMenuEvent_wrapper(self, menu):
78:def editorWebView_contextMenuEvent_wrapper(self, menu):
91:addHook("Reviewer.contextMenuEvent", ankiWebView_and_reviewer_contextMenuEvent_wrapper)
92:addHook("AnkiWebView.contextMenuEvent", ankiWebView_and_reviewer_contextMenuEvent_wrapper)
93:addHook("EditorWebView.contextMenuEvent", editorWebView_contextMenuEvent_wrapper)

2020-04-04__318752047___Add Hyperlink/add_hyperlinks.py
148:addHook("EditorWebView.contextMenuEvent", add_to_context)
167:    addHook('AnkiWebView.contextMenuEvent', _reviewerContextMenu)