HOW-TO:Script addon: Difference between revisions
(Created page with "{{mininav|Development|Add-on development}} This page will outline the basics of creating your first Python script for Kodi. It assumes you're at least familiar with t...") |
No edit summary |
||
Line 20: | Line 20: | ||
In the addon.xml file you define the (unique) id of your addon and the name of the addon. | In the addon.xml file you define the (unique) id of your addon and the name of the addon. | ||
It will also | It will also tell Kodi what type of addon it is. Since we're going to create a script type addon, we need to set our extension point to 'xbmc.python.script'. | ||
Also define your python file in the 'library' field. This is the file Kodi will execute when you run your script. | |||
This is what your addon.xml will need to look like (the bare minimum): | This is what your addon.xml will need to look like (the bare minimum): | ||
Line 39: | Line 40: | ||
</extension> | </extension> | ||
</addon> | </addon> | ||
</syntaxhighlight> | |||
= Your default.py file = | |||
:''See also: [https://codedocs.xyz/xbmc/xbmc/group__python.html '''kodi python api''']'' | |||
tba | |||
<syntaxhighlight lang="python" enclose="div"> | |||
import xbmc | |||
import xbmcgui | |||
import xbmcaddon | |||
ADDON = xbmcaddon.Addon() | |||
CWD = ADDON.getAddonInfo('path').decode('utf-8') | |||
class GUI(xbmcgui.WindowXML): | |||
def onInit(self): | |||
listitems = [] | |||
listitem1 = xbmcgui.ListItem('my first item') | |||
listitems.append(listitem1) | |||
listitem2 = xbmcgui.ListItem('my second item') | |||
listitems.append(listitem2) | |||
self.addItems(listitems) | |||
xbmc.sleep(100) | |||
self.setFocusId(self.getCurrentContainerId()) | |||
if (__name__ == '__main__'): | |||
ui = GUI('script-testwindow.xml', CWD, 'default', '1080p', True) | |||
ui.doModal() | |||
del ui | |||
</syntaxhighlight> | |||
= Your script-testwindow.xml file = | |||
{{See also|Skinning_Manual}} | |||
tba | |||
<syntaxhighlight lang="xml" enclose="div"> | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<window> | |||
<views>50</views> | |||
<controls> | |||
<control type="list" id="50"> | |||
<left>500</left> | |||
<top>200</top> | |||
<width>1000</width> | |||
<height>500</height> | |||
<viewtype label="535">list</viewtype> | |||
<itemlayout height="100" width="1000"> | |||
<control type="label"> | |||
<left>20</left> | |||
<top>0</top> | |||
<height>50</height> | |||
<width>960</width> | |||
<font>font13</font> | |||
<label>$INFO[ListItem.Label]</label> | |||
</control> | |||
</itemlayout> | |||
<focusedlayout height="100" width="1000"> | |||
<control type="image"> | |||
<left>0</left> | |||
<top>0</top> | |||
<width>1000</width> | |||
<height>50</height> | |||
<texture>testwindow-focus.png</texture> | |||
</control> | |||
<control type="label"> | |||
<left>20</left> | |||
<top>0</top> | |||
<height>50</height> | |||
<width>960</width> | |||
<font>font13</font> | |||
<label>$INFO[ListItem.Label]</label> | |||
<textcolor>orange</textcolor> | |||
</control> | |||
</focusedlayout> | |||
</control> | |||
</controls> | |||
</window> | |||
</syntaxhighlight> | </syntaxhighlight> |
Revision as of 23:58, 15 January 2018
Development | Add-on development | HOW-TO:Script addon |
This page will outline the basics of creating your first Python script for Kodi. It assumes you're at least familiar with the basics of Python (or at least, programming in general). If not, we recommend visiting the Python tutorial first, and then returning here.
While a python script can do many things, this tutorial is aimed at creating a window in Kodi.
Before we get started
The first step to making an add-on is to put the basic structure in place. Make sure your directory is properly named, e.g. script.my-addon
.
Once these are done, you can get started writing the actual code for your add-on!
The structure of our addon will look like this:
The addon.xml file
In the addon.xml file you define the (unique) id of your addon and the name of the addon. It will also tell Kodi what type of addon it is. Since we're going to create a script type addon, we need to set our extension point to 'xbmc.python.script'. Also define your python file in the 'library' field. This is the file Kodi will execute when you run your script.
This is what your addon.xml will need to look like (the bare minimum):
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <addon id="script.testwindow" name="test window" version="0.0.1" provider-name="me"> <requires> <import addon="xbmc.python" version="2.25.0"/> </requires> <extension point="xbmc.python.script" library="default.py"> <provides>executable</provides> </extension> <extension point="xbmc.addon.metadata"> <summary lang="en_GB">window demo script</summary> <description lang="en_GB">a demo script to create a window</description> <language></language> <platform>all</platform> </extension> </addon>
Your default.py file
- See also: kodi python api
tba
import xbmc import xbmcgui import xbmcaddon ADDON = xbmcaddon.Addon() CWD = ADDON.getAddonInfo('path').decode('utf-8') class GUI(xbmcgui.WindowXML): def onInit(self): listitems = [] listitem1 = xbmcgui.ListItem('my first item') listitems.append(listitem1) listitem2 = xbmcgui.ListItem('my second item') listitems.append(listitem2) self.addItems(listitems) xbmc.sleep(100) self.setFocusId(self.getCurrentContainerId()) if (__name__ == '__main__'): ui = GUI('script-testwindow.xml', CWD, 'default', '1080p', True) ui.doModal() del ui
Your script-testwindow.xml file
tba
<?xml version="1.0" encoding="UTF-8"?> <window> <views>50</views> <controls> <control type="list" id="50"> <left>500</left> <top>200</top> <width>1000</width> <height>500</height> <viewtype label="535">list</viewtype> <itemlayout height="100" width="1000"> <control type="label"> <left>20</left> <top>0</top> <height>50</height> <width>960</width> <font>font13</font> <label>$INFO[ListItem.Label]</label> </control> </itemlayout> <focusedlayout height="100" width="1000"> <control type="image"> <left>0</left> <top>0</top> <width>1000</width> <height>50</height> <texture>testwindow-focus.png</texture> </control> <control type="label"> <left>20</left> <top>0</top> <height>50</height> <width>960</width> <font>font13</font> <label>$INFO[ListItem.Label]</label> <textcolor>orange</textcolor> </control> </focusedlayout> </control> </controls> </window>