Built-in scripting: Difference between revisions

From Official Kodi Wiki
Jump to navigation Jump to search
>Moinois
>NedBot
m (Robot: Cosmetic changes)
Line 1: Line 1:
XBMC contains several built-in functions that can be accessed from the skin (via a button) or from within a python script, XBMC's [[HTTP API]] or from a press of a button on the remote, gamepad, or keyboard.
XBMC contains several built-in functions that can be accessed from the skin (via a button) or from within a python script, XBMC's [[HTTP API]] or from a press of a button on the remote, gamepad, or keyboard.


====General form of built-in Functions====
==== General form of built-in Functions ====
Built in functions take the form
Built in functions take the form


   [XBMC.]Function(param1,param2,...).
   [XBMC.]Function(param1,param2,...).


The XBMC. prefix is optional. Some parameters are required, depending on the function. In parsing built in functions, XBMC first treats quoted (using double quotes ") character strings as literal, and drops the quotes. Thus, when inside a quote, any otherwise special characters will be ignored until the quote is complete. Parameters are separated by comma's, and, given that functions may be parameters to other functions (such as with the AlarmClock function), anything within brackets () are treated as a single block as well. Finally, prior to passing parameters into the function, any initial and trailing spaces is removed. This system allows you to pass in functions as parameters (the comma's used for the passed function are ignored as they're within a () block) as well as allowing you to ignore whitespace around parameter separators. If you wish to pass comma's in directly as part of a parameter, simply put quotes around the parameter string - XBMC will strip off the quotes prior to passing it in. Lastly, to pass in an actual quote character, make sure it's escaped (using the \ character), as in \".
The XBMC. prefix is optional. Some parameters are required, depending on the function. In parsing built in functions, XBMC first treats quoted (using double quotes ") character strings as literal, and drops the quotes. Thus, when inside a quote, any otherwise special characters will be ignored until the quote is complete. Parameters are separated by comma's, and, given that functions may be parameters to other functions (such as with the AlarmClock function), anything within brackets () are treated as a single block as well. Finally, prior to passing parameters into the function, any initial and trailing spaces is removed. This system allows you to pass in functions as parameters (the comma's used for the passed function are ignored as they're within a () block) as well as allowing you to ignore whitespace around parameter separators. If you wish to pass comma's in directly as part of a parameter, simply put quotes around the parameter string - XBMC will strip off the quotes prior to passing it in. Lastly, to pass in an actual quote character, make sure it's escaped (using the \ character), as in \".


Some examples:
Some examples:
Line 14: Line 14:
   ActivateWindow(VideoFiles,"path_to_some_files")
   ActivateWindow(VideoFiles,"path_to_some_files")


will all produce the exact same functionality, under the assumption that path_to_some_files contains no initial or trailing spaces (unlikely) and no unmatched brackets and commas. The "ActivateWindow" function will be called with two parameters: "VideoFiles" (the window to open) and "path_to_some_files" (a starting path for the browsing). If path_to_some_files contains initial or trailing spaces, or contains commas or brackets, then only the last form will function correctly.
will all produce the exact same functionality, under the assumption that path_to_some_files contains no initial or trailing spaces (unlikely) and no unmatched brackets and commas. The "ActivateWindow" function will be called with two parameters: "VideoFiles" (the window to open) and "path_to_some_files" (a starting path for the browsing). If path_to_some_files contains initial or trailing spaces, or contains commas or brackets, then only the last form will function correctly.


====Using Built-in Functions from the skin====
==== Using Built-in Functions from the skin ====
To have a button (or toggle button) on the skin run a particular function, you just have to add an <onclick> tag (or <onfocus> tag) containing the function you wish to run.<br>
To have a button (or toggle button) on the skin run a particular function, you just have to add an <onclick> tag (or <onfocus> tag) containing the function you wish to run.<br />
For example, adding the following to a button control will create a stop button.
For example, adding the following to a button control will create a stop button.
   <onclick>XBMC.PlayerControl(Stop)</onclick>
   <onclick>XBMC.PlayerControl(Stop)</onclick>
Line 24: Line 24:
   <onclick>xbmc.activatewindow(myvideolibrary,movietitles)</onclick>
   <onclick>xbmc.activatewindow(myvideolibrary,movietitles)</onclick>
A list of parameters can be found here:
A list of parameters can be found here:
*[[Opening Windows and Dialogs]]<br>
* [[Opening Windows and Dialogs]]<br />


====Using Built-in Functions from python====
==== Using Built-in Functions from python ====
To run a built-in XBMC function from within a python script, you just need to call executebuiltin() with the function name. For example,
To run a built-in XBMC function from within a python script, you just need to call executebuiltin() with the function name. For example,
   executebuiltin('XBMC.RunScript(Q:\Scripts\myscript.py)')
   executebuiltin('XBMC.RunScript(Q:\Scripts\myscript.py)')
Line 32: Line 32:




====Using Built-in Functions from keymap.xml====
==== Using Built-in Functions from keymap.xml ====
To bind a built-in function to a particular key, you just add the built-in command to the appropriate section and button in keymap.xml
To bind a built-in function to a particular key, you just add the built-in command to the appropriate section and button in keymap.xml


Line 46: Line 46:




to whatever window section of keymap.xml is appropriate.<br>
to whatever window section of keymap.xml is appropriate.<br />
For more information on changing the keymapping with keymap.xml see: [[Keymap.xml|Changing the keymapping]]
For more information on changing the keymapping with keymap.xml see: [[Keymap.xml|Changing the keymapping]]


===[[List of Built In Functions]]===
=== [[List of Built In Functions]] ===


===[[WebServerHTTP-API|Using Built-in Functions from the Web Server (HTTPAPI)]]===
=== [[WebServerHTTP-API|Using Built-in Functions from the Web Server (HTTPAPI)]] ===


===[[FTP Site Commands]]===
=== [[FTP Site Commands]] ===


[[category:Inner Workings]]
[[Category:Inner Workings]]
[[category:Development]]
[[Category:Development]]
[[category:Skin Development]]
[[Category:Skin Development]]
[[Category:HTTP API]]
[[Category:HTTP API]]

Revision as of 16:07, 7 September 2011

XBMC contains several built-in functions that can be accessed from the skin (via a button) or from within a python script, XBMC's HTTP API or from a press of a button on the remote, gamepad, or keyboard.

General form of built-in Functions

Built in functions take the form

 [XBMC.]Function(param1,param2,...).

The XBMC. prefix is optional. Some parameters are required, depending on the function. In parsing built in functions, XBMC first treats quoted (using double quotes ") character strings as literal, and drops the quotes. Thus, when inside a quote, any otherwise special characters will be ignored until the quote is complete. Parameters are separated by comma's, and, given that functions may be parameters to other functions (such as with the AlarmClock function), anything within brackets () are treated as a single block as well. Finally, prior to passing parameters into the function, any initial and trailing spaces is removed. This system allows you to pass in functions as parameters (the comma's used for the passed function are ignored as they're within a () block) as well as allowing you to ignore whitespace around parameter separators. If you wish to pass comma's in directly as part of a parameter, simply put quotes around the parameter string - XBMC will strip off the quotes prior to passing it in. Lastly, to pass in an actual quote character, make sure it's escaped (using the \ character), as in \".

Some examples:

 ActivateWindow( VideoFiles, path_to_some_files )
 ActivateWindow(VideoFiles,path_to_some_files)
 ActivateWindow(VideoFiles,"path_to_some_files")

will all produce the exact same functionality, under the assumption that path_to_some_files contains no initial or trailing spaces (unlikely) and no unmatched brackets and commas. The "ActivateWindow" function will be called with two parameters: "VideoFiles" (the window to open) and "path_to_some_files" (a starting path for the browsing). If path_to_some_files contains initial or trailing spaces, or contains commas or brackets, then only the last form will function correctly.

Using Built-in Functions from the skin

To have a button (or toggle button) on the skin run a particular function, you just have to add an <onclick> tag (or <onfocus> tag) containing the function you wish to run.
For example, adding the following to a button control will create a stop button.

 <onclick>XBMC.PlayerControl(Stop)</onclick>

If you want a button in your skin taking you directly to the movie listing, add a parameter to the Window ID as follows:

  <onclick>xbmc.activatewindow(myvideolibrary,movietitles)</onclick>

A list of parameters can be found here:

Using Built-in Functions from python

To run a built-in XBMC function from within a python script, you just need to call executebuiltin() with the function name. For example,

 executebuiltin('XBMC.RunScript(Q:\Scripts\myscript.py)')

will run the script myscript.py located in the Scripts directory.


Using Built-in Functions from keymap.xml

To bind a built-in function to a particular key, you just add the built-in command to the appropriate section and button in keymap.xml

For example, to map the running of an executeable to the BLACK button, we'd add:

  <gamepad>
    ...
    <black>XBMC.RunXBE(E:\Apps\AVALaunch.xbe)</black>
    ...
  </gamepad>


to whatever window section of keymap.xml is appropriate.
For more information on changing the keymapping with keymap.xml see: Changing the keymapping

List of Built In Functions

Using Built-in Functions from the Web Server (HTTPAPI)

FTP Site Commands