Passing parameter(s) to Popup menu?

How can pass parameter to popup menu (or function called by popup menu)?

I want to have a global script to show me a popup menu called Reset, when I right click on the label or text field. In this labels I show numbers, which occasionally needs to be reset to zero.

Because I have 20 fields on the screen, I need to pass to the popup menu function a parameter, so the function will know, which field values in database needs to be reset.

The easiest way to do this is with a custom property on each label:

  1. Create a label, giving it a string custom property of ‘tagName’. Write the full path of the SQLTag to be reset to this property.

  2. In both the mousePressed and mouseReleased events of the label (required so it will run cross-platform), put the following code:menu = app.util.getPopup()

  3. Create a new module called ‘util’ in the Script Module Editor and put the following code in it:[code]def getPopup():
    import system

    The function which is carrying out the resetting

    def reset(event):
    import system

    tagName = event.source.tagName
    system.tag.write(tagName, 0)

    Create the actual popup menu and return it

    popup = system.gui.createPopupMenu([“Reset”],[reset])
    return popup[/code]Now when you right-click on the label you will get a popup containing a ‘Reset’ entry - clicking this will set the point back to zero.

If you want to reset to any other value you can change the value in the reset function. If you want to reset different points to different values, you will have to create another custom property for each label and use this within the reset function.

Thank you again. I didn’t even considered (remembered) custom properties (this is my first ‘real’ project)… :slight_smile:

Over the weekend I found this way:

In the mouseReleased event I put:

menu = app.util.resetPopup("mesalo_egalizacija") <--- this is my filed name in DB

In ScriptModule Editor I create ‘util’ and put this:

def resetPopup(objekt):
	import system
	def reset(event):
		username =
		roles =
		if "Administrator" in roles:
			if system.gui.confirm("Do you really want to reset?", "UPOZORENJE!"):
				num = system.db.runUpdateQuery("UPDATE hour_meter SET " + objekt + " = 0 WHERE " + objekt + " <> 0;")
				system.gui.messageBox("Deleted rows: %d" % num)
			system.gui.messageBox("Only administrator can reset!")

	resetPopup = system.gui.createPopupMenu(["Reset"],[reset])
	return resetPopup

I guess, when I acquire some mileages it’ll get easier… :slight_smile:

Regards from sLOVEnia