I am having some trouble on the Jython end of creating a popup menu. The underlying goal (while perhaps not the best programming practice) is to have each item’s action perform a Jython command which is stored as a string in the database. I have a function called ‘generalFunction’ which is supposed to retrieve a string from the database depending on which item was selected. The problem is that when I setup the dictionary sequence to populate the popup (in the format of {‘Menu Text’:functionToCall} ) I cannot pass a parameter into my functionToCall (in my case it is generalFunction). If I define the action for the item to be generalFunction(idx), the function executes immediately which I do not want. I just want to assign a different instance of this function to each item in the popup menu.
Is there anyway to setup a function that can reference another function as a variable? Would I be better off going about this at the Java level and using the Java JMenuPopup documentation? Thanks in advance!
[code]qryText = “SELECT idx, popupText FROM %s WHERE id = %i AND roleId =%i” %(popupCfgTable, depth, roleId)
popupData = system.db.runQuery(qryText, dbname)
def generalFunction(idx=idx, event=event, selectedId=selectedId, selectedParentId=selectedParentId, popupCfgTable=popupCfgTable, depth=depth):
import system
import app
qryNames = “SELECT functionName FROM %s WHERE idx = %i” %(popupCfgTable, idx)
functionName = system.db.runScalarQuery(qryNames, dbname)
exec functionName
Obtain the unique id and popup message text based on the depth of the selection and the user’s role
popSequence = {}
for p in popupData:
idx = p[0]
popupText = p[1]
popSequence[popupText] = generalFunction
popSequence[popupText] = generalFunction(idx)
menu = system.gui.createPopupMenu(popSequence)
menu.show(event)[/code]