How to react to a user 'click' on a list ?
#1
context: video plugin (classic web scraping showed as a list)

I've succesfully showed a list of video titles to user.

When the user click on a title, how can i react to this ?

The question is: how to write this classic event handler in xbmc-python plugin?
Reply
#2
Those are handled through the list item's "url" property. For example, if you set the listitem's url to
Code:
plugin://plugin.video.foo/?mode=show_list2&my_key=my_value
When the user selects it, the plugin plugin.video.foo will be launched and passed "?mode=show_list2&my_key=my_value" in sys.argv

plugin.video.foo is expected to grab that string and use something like urlparser.parse_qs() to process those key/value pairs into useful information (a dict in the case of parse_qs). From there, it will decide how to react based on those parameters.

Hope that clears things up a bit
Reply
#3
Uhm.. so all is piloted by sys.argv.
That sounds good and now it's more clear the trick used by the gui/addon system to handle list !

Actually, when run the video addon list, i print sys.argv and it's this

Code:
['plugin://plugin.video.realtebo/', '2', '']

Ok, the first i my plugin 'url', but, what are the other 2 arguments about ?

Actually I've something like this:

Code:
def sendToXbmc(listing ):
    global thisPlugin
    for item in listing:
        listItem = xbmcgui.ListItem(item)
        xbmcplugin.addDirectoryItem(thisPlugin, '',listItem)
        
    xbmcplugin.endOfDirectory(thisPlugin)

.. where listtem is a simple string, because listing is a simple string array.

How can I set listitem url ? Is it enough to use 'url' parameter ?

This from xmb online docs:
Code:
addDirectoryItem(handle, url, listitem [,isFolder, totalItems])

Thanks even for urlparser.parse_qs(); i'll study, and I'll google about it
Reply
#4
Yes, it's enough to pass the url as the url parameter when creating the ListItem object

sys.argv[1] contains the handle xbmc used when creating this directory. This is needed to as the first parameter to xbmcplugin.addDirectoryItem()
sys.argvv[2] contains the url encoded string of parameters passed to the plugin when it was launched: '?mode=main&my_key=my_value'
Reply

Logout Mark Read Team Forum Stats Members Help
How to react to a user 'click' on a list ?0