Pass Mouse Event to Template Definition

The title basically sums it up.
Is there a method to dispatch a mouse event to the template definition of a template instance on a screen which does have a mouse event defined.

You can, but not directly. You create a new MouseEvent() with the target component (nesting inside the template instance) as its source, copying properties from the original event and adjusting coordinates as needed, then calling the target component’s .dispatchEvent() method.

So assuming I have a component called Path inside the template. Do I just use {path to template holder}.Path.dispatchEvent()?

I don’t understand how to reference internal components in a template holder.

No. You have to use .getComponent(0) (maybe twice?). Or something like that. I don’t recall precisely. The root container of the template is a couple layers down. (It’s not documented nor supported, fwiw.) And no, you can’t use component names like property names. Once you find the root of the template, you have to use .getComponent(“someName”) as usual.

1 Like

Thank you Phil! I will give that a try and report back.

Just to close the loop here:

I have a group of popup alarms that are invisible when the alarms are not active. This is the code under that group:

# Have to dispatch the event caught by the alarm buttons to the pump template
from java.awt.event import MouseEvent
evt = MouseEvent(
		 event.source.parent.getComponent('ARP5401').getComponent(0).getComponent("Group") #Get component 0 is a reference to the template itself.  Group is the name of the grouped objects in the template

This is the script under the template:

from java.awt import BasicStroke
if event.source.parent.InRemote:
	event.source.getComponent('Circle').strokeStyle = BasicStroke(3)
	event.source.getComponent('Polygon').strokeStyle = BasicStroke(3)
	event.source.getComponent('Rectangle 2').strokeStyle = BasicStroke(3)

So what happens is, when I pass my mouse over the invisible group the template border changes as it would if the group where not positioned on top of it.

Please note the first argument is referencing the object named “Group” instead of the root container. This is important to do otherwise any script referencing the event property in the template will not work properly.

Hope this helps someone!