Kodi Community Forum

Full Version: Video addon: How to periodically refresh list items
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

In my video addon, I have some list items containing dynamic data -- think download progress percentage, as in for example

* Movie 1 [80% downloaded]
* Movie 2 [100% downloaded]
* Movie 3 [paused]

this kind of thing.

While it's easy to populate the initial list (with xbmcplugin.addDirectoryItem()), I would like to be able to periodically auto-refresh the list every (say) 2 seconds, so that I can update the list items with fresher data.

I have tried spawning a new background thread to do a new setLabel() on the items in question, but alas it does not seem to have any effect.

Is periodically refreshing list item labels possible? If so, how?
No code? I'll answer accordingly... Yes, use info properties and thread timer.
Hi Lunatixz,

Quote:No code? I'll answer accordingly... Yes, use info properties and thread timer.

OK. Bear with me though. I can't post the real code as it is kind of spread across multiple classes and it would be hard to follow. But in a nutshell it does the usual stuff. Here's more or less what it does:

Code:
for oneContent in myContents:
    li = xbmcgui.ListItem(oneContent["name"])
    li.setProperty("IsPlayable", "true")
    xbmcplugin.addDirectoryItem(handle=addon_handle, url=oneContent["url"], listitem=li)
xbmcplugin.endOfDirectory(addon_handle)

So you suggest I use a thread timer. Fair enough. And "info properties". Here I need some more. Do you refer to ListItem.setInfo()? But how would I use that to change the item's label?
(2016-01-22, 15:48)gdomenici Wrote: [ -> ]Hi Lunatixz,

Quote:No code? I'll answer accordingly... Yes, use info properties and thread timer.

OK. Bear with me though. I can't post the real code as it is kind of spread across multiple classes and it would be hard to follow. But in a nutshell it does the usual stuff. Here's more or less what it does:

Code:
for oneContent in myContents:
    li = xbmcgui.ListItem(oneContent["name"])
    li.setProperty("IsPlayable", "true")
    xbmcplugin.addDirectoryItem(handle=addon_handle, url=oneContent["url"], listitem=li)
xbmcplugin.endOfDirectory(addon_handle)

So you suggest I use a thread timer. Fair enough. And "info properties". Here I need some more. Do you refer to ListItem.setInfo()? But how would I use that to change the item's label?

Just trying to understand what you want...

Going by post1 you have a label that you want to change dynamically while the plugin is open?
semi pseudocode, simple concept, each property needs to be unique for each listitem.

Code:
Thread_Timer = threading.Timer(timer, foo)

def foo:
    for oneContent in myContents:
         setProperty(mynameis,oneContent["name"])

def bar:
             li = xbmcgui.ListItem(getProperty(mynameis))
            li.setProperty("IsPlayable", "true")
             xbmcplugin.addDirectoryItem(handle=addon_handle, url=oneContent["url"], listitem=li)

xbmcplugin.endOfDirectory(addon_handle)
xbmc.exec(refresh list)
Thanks Lunatixz -- I took part of your solution (the use of threading.Timer) but for the rest I realized I needed something a lot simpler than I'd anticipated -- just refreshing the container did the trick.

For future reference, the code I used was something along the lines of:

Code:
def populateList(self):
    for oneContent in myContents:
        li = xbmcgui.ListItem(oneContent["name"])
        li.setProperty("IsPlayable", "true")
        xbmcplugin.addDirectoryItem(handle=addon_handle, url=oneContent["url"], listitem=li)
    xbmcplugin.endOfDirectory(addon_handle)
    guiUpdateTimer = threading.Timer(
        4.0, # fire after  4 seconds
        self.refreshGuiItems)
    guiUpdateTimer.start()

def refreshGuiItems(self):
    xbmc.executebuiltin('Container.Refresh')