PDA

View Full Version : Using python libraries


dan131m
April 5th, 2009, 06:20 PM
I'd like to use a python library in my app. What is the best way to do this? I can't find a good way that would seem to work cross-platform, and I don't have a linux install to test on at the moment.

Also, is there any real comprehensive developer documentation out there at all? Most of what I can find seems very spotty and often pertains to obsolete versions...

afuchs
April 5th, 2009, 08:04 PM
I'd like to use a python library in my app. What is the best way to do this? I can't find a good way that would seem to work cross-platform, and I don't have a linux install to test on at the moment.

I would think you would bundle it with the app, figure out where they app is stored, then modify the PYTHONPATH environment variable to include the directory where the library is stored (made easier by XBMC's 'Q:' drive, no idea how relevant that is to boxee). If there is an easier way (see spotty documentation), I would like to know.

Also, is there any real comprehensive developer documentation out there at all? Most of what I can find seems very spotty and often pertains to obsolete versions...

Haven't found anything other than the XBMC docs (http://xbmc.org/wiki/?title=Main_Page) and one page from boxee (http://developer.boxee.tv/). I've been looking around in existing apps (check your ~/.boxee/UserData/apps/ dir if you are runing linux, find XBMC related stuff, etc), trying to figure out the API.

Once I figure out how to make something that works, I might publish a howto.

dan131m
April 5th, 2009, 08:56 PM
Can I get some more specifics on the "find out where the app is stored" part?

I can't see any way of doing this, minus trying to check the default locations by operating system... can't even really use a config file, b/c where would you look for the config file?

afuchs
April 6th, 2009, 09:21 PM
They just released some official documentation (http://blog.boxee.tv/2009/04/06/introducing-the-boxee-api/). I don't know if it has any information about importing libraries.

XBMC mapped a drive letter to give easy access to XBMC's install directory. Files included with it's scripts could be found because XBMC installed all of it's scripts in a specific directory. Boxee, AFAIK, installs its scripts in the user's home directory.

riegersn
April 6th, 2009, 10:18 PM
I'd like to use a python library in my app. What is the best way to do this? I can't find a good way that would seem to work cross-platform, and I don't have a linux install to test on at the moment.

Also, is there any real comprehensive developer documentation out there at all? Most of what I can find seems very spotty and often pertains to obsolete versions...

@dan131m:

Python is already built into the boxee app. Have you taken the time to look at the code in any of the current apps available for boxee? Simple add the python code to your skin.


<onclick><![CDATA[CallPython(
import os
import xbmc
import xbmcgui
path = xbmc.getInfoLabel('Container(120).ListItem.Filenam eAndPath')
title = xbmc.getInfoLabel('Container(120).ListItem.Label')
xbmc.executebuiltin( 'RunApp(app://myapp?link='+path+)' )
)]]></onclick>

DPK
April 10th, 2009, 10:01 AM
@dan131m:
Python is already built into the boxee app. Have you taken the time to look at the code in any of the current apps available for boxee? Simple add the python code to your skin.


dan131m is asking about using a 3rd party python library. Something that basically builds off python's existing functions. At least that's what I think he's asking.

In which case that is what he's asking, check out this post I made:
http://forum.boxee.tv/showpost.php?p=45194&postcount=4

It should detail a short example on including a 3rd party library in a boxee app.

mwpei
April 10th, 2009, 01:55 PM
@dan131m:


<onclick><![CDATA[CallPython(
import os
import xbmc
import xbmcgui
path = xbmc.getInfoLabel('Container(120).ListItem.Filenam eAndPath')
title = xbmc.getInfoLabel('Container(120).ListItem.Label')
xbmc.executebuiltin( 'RunApp(app://myapp?link='+path+)' )
)]]></onclick>


This way of calling Python seems to crash the ATV in the 0.9.11 version of boxee now but if you change it to the following it seems to fix the problem

<onclick lang="python"><![CDATA[

ameno
May 15th, 2009, 12:46 PM
Let's say that your example file in this case is "utils.py".

Place it in the root folder of your app (in this case I called it "your-app-name"), the same folder with descriptor.xml

then include this code whenever you want to import it in:

if sys.platform == 'darwin':
sys.path.append('u:\\apps\\your-app-name\\')
else:
sys.path.append('t:\\apps\\your-app-name\\')
import utils

If you don't do that if/else it won't work cross-platform

idan
May 19th, 2009, 08:43 AM
btw guys, next version of boxee will automatically add the application root to the system path of each application. i will let you know once its out.

junda
May 26th, 2009, 12:57 PM
put the .py in your app root folder, along with descriptor.xml, and you are done.
you can find more details in my app

http://forum.boxee.tv/showthread.php?t=9018

Mallet
July 9th, 2009, 08:03 PM
This clearly works for other apps that I've tried, but for my own, the app path isn't being included in the sys.path by default so my include statement fails. What am I missing?

ameno
July 9th, 2009, 09:35 PM
In the latest versions, this has changed. Here is code we are currently using with boxxxee.


if sys.platform == 'darwin':
sys.path.append('u:\\apps\\com.bx.boxxxee\\')
sys.path.append('special://masterprofile/apps/com.bx.boxxxee/')
else:
sys.path.append('t:\\apps\\com.bx.boxxxee\\')
sys.path.append('special://masterprofile/apps/com.bx.boxxxee/')
import utils


Adjust as necessary for your own app

riegersn
September 22nd, 2009, 03:45 PM
it will not work if you set the window id too high. try something under 14050 for the window id and test again.