Vision: Button Template

For another approach, you can lean on our built in EventDelegateDispatchers class to automatically forward events (of certain types/all types) from a child component to a parent component provided by reference, i.e.

from com.inductiveautomation.ignition.client.util.gui import IgnitionSwingUtilities
from com.inductiveautomation.vision.api.client.components.model import TopLevelContainer
from com.inductiveautomation.factorypmi.application.components.util import EventDelegateDispatcher

KEY_EVENT_MASK = EventDelegateDispatcher.KEY_EVENT_MASK
MOUSE_EVENT_MASK = EventDelegateDispatcher.MOUSE_EVENT_MASK
FOCUS_EVENT_MASK = EventDelegateDispatcher.FOCUS_EVENT_MASK
ALL_EVENTS_MASK = EventDelegateDispatcher.ALL_EVENTS_MASK

def addForwardingEventListener(event, startSource = None, mask = ALL_EVENTS_MASK):
	startSource = event.source if startSource is None else startSource		
	parent = IgnitionSwingUtilities.getAncestorOfClass(TopLevelContainer, startSource.parent)
	EventDelegateDispatcher.initializeDispatchers(startSource, parent, mask)

The class internally does the event cloning + adjusts cursor points as necessary.

For a smaller refactor, you could also probably use something from Java's SwingUtilities to ease the mouse event translation, e.g:

5 Likes