Linux Can I call xbmc.python.library functions from a skin?
#1
Hi.

I am currently modding the re-Touched skin to execute a (hardware-specific) Linux binary by pressing buttons. The program is C code I Have written and compiled for Linux and embedded in OpenELEC. So far so good.

The program is invoked with different arguments depending on what skin button is pressed. It also relies upon stdout to return information to the caller. [I don't know why] I couldn't run the program with arguments using System.Exec() or System.ExecWait(). I could make it work running a wrapper shell script without any arguments. So I am currently heading towards wrapping my calls with some Python scripting.

My question is: from a skin, (how) can I call functions defined in an XBMC python library addon (i.e. extension point="xbmc.python.library")?

EDIT: Here's how I'd like my script/library to look like:
Code:
#!/usr/bin/env python

import xbmc
import xbmcgui
import xbmcaddon

__ADDON__ = xbmcaddon.Addon()
__ADDONNAME__ = __ADDON__.getAddonInfo('name')
__ICON__ = __ADDON__.getAddonInfo('icon')

import os, sys
import subprocess

def notify(message, delay):
    xbmc.executebuiltin('Notification(%s, "%s", %d, %s)'%(__ADDONNAME__, message, delay, __ICON__))


def k8090(*args):
    try:
        p = subprocess.Popen(["k8090", "-c", "/etc/k8090/config"] + list(args), stdout=subprocess.PIPE)
        stdout, stderr = p.communicate()
        if stderr:
            notify( stderr, 3000 )
        return stdout
    except OSError, e:
        notify( repr(e), 5000 )


def switchVideoSource():
    k8090("--timer=1", "video-source")
...

Why a library? The addon doesn't appear under the Program Addons and that suits me well.
Reply
#2
you can run your script from a skin using the RunScript() action.

basic usage:
RunScript(script.something)

you also can pass additional arguments to your script:
RunScript(script.something,option1=foo&option2=bar)
Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ, Help and Search the forum before posting.
Reply
#3
Thanks ronie. I'm not sure I get what you mean though. Shouldn't my [Python] script then include a main() entry point to do what you suggest?

I am currently testing my add-ons but they will all be embedded in OpenELEC. So none of the locations may be hardcoded, i.e. I must make calls as location-agnostic as can be. The something you are referring to, can it be the script ID? (having read zillions of pages all around I can be sure I have seen somewhere what you're talking about but can't get my hands on that page.)
Reply
#4
yes & yes :-)
Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ, Help and Search the forum before posting.
Reply
#5
Oooh, I see from this page the argument string can be just about *any* string, not necessarily in the form "name=value" – I didn't see how the latter would fit my application but now I think I get it.
Reply

Logout Mark Read Team Forum Stats Members Help
Can I call xbmc.python.library functions from a skin?0