Hi, I'm trying to create a vertical scrollable template canvas in ignition (vision module) that contains multiple instances of a certain custom template called collapsablePanel. this Panel contains a template repeater. When the mouse pointer is on top of the repeater, it blocks the user from being able to scroll on the canvas. I'm trying to figure out how to pass the scrolling from the repeater on to the canvas. Below you can find the code I cooked up trying to pass the scroll events, but it doesn't work as expected. To show the hierarchy, I represented them with some variables. If you are wondering what the reason is behind all the "else None"s, it is sometimes possible that the hierarchy of the components isn't loaded yet during runtime.
from java.awt.event import MouseWheelEvent, MouseWheelListener
# Get the Template Repeater component
templateRepeater = event.source
# Traverse the component hierarchy safely
collapsablePanelTemplate = templateRepeater.getParent() if templateRepeater else None
layoutPanel = collapsablePanelTemplate .getParent() if collapsablePanelTemplate else None
jViewport = layoutPanel.getParent() if layoutPanel else None
templateCanvas1 = jViewport.getParent() if jViewport else None
templateCanvas = templateCanvas1.getParent() if templateCanvas1 else None
# Check if the target component (templateCanvas) is not None
if templateCanvas is None:
print("templateCanvas is None. Component hierarchy is not intact.")
else:
print("templateCanvas found, proceeding with listener registration.")
# Define a custom MouseWheelListener to forward the scroll events to the templateCanvas
class CustomMouseWheelListener(MouseWheelListener):
def mouseWheelMoved(self, e):
print("Mouse wheel moved event captured.") # Debug line to confirm event capture
# Create a new MouseWheelEvent for the correct parent component (templateCanvas)
newEvent = MouseWheelEvent(
templateCanvas, # Forward to the templateCanvas
e.getID(),
e.getWhen(),
e.getModifiers(),
e.getX(),
e.getY(),
e.getClickCount(),
e.isPopupTrigger(),
e.getScrollType(),
e.getScrollAmount(),
e.getWheelRotation()
)
print("Dispatching new mouse wheel event to templateCanvas.") # Debug line to confirm event dispatch
# Dispatch the new event to the templateCanvas
templateCanvas.dispatchEvent(newEvent)
# Remove any existing MouseWheelListener (to avoid duplicates)
for listener in templateRepeater.getMouseWheelListeners():
templateRepeater.removeMouseWheelListener(listener)
print("Removed an existing MouseWheelListener from templateRepeater.") # Debug line to confirm listener removal
# Add the custom MouseWheelListener to the Template Repeater
templateRepeater.addMouseWheelListener(CustomMouseWheelListener())
print("Added custom MouseWheelListener to templateRepeater.") # Debug line to confirm listener addition
Any help would be greatly appreciated, Thanks!
Kevin