Refresh a plugin listing
#1
Hello,
I'm currently write a plugin and I want to add/remove items by context menu actions.
So I call actions with
Code:
item.addContextMenuItems( [ ("foo", "XBMC.RunPlugin(...)") ] )

but once action is done, how to update listing ?
I've tried
Code:
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
Reply
#2
Any way you could post your full code? I have an idea but need to see how you've written everything else first....
Always read the XBMC online-manual, FAQ and search and search the forum before posting.
For troubleshooting and bug reporting please read how to submit a proper bug report.

If you're interested in writing addons for xbmc, read docs and how-to for plugins and scripts ||| http://code.google.com/p/xbmc-addons/
Reply
#3
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):
Code:
# 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 :
Code:
## 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 :
Code:
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):
Code:
## 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
Code:
sys.modules.clear()
Fails each times ! (I don't know if it's normal or not)
Reply
#4
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://trac.xbmc.org/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!
Always read the XBMC online-manual, FAQ and search and search the forum before posting.
For troubleshooting and bug reporting please read how to submit a proper bug report.

If you're interested in writing addons for xbmc, read docs and how-to for plugins and scripts ||| http://code.google.com/p/xbmc-addons/
Reply
#5
Thanks for answer but disableCache doesn't exists anymore : it's replaced by cacheToDisc parameter on xbmcplugin.endOfDirectory and there's no change Huh

And items are added this way :
Code:
## 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)
Reply
#6
Quote: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...
Always read the XBMC online-manual, FAQ and search and search the forum before posting.
For troubleshooting and bug reporting please read how to submit a proper bug report.

If you're interested in writing addons for xbmc, read docs and how-to for plugins and scripts ||| http://code.google.com/p/xbmc-addons/
Reply
#7
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 Huh may be it's the problem source ?
Reply
#8
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
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


Image
Reply
#9
Fantastic ! It works ! Thank you.
The correct call is :
Code:
xbmc.executebuiltin("Container.Refresh")
after an action.
Reply
#10
Glad you got it working

Guess we should start using the appropriate .cpp files instead of the docs.
Always read the XBMC online-manual, FAQ and search and search the forum before posting.
For troubleshooting and bug reporting please read how to submit a proper bug report.

If you're interested in writing addons for xbmc, read docs and how-to for plugins and scripts ||| http://code.google.com/p/xbmc-addons/
Reply
#11
Glad you got it working Smile
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


Image
Reply
#12
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
Reply
#13
Is it possible to delete an item from the container directly?
Retired from Add-on dev
Reply

Logout Mark Read Team Forum Stats Members Help
Refresh a plugin listing0