Template Event Handlers - Events in template and template instance

I have a template created with a component that has mouseEntered and mouseExited scripts to produce a hover over effect. However I also want to be able to perform any action the developer wishes on the instance so I’ve left the template’s mouseClicked action empty.
To test, I dragged on a template into a Window and wrote a simple script to write to the console into the mouseClicked event handler, but this event never fires.

Is it possible to do this?

Travis’ post below suggests perhaps not… but I’m looking for some further clarification and other possible ideas for how I can achieve this.

In the mouseClicked event of the template you can dispatch the mouse event to the templates parent.

from java.awt.event import MouseEvent
evt = MouseEvent(
		 event.source.parent
		,event.getID()
		,event.getWhen()
		,event.getModifiers()
		,event.x
		,event.y
		,event.clickCount
		,event.popupTrigger
		,event.button)
event.source.parent.dispatchEvent(evt)	
4 Likes

Awesome! Thanks :slight_smile: I really need to learn more Java… and soon HTML5 and CSS

Hi,
I have a template instance where I want to check a template property value to do something. Where should I put my code? After or before your code? Should I reference something else?
This is what i want to do:

if not event.source.enabled:
print 1
else:
print 0

Thanks

Not sure how this relates at all to this forum topic?
However it doesn’t matter where you put your code, before or after, or in between. Assuming you format it correctly with white space, e.g your print statements should have tabs or spaces to indicate they’re part of the if and else bodies

I assumed that tabs/spaces will be understanded.

from java.awt.event import MouseEvent
evt = MouseEvent(
		 event.source.parent
		,event.getID()
		,event.getWhen()
		,event.getModifiers()
		,event.x
		,event.y
		,event.clickCount
		,event.popupTrigger
		,event.button)
event.source.parent.dispatchEvent(evt)

#enabled is a boolean template property
if not event.source.enabled:
    system.gui.messageBox("You have permission")
else:
    system.gui.messageBox("You don't have permission")

That’s how really is the code, indented and all. Anyway, the mouseClicked event don’t work on my template instance. I thought you were trying to do something related.

The code that jgjohnson posted will pass mouse click events through to the template instance so that I can handle mouseClicked events at the instance level. If you want to handle the click event inside the template, then you don’t need that code. You should just have your code in the mouseClicked event. For mouse click events, I tend to always use a button component to capture and handle those events. You can make the button unfocusable, no border, no background, and no text to make it essentially invisible but still provide an area to click. I found that handling mouse click events on the root had issues

Figured I’d piggy back on this for assistance with an issue.

I have a template that uses mouse entered/exited scripts within the template to set a custom property on the template. The custom property is 1 when entered and 0 when exited. I then bound a rectangles visible property to this custom property. This is done to achieve the same ‘hover’ effect you described.

For some reason it causes the border to constantly appear and disappear as the mouse passes through the space over the template. Is there a different or better way to achieve this outcome?

What component have you bound the mouse event scripts to? You should bind them to an “invisible” (note: not visible = false) button that is at the top of the Z-order.