Kodi Community Forum

Full Version: Programmatically Selecting a ListItem in a Plugin
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Kodi has the nice setting to select the first unwatched episode of a series. That's great, but it doesn't work in addons, and since addons are not necessarily providing a list that is relevant to that setting, it's fine.
Not working code that I think should
The plugin_dir object adds directory items and calls endofdirectory. I'm confident that code works well, but posting all of it would clutter up the forums.
My issue is that ListItem.select(self, selected: bool) -> None seems to do absolutely nothing, let alone what it's supposed to.
Working code that isn't reliable or good practice
This code works, but if it's called without enough time for Kodi to do proper endOfDirectory() stuff, then it does nothing, as the directory doesn't exist yet. It's generally bad practice to wait an arbitrary amount of time and assume it's enough, so what are my options?
(2019-03-17, 06:51)da3dsoul Wrote: [ -> ]Kodi has the nice setting to select the first unwatched episode of a series. That's great, but it doesn't work in addons, and since addons are not necessarily providing a list that is relevant to that setting, it's fine.
Not working code that I think should
The plugin_dir object adds directory items and calls endofdirectory. I'm confident that code works well, but posting all of it would clutter up the forums.
My issue is that ListItem.select(self, selected: bool) -> None seems to do absolutely nothing, let alone what it's supposed to.
Working code that isn't reliable or good practice
This code works, but if it's called without enough time for Kodi to do proper endOfDirectory() stuff, then it does nothing, as the directory doesn't exist yet. It's generally bad practice to wait an arbitrary amount of time and assume it's enough, so what are my options?

I am having a very similar problem to this. I am using the following code to create my directory:

python:

xbmcplugin.setContent(PLUGIN_HANDLE, 'tvshows')
xbmcplugin.setPluginCategory(PLUGIN_HANDLE, 'My Directory')
xbmcplugin.addDirectoryItems(PLUGIN_HANDLE, menu_items_xbmc, len(menu_items_xbmc))
xbmcplugin.endOfDirectory(PLUGIN_HANDLE)

`menu_items_xbmc` is an array of tuples (url, list item, True/False). On the list item I want to be selected I call `.select(True)` When I run my plugin  I see the list item has a different color treatment but the ".." is always the active entry if that makes sense. I would like to make the active entry one I called `.select(True)` on so the user could just press enter without having to scroll.
You can calculate number of "Down" events and follow it with "Select" event:
python:
xbmc.executeJSONRPC('{"jsonrpc":"2.0","method":"Input.Down","id":1}')
xbmc.executeJSONRPC('{"jsonrpc":"2.0","method":"Input.Select","id":1}')
https://github.com/Virusmater/plugin.aud...lt.py#L152
This is not an ideal, but an only possible way of doing it for me.