View Full Version : Refresh a plugin listing
Hello,
I'm currently write a plugin and I want to add/remove items by context menu actions.
So I call actions with
item.addContextMenuItems( [ ("foo", "XBMC.RunPlugin(...)") ] )
but once action is done, how to update listing ?
I've tried
xbmc.executebuiltin("XBMC.RunPlugin(%s)"%sys.argv[0])
But it's not work (apparently, Python is launched and crashes when it fills list : nothing changes at screen)
My config : XBMC rev 15340 (Sep 2 2008) on Ubuntu 8.10
rwparris2
2008-09-06, 16:59
Any way you could post your full code? I have an idea but need to see how you've written everything else first....
Sure,
this is an emulator frontend. I'll try to post correct snippets because code is pretty huge and I've coded it with MVC pattern : just controllers (ie core instructions) are interesting here.
Context menu items are added this way (here for delete a platform):
# add menu options
item.addContextMenuItems([
(misc.locale(117), "XBMC.RunPlugin(%s?platform=del:%s)"%(sys.argv[0], pf["platformId"]))
])
As you can see it restarts the plugin with different arguments that are parsed by generic controller constructor :
## Base class for controllers
class BaseController:
## Universal URI pattern
URI_PATTERN = "^\?%s=(.*)$"
## Create common controller utils
# @param action action type (platform, game, rom, run)
def __init__(self, action):
self.db = model.DataBase(DB_FILE)
self.action = action
self.uri = self._parseURI(sys.argv[2])
xbmcplugin.setContent(int(sys.argv[1]), 'files') # <-- May cause a problem ???
print "Action : "+self.action+" ; Arguments : "+str(self.uri)
I don't if it matters but "xbmcplugin.setContent(int(sys.argv[1]), 'files')" is executed all times (even for actions that doesn't display anything).
And platforms controller :
class Main(BaseController):
## Make platform list window
def __init__(self):
BaseController.__init__(self, "platform")
if self.uri is None:
self._fillList() # fills platforms list
elif self.uri[0] == "del": # <-- this condition is True for deleting
self._delete(self.uri[1])
else:
...
self._close() #just close DB properly
Finally following method is called (still for deleting):
## Ask user confirmation and delete given platform
# @param id platform ID
def _delete(self, id):
name = self.db.getPlatformData(id)["name"]
if misc.dlg.yesno(misc.locale(750), misc.locale(30229)%name, misc.locale(30230)):
self.db.delPlatform(id)
Then a final cleanup instruction
sys.modules.clear()
Fails each times ! (I don't know if it's normal or not)
rwparris2
2008-09-06, 20:38
Didn't really show me what I was looking for, I needed how your directory items are actually listed. Anyways, my idea is this: there is a currently undocumented function xbmcplugin.disableCache(handle). You can see the docs for it here: http://xbmc.org/trac/changeset/14439
I haven't actually used it yet, so no idea if this will work, but you can try it out.
Disable the cache on your plugin, then go into a directory that calls a fake function. This should in theory force xbmc to return to the previous directory & repopulate it.
Hope that makes sense?
Either way I'm looking forward the new emulator plugin!
Thanks for answer but disableCache doesn't exists anymore : it's replaced by cacheToDisc parameter on xbmcplugin.endOfDirectory and there's no change ???
And items are added this way :
## fills lists with each found platform.
def _fillList(self):
# lists all platforms
ok = True
fav = misc.getBoolSetting("favonly") # get favourites status
for pf in self.db.getPlatformList():
print pf["name"]
uri = "%s?game=%s:%s"%(sys.argv[0], pf["platformId"], FAVOURITE[fav])
item = xbmcgui.ListItem(pf["name"])
setThumbnail(item, pf["icon"])
# add menu options
item.addContextMenuItems([
(misc.locale(misc.iif(fav, 30016, 30017)), "XBMC.RunPlugin(%s?game=%s:%s)"%(sys.argv[0], pf["platformId"], FAVOURITE[fav])),
(misc.locale(1026), "XBMC.RunPlugin(%s?platform=addpath:%s)"%(sys.argv[0], pf["platformId"])),
(misc.locale(30231), "XBMC.RunPlugin(%s?platform=refresh:%s)"%(sys.argv[0], pf["platformId"])),
(misc.locale(21435), "XBMC.RunPlugin(%s?dialog=editpf:%s)"%(sys.argv[0], pf["platformId"])),
(misc.locale(117), "XBMC.RunPlugin(%s?platform=del:%s)"%(sys.argv[0], pf["platformId"])),
(misc.locale(30026), "XBMC.RunPlugin(%s?dbcleanup)"%(sys.argv[0]))
])
ok = xbmcplugin.addDirectoryItem(int(sys.argv[1]), uri, item, True)
if not ok : break
# append addition buttons
emu = ("%s?dialog=emu"%sys.argv[0], xbmcgui.ListItem(misc.locale(30202), thumbnailImage=ADD_ICON))
newpf = ("%s?dialog=newpf"%sys.argv[0], xbmcgui.ListItem(misc.locale(30212), thumbnailImage=ADD_ICON))
ok = ok and \
xbmcplugin.addDirectoryItem(int(sys.argv[1]), emu[0], newemu[1], False) and \
xbmcplugin.addDirectoryItem(int(sys.argv[1]), newpf[0], newpf[1], False)
xbmcplugin.addSortMethod(handle=int(sys.argv[1]), sortMethod=xbmcplugin.SORT_METHOD_LABEL)
xbmcplugin.endOfDirectory(int(sys.argv[1]), ok, cacheToDisc=False)
rwparris2
2008-09-06, 23:05
Thanks for answer but disableCache doesn't exists anymore : it's replaced by cacheToDisc parameter on xbmcplugin.endOfDirectory and there's no change
Right you are...
Have you tried simply adding rerunning the plugin after _delete, giving arguments to put the user back where he was?
Not sure what else to try if that doesn't work...
Maybe post a feature request on trac for xbmcplugin.refreshDirectoryItems() or something like that...
Still not working : items adding still fails xbmcplugin.addDirectoryItem() returns False when I try re reload list.
I've noticed that "directory handle" is -1 and after lots of searches, I still not understand what exactly is that handle ??? may be it's the problem source ?
jmarshall
2008-09-07, 01:02
Try just calling "Refresh" as a builtin perhaps?
I don't have the actual format in front of me - you can find all builtins listed in CUtil::ExecBuiltIn() (xbmc/Util.cpp)
Cheers,
Jonathan
Fantastic ! It works ! Thank you.
The correct call is :
xbmc.executebuiltin("Container.Refresh")
after an action.
rwparris2
2008-09-07, 03:36
Glad you got it working
Guess we should start using the appropriate .cpp files instead of the docs.
jmarshall
2008-09-07, 08:26
Glad you got it working :)
Aniecruz
2008-09-08, 12:24
In an effort to answer the emails and search patterns requesting active plugin currently in use on 5ThirtyOne, I’ve widdled through the plugins page deciding which ones I relied on most. I realized that quite a number of plugins were activated, yet unused. So I thank readers for their inquiries which prompted me to do a little Spring cleaning and sharing.
Bloggers always say that the content is what drives a blog into “stardom”. While completely true, there are some aspects of blogging which are often overlooked or receive very little attention.
---------------
Aniecruz
sneezer (http://www.drivenwide.com)
BigBellyBilly
2009-04-22, 15:23
Is it possible to delete an item from the container directly?