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
Fails each times ! (I don't know if it's normal or not)