Thread Rating:
  • 0 Vote(s) - 0 Average
Run code from context menu in Plugin
i want to call code block that is inside my current running plugin from selecting an item in a context menu.... is this possible to do without restarting the plugin?

ie. if i have in my
PHP Code:
def DoSomeLolThings(blah1,blah2):

i would like to run DoSomeLolThings('rofl','lmao') when i click the entry in the list item.

the code below is what i'm currently using to add list item.

PHP Code:
commands=GetContextItem('Add to Icefilms Favourites',icepath+'+/',"")
liz.addContextMenuItemscommandsreplaceItems=True )

def GetContextItem(name,script,arg):
commands = []
runner "XBMC.RunPlugin(" str(script) + str(arg) + ")"
commands.append(( str(name), runner, ))

this is what is use for the context items (to add/remove queue items from netflix), curX is the object that has the info label data for the movie/show.

When i add the item to the directory list, it's already got the context menu item associated with it

def addLink(name,url,curX,rootID=None):
    liz=xbmcgui.ListItem(name, iconImage="DefaultVideo.png", thumbnailImage=curX.Poster)
    liz.setInfo( type="Video", infoLabels={ "Mpaa": curX.Mpaa, "TrackNumber": int(curX.Position), "Year": int(curX.Year), "OriginalTitle": curX.Title, "Title": curX.TitleShort, "Rating": float(curX.Rating)*2, "Duration": str(int(curX.Runtime)/60), "Director": curX.Directors, "Genre": curX.Genres, "CastAndRole": curX.Cast, "Plot": curX.Synop })

    commands = []

    argsRemove = str(curX.ID) + "delete"
    argsAdd = str(curX.ID) + "post"
    argsSimilar = str(curX.ID)
    if rootID:
        argsRemove = str(rootID) + "delete"
        argsAdd = str(rootID) + "post"
        argsSimilar = str(rootID)
    runnerRemove = "XBMC.RunScript(special://home/addons/, " + argsRemove + ")"
    runnerAdd = "XBMC.RunScript(special://home/addons/, " + argsAdd + ")"
    runnerSearch = "XBMC.RunScript(special://home/addons/, " + argsSimilar + ")"

    if(not curX.TvEpisode):
        commands.append(( 'Netflix: Add to Instant Queue', runnerAdd, ))
        commands.append(( 'Netflix: Remove From Instant Queue', runnerRemove, ))
        #commands.append(( 'Netflix: Find Similar', runnerSearch, ))
        commands.append(( 'Netflix: Add Entire Season to Instant Queue', runnerAdd, ))
        commands.append(( 'Netflix: Remove Entire Season From Instant Queue', runnerRemove, ))

    liz.addContextMenuItems( commands )
    whichHandler = sys.argv[1]
    ok=xbmcplugin.addDirectoryItem(handle=int(whichHandler),url=url,listitem=liz, isFolder=False)

    return ok
thanks, i will give this a go when i get a chance

Run code from context menu in Plugin00