Enhacement Request: plugins in context menu of tag browser

Bug #1936472 reported by capink
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
calibre
Fix Released
Undecided
Charles Haley

Bug Description

Would be nice if plugins can add their own entries to the tag browser context menu, in the same way plugins have their entries in the library view context menu. I can do this by editing the source and adding the following:

def add_plugins_tag_browser_menu_action(gui, index, context_menu):
    print('Adding plugins tag browser context action')
    for ac in gui.iactions.values():
        try:
            if hasattr(ac, 'tag_browser_context_action'):
                context_action = ac.tag_browser_context_action(index)
                if context_action:
                    context_menu.addAction(context_action)
        except Exception:
            import traceback
            traceback.print_exc()

The plugin will use the index to determine whether it have any action for this particular node, if it does the method returns a QAction, otherwise, it returns None.

It would be easier if something like this is included in calibre without having to edit the source.

Revision history for this message
Charles Haley (cbhaley) wrote :

Where do you put that code? In gui2.tag_browser.view?

Revision history for this message
capink (capink-eg) wrote :

Yes. I modified gui2.tag_browser.view as in the attachment.

Revision history for this message
Charles Haley (cbhaley) wrote :

@kovid: I will do this unless you object to it.

Changed in calibre:
assignee: nobody → Charles Haley (cbhaley)
Revision history for this message
Kovid Goyal (kovid) wrote : Re: calibre bug 1936472

Fine by me

Revision history for this message
Charles Haley (cbhaley) wrote :

@capink: Does this work? I can't test it.

Revision history for this message
capink (capink-eg) wrote :

It works but the entry is in the expand or collapse menu (see attached screen). I think it should be self.context_menu.addAction instead of m.addAction (also self.context_menu.addSeparator).

Revision history for this message
capink (capink-eg) wrote :

You can test using the attached plugin. Thanks for taking the time to add it to calibre, much appreciated.

Revision history for this message
Charles Haley (cbhaley) wrote :

This version works for me with your plugin.

Revision history for this message
Charles Haley (cbhaley) wrote :

And you are welcome.

Revision history for this message
capink (capink-eg) wrote :

confirmed. Thanks again.

Charles Haley (cbhaley)
Changed in calibre:
status: New → Fix Committed
Revision history for this message
Kovid Goyal (kovid) wrote : Fixed in master

Fixed in branch master. The fix will be in the next release. calibre is usually released every alternate Friday.

 status fixreleased

Revision history for this message
Kovid Goyal (kovid) wrote : Re: calibre bug 1936472

I have changed the API to allow plugins to add more than one action.

Revision history for this message
Charles Haley (cbhaley) wrote :

@capink: note that Kovid changed (fixed) my implementation so that it fits with the plugin architecture. In particular the method is now defined in the plugin class. In addition the method is now a generator so it can yield multiple context actions, which is what I should have done from the beginning.

Changed in calibre:
status: Fix Committed → Fix Released
Revision history for this message
capink (capink-eg) wrote :

Yes I saw that. I went for a single action because I thought it is better for plugins to add their own submenu to the QAction to prevent cluttering the context menu.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers