Template canvas blinking/refreshing/loading

Hi,
I am using the template canvas to illustrate positions of robots. Meaning that the templates used are rectangles moving around the layout.

I am doing this by using cell update bindings on the x,y coordinates of the individual robots.
We have 15 robots so this means 30 cell update lines(x+y).

My problems is that everytime one position changes, the screen “blinks”. It is just a few ms, but its easely observable. I am pretty sure it is due to loading the canvas.

The second problem is that I have a drawing behind the template repeater. (illustration of the factory floor). And everytime the reapeater blinks/loads, the graphic behind is also blinking. Even though the template repeater(which is in front) has a transparent background.

Is there any way around this?
Maybe a fix to “disable loading indication”.
Or some code to turn the canvas.visible=0 during a cell update. and then back to 1 after the update has been finished.

Consider using a paintable canvas to draw your robot rectangles in the desired locations. Or more complicated robot imagery. As long as all of the data needed for the paint operation is kept local to the component/window, its update will be effectively instant. (No DB or other gateway callouts in the python.)

That is a good alternative to the template canvas i guess. It would be nice to be able to click on the various robots and open popups with details. Will this still be posible throught the paintable canvas?

Its a bit sad not to utilize the power of templates though :confused:

Is there any other way to place a normal template on a display, and set the position dynamically? For example, I have tried writing “component.x=100” but that is a read only property.

Yes, you can use mouse events with the paintable canvas. You'll have to to "find" the right rectangle within the canvas yourself, though.

Just a trade-off. Templates are low-performance overkill for drawing rectangles, as you've seen. If you want more complex imagery, you could write a generic "draw my robot" subroutine in a project script, including whatever text and animations you wish, called by the paint event multiple times. Re-use is re-use, whatever form it takes in the end.

Yes:
https://docs.inductiveautomation.com/display/DOC79/system.gui.transform

1 Like

I see, im trying out the paintable canvas now.

(Got quite far on just a few lines of code:
xCoords=system.tag.readBlocking(tagListX)
yCoords=system.tag.readBlocking(tagListY)
for i in range(0,15):
robot =Rectangle2D.Float(xCoords[i].value, yCoords[i].value, 50 , 50)
g.draw(robot))

Thanks for the answers!

You should not read tags inside your paint event–you can lock up your GUI. Bring all of your coordinates and any other dynamic information to the component in a dataset or other collection of properties. The paint event should only look up data that is already present in the client. Also, changes to custom properties on the canvas is what triggers repainting.

Thank you for the advice! That was actually my next question, how to trigger repainting.

How about the gui.transform, I like that one can include animation effects. How would you most efficiently trigger a for loop for gui.transform(s)

Don't use a for loop. Just fire the transform when coordinates change. (And its built-in animations do not require you to call it again.)

Just an update. The problem regarding this topic was fixed in the 8.06 Nightly build.

15065: Template Canvas - Changes to instance position shouldn’t reload all instances
Making positioning changes to an instance in a template canvas will no longer force all instances to reload.