Using the Template Canvas as a work-around for Zoom

I am currently using the Template Canvas for displaying a template that is my system layout. I have a dropdown component with different zoom percentages, and an update button. If a user selects a different zoom percentage and then clicks the update button, the window will run a timer script which re-populates the data in the Template canvas’s “.templates” attribute.

This all works as intended, however, Id really like to have the Template Canvas “focus” on a specific area when I do this zoom update, by initializing where the scroll bars are at when I do the update. I figured I could do this by setting the x and y columns to something like -100, -200 respectively and the Template Canvas would update with the scroll bars set to -100 and -200 in from the corner of the template… Instead it just cuts off 100 off the left of my template and 200 off the top of my template.

Please let me know if anyone has a suggestion for this! Thanks!

I have noticed several forum posts on similar topics:

But there has only been solutions to scrollbar incrementing. This is my solution to the "focus" or "Jump-to" issue....

from java.awt import Point
def TemplateCanvas_Focus():
	canvas = event.source.parent.parent.getComponent("Template Canvas")
	#### this is the java JScrollPane class... we can use any methods associated with JScrollPane here####
	scrollPane = canvas.getComponents()[2]
	####this is the java JSViewport class... we can use any methods associated with JViewport here####
	viewPort = scrollPane.getViewport()	
	
	if event.source.parent.getComponent('Dropdown for Zoom').selectedLabel == 'Full Screen':
		setViewPositionX = 0
		setViewPositionY = 0
	elif event.source.parent.getComponent('Dropdown for Zoom').selectedLabel == '75%':
		setViewPositionX = 0
		setViewPositionY = 350
	elif event.source.parent.getComponent('Dropdown for Zoom').selectedLabel == '100%':
		setViewPositionX = 250
		setViewPositionY = 500
	elif event.source.parent.getComponent('Dropdown for Zoom').selectedLabel == '200%':
		setViewPositionX = 1000
		setViewPositionY = 1000
	elif event.source.parent.getComponent('Dropdown for Zoom').selectedLabel == 'Max Zoom':
		setViewPositionX = 1500
		setViewPositionY = 1500
	
	
	viewPort.setViewPosition(Point(setViewPositionX,setViewPositionY))
1 Like

I used the viewPostition method on Ignition 8 and I was having issues with getting it to work until I ran this in an invokeAsynchronous function.

1 Like