Context Item Add-ons
Context item add-ons allows the context menu in Kodi to be extended. Add-ons must provide the kodi.context.item
extension point and a <item> definition. Example:
<extension point="kodi.context.item" library="addon.py"> <item> <label>Hello World</label> <visible>!IsEmpty(ListItem.Genre)</visible> <parent>kodi.core.manage</parent> </item> </extension>
<label>: Required. The label to show in the context menu. String or an ID from the language file.
<visible>: Required. A visibility expression that determines when the item will be visible in the context menu.
<parent>: Optional. The parent group for the context item. If "kodi.core.manage" the item will be added under the "Manage" sub-menu. If not specified, it will be added to the top level.
It is currently only possible to provide one item per add-on.
Note: Before adding a context menu extension to existing add-on, keep in mind that there is limited space in the context menu and that having multiple extension in and add-on will force the user to have all of them enabled at the same time.
This feature requires at least version 2.20.0 of the Python API, which should be specified in the Addon.xml#<requires> element:
<import addon="xbmc.python" version="2.20.0"/>
The item the context menu was opened on can be accessed in python via the sys.listitem
attribute. The attribute is an instance of xbmcgui.ListItem
.
Example python script
This example script will display a notification message showing the name of item the context menu was opened on:
import sys import xbmc if __name__ == '__main__': message = "Clicked on '%s'" % sys.listitem.getLabel() xbmc.executebuiltin("Notification(\"Hello context items!\", \"%s\")" % message)