Run code from context menu in Plugin - anarchintosh - 2011-01-08
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 default.py:
PHP Code: def DoSomeLolThings(blah1,blah2): print 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+'+/default.py',"") liz.addContextMenuItems( commands, replaceItems=True )
def GetContextItem(name,script,arg): commands = [] runner = "XBMC.RunPlugin(" + str(script) + str(arg) + ")" commands.append(( str(name), runner, )) return commands
thanks,
A
- fekker - 2011-01-08
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
Code: def addLink(name,url,curX,rootID=None):
ok=True
liz=xbmcgui.ListItem(name, iconImage="DefaultVideo.png", thumbnailImage=curX.Poster)
#if(xSummary):
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/plugin.video.xbmcflicks/resources/lib/modQueue.py, " + argsRemove + ")"
runnerAdd = "XBMC.RunScript(special://home/addons/plugin.video.xbmcflicks/resources/lib/modQueue.py, " + argsAdd + ")"
runnerSearch = "XBMC.RunScript(special://home/addons/plugin.video.xbmcflicks/resources/lib/modQueue.py, " + 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, ))
else:
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
- anarchintosh - 2011-01-08
thanks, i will give this a go when i get a chance
|