Context Item Add-ons: Difference between revisions
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
Context item add-ons allows the [[ | Context item add-ons allows the [[context menu]] in Kodi to be extended. Add-ons must provide the <code>kodi.context.item</code> extension point and a <item> definition. Example: | ||
<syntaxhighlight lang="xml"> | <syntaxhighlight lang="xml"> | ||
<item> | <extension point="kodi.context.item" library="addon.py"> | ||
<label></label> | <item> | ||
<label>Hello World</label> | |||
<visible>!IsEmpty(ListItem.Genre)</visible> | |||
</item> | <parent>kodi.core.manage</parent> | ||
</item> | |||
</extension> | |||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 22: | Line 24: | ||
This feature requires at least version 2.20.0 of the Python API, which should be specified in the [[Addon.xml#<requires>]] element: | |||
<syntaxhighlight lang="xml"> | <syntaxhighlight lang="xml"> | ||
<import addon="xbmc.python" version="2.20.0"/> | |||
</syntaxhighlight> | </syntaxhighlight> | ||
The item the context menu was opened on can be accessed in python via the <code>sys.listitem</code> attribute. The attribute is an instance of <code>xbmcgui.ListItem</code>. | |||
== Example python script | == Example python script == | ||
This example script will display a notification message showing the name of item the context menu was opened on: | |||
<syntaxhighlight lang="python"> | <syntaxhighlight lang="python"> |
Revision as of 11:47, 5 March 2015
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)