PDA

View Full Version : Python onclick event?


matt.antone
April 30th, 2009, 08:16 PM
Hi guys,

Can you control the onclick event of a list using python?

xmcnuggetx
April 30th, 2009, 10:01 PM
Sounds like it... from http://developer.boxee.tv/boxee-applications/

Events
The window and each control has event tags (like onclick, onfocus, onload etc.) which are triggered upon specific events. Each event support the attribute lang="python" after which, python code may be inlined. Itís important to note that Boxee currently support Python 2.4. Omitting the language specification, falls back to the original XBMC actions, which are not described here. For example:


<onclick lang="python"><![CDATA[
...python code goes here
]]></onclick>

matt.antone
May 5th, 2009, 08:19 PM
I should probably rephrase. I'm working a little lower level than that.

I'm adding my list using python, and need to add that onclick event using python and not the application API.

junda
May 26th, 2009, 01:02 PM
i'm afraid current API doesn't support this. the onclick is for ListItems, not ListItem.
I'm not sure why you need this, if you want special behavior for each list item, you can make the decision in the ListItems onclick by getting the clicked item number

DPK
May 26th, 2009, 01:44 PM
Trust me, you'll save yourself a lot of pain by just tacking an onclick section within your list content that gets triggered when any of your list items is clicked on. Try to avoid list generation w/ the old xbmc api and stick with the boxee api. Note however that the boxee api is not supported on the current Windows boxee build.

A boxee api example:
<content type="url">
<onclick lang="python"><![CDATA[
import mc

list = mc.GetActiveWindow().GetList(1000)
list_foc = list.GetFocusedItem()
list_itm = list.GetItems()[list_foc]

print "Item ID: %s" % list_foc
print "Item Label: %s" % list_itm.GetLabel()
print "Item Description: %s" % list_itm.GetDescription()

]]></onclick>
</content>


This will get the selected/clicked item's position in a list with an id of 1000, it's label, and description. There are a ton of other attributes as well. Simillarly, you could pass "list_itm" to your own function and then determine what actions you have to perform on the selected list item.

Mallet
July 17th, 2009, 01:25 PM
I have the following content in a list:


<content>
<item id="2001">
<label>Live Shows</label>
<onclick lang="python"><![CDATA[
import mc
mc.LogDebug("Live Shows menu selected")
mc.GetApp().ActivateWindow(12345)
]]></onclick>
</item>
</content>


When I select the item in the list Boxee reports the following error:

ERROR: Keymapping error: no such action '
import mc
mc.logdebug("live shows menu selected")
mc.getapp().activatewindow(12345)
' defined

Any help understanding this would be appreciated.

DPK
July 17th, 2009, 02:59 PM
Is 12345 a valid window id?

Try replacing:
mc.LogDebug("Live Shows menu selected")

With this:
print "Live Shows menu selected"

juicejuice
December 27th, 2010, 02:51 AM
A boxee api example:

Out of interest, where is this documented? The boxee docs (http://developer.boxee.tv/List_Container) indicate that <onclick> should be a child of the list container <control>, but in reality the <onclick> must be embedded within a <content> tag.

The whole <content> tag thing and its usage doesn't seem to be described in detail anywhere??

joshuajonah
December 31st, 2010, 12:10 AM
It's kind of weird, but programming Boxee apps is completely retarded, however I still do it for some reason.

Everything is hidden so that you cannot just inspect the source and see what methods you could expect from an object. It's all generated in C++ (but has Java style programming) kind of like swig bindings.

I've learned a hell of a lot by dir()ing things and log outputting everything. I'd recommend examining the layout once it's already running. It's a weird data structure and not quite what you'd expect. For example, a ListItem in the Boxee API does not appear to be in any way inherited from an XBMC ListItem.

Obligatory dir() of ListItem:

>>> listitem = the_list.GetItem(the_list.GetFocusedItem())
>>> print dir(listitem)

['AddAlternativePath', 'AddCast', 'AddCastAndRole', 'ClearCastAndRole', 'Dump', 'GetAlbum', 'GetArtist',
'GetAuthor', 'GetCast', 'GetCastAndRole', 'GetComment', 'GetContentRating', 'GetContentType', 'GetDate',
'GetDescription', 'GetDirector', 'GetDuration', 'GetDurationFormatted', 'GetEpisode', 'GetFileItem',
'GetGenre', 'GetIcon', 'GetImage', 'GetKeywords', 'GetLabel', 'GetMediaType', 'GetPath', 'GetProperty',
'GetProviderSource', 'GetReportToServer', 'GetResumable', 'GetSeason', 'GetSize', 'GetSizeFormatted',
'GetStarRating', 'GetStudio', 'GetTVShowTitle', 'GetTagLine', 'GetThumbnail', 'GetTitle', 'GetTrackNumber',
'GetViewCount', 'GetViewCountFormatted', 'GetWatched', 'GetWriter', 'GetYear', 'HasProperty',
'IsEnabledRate', 'IsEnabledRecommend', 'MEDIA_AUDIO_MUSIC', 'MEDIA_AUDIO_OTHER',
'MEDIA_AUDIO_RADIO', 'MEDIA_AUDIO_SPEECH', 'MEDIA_FILE', 'MEDIA_PICTURE', 'MEDIA_UNKNOWN',
'MEDIA_VIDEO_CLIP', 'MEDIA_VIDEO_EPISODE', 'MEDIA_VIDEO_FEATURE_FILM',
'MEDIA_VIDEO_MUSIC_VIDEO', 'MEDIA_VIDEO_OTHER', 'MEDIA_VIDEO_TRAILER', 'Select',
'SetAddToHistory', 'SetAlbum', 'SetArtist', 'SetAuthor', 'SetComment', 'SetContentRating',
'SetContentType', 'SetDate', 'SetDescription', 'SetDirector', 'SetDuration', 'SetEnableRate',
'SetEnableRecommend', 'SetEpisode', 'SetExternalItem', 'SetGenre', 'SetIcon', 'SetImage', 'SetKeywords',
'SetLabel', 'SetPath', 'SetProperty', 'SetProviderSource', 'SetReportToServer', 'SetResumable',
'SetSeason', 'SetSize', 'SetStarRating', 'SetStudio', 'SetTVShowTitle', 'SetTagLine', 'SetThumbnail',
'SetTitle', 'SetTrackNumber', 'SetViewCount', 'SetWriter', 'SetYear', '__class__', '__del__', '__delattr__',
'__dict__', '__doc__', '__getattr__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__',
'__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', '[__swig_destroy__',
'__swig_getmethods__', '__swig_setmethods__', '__weakref__', 'this']



Edit: Just noticed ^, I guess it actually is swig.

juicejuice
January 1st, 2011, 07:25 AM
Thanks for the tip. I've not really done any Python before but very familiar with Javascript, Perl, C, Java, etc. Your suggestion is similar to what I have done in reversing a bunch of other APIs I have had to deal with in the past :)

It does seem that developing Boxee apps is made significantly more difficult by lack of reliable documentation... :(