Defining callback function for context menu items
#1
Hi,

I'm trying to build my first add-on which involves scraping a website and getting video information. I'd like to be able to define a callback function for when the user clicks the "Information" item in the default context menu to bring up the information dialog.

An example scenario is this: in my add-on I want to include a search function which returns a directory of list items. This functionality mimics the same functionality of the website for which I am building the add-on. On the website, the search results include a collection of video items, however by default this only includes basic information like title, media type, year, etc. A separate API call is required per search result to get additional information, such as the plot.

I want to minimise API calls and only make such a call if the user goes to the information dialog. Does such functionality exist? Is there a similar way to achieve my goal? I've done a lot of searching and unfortunately I can't find any solution, just a lot of people being disappointed that they can't adjust the context menu items. However, I'm sure this kind of behaviour is possible - I'm almost certain I've seen this kind of behaviour in practice before but I'm still a novice Kodi user so can't find any examples of it now.

To be clear, I am aware of the addContextMenuItems function, I don't think this will be able to assist me as it doesn't change the behaviour of the built-in context menu items from what I can tell.

Cheers
Reply
#2
I've done a bit more digging - maybe I want to assign an action to an Action ID?

https://kodi.wiki/view/Action_IDs

Here there is an action ID
Code:
Info
"Show the information about the currently highlighted item, or currently playing item."

https://xbmc.github.io/docs.kodi.tv/mast...002b029c75

Or do I add my API code to this onAction function? With the following ID?

https://xbmc.github.io/docs.kodi.tv/mast...0ffe8f442f

Just fumbling my way around at the moment. If anyone has any clues let me know! An example of an add-on that addresses this need would be awesome 😎
Reply
#3
I think the best way to do this is to use the RunPlugin builtin:
xml:

my_listitem.addContextMenuItems([('Context Menu Title','RunPlugin(plugin://plugin.xxx.yyy/route_to_callback_function)')])

And then the route in your plugin will open a custom dialog/info window.
Reply
#4
That's only if I want to add a new context menu item though, correct?

I am trying to change the built-in behaviour of loading the information dialog, rather than creating a new option to select.
Reply
#5
Ah sorry, i missed that part. As far as i know, this isn't possible. More info on that here:
https://forum.kodi.tv/showthread.php?tid=332266
Reply

Logout Mark Read Team Forum Stats Members Help
Defining callback function for context menu items0