Scripton / Docs

Synchronization

Usually, Canvas operations execute as soon as possible. For instance, consider the following example:

from scripton.canvas import Canvas from time import sleep canvas = Canvas(width=640, height=480) canvas.draw_circle(x=100, y=100, radius=100, fill='red') sleep(1) canvas.draw_circle(x=300, y=300, radius=50, fill='blue')

The first circle appears on the canvas immediately, while the second one shows up after a 1 second delay due to the sleep call.

More realistically, you may have a series of drawing operations that you want to present simultaneously rather than progressively. For such scenarios, you can use a Canvas.sync block that ensures all nested drawing operations are presented only when the block exits. Behind the scenes, Scripton automatically routes rendering calls to an offscreen buffer and defers its presentation.

For the example above, the synchronized version would be as follows:

from scripton.canvas import Canvas from time import sleep canvas = Canvas(width=640, height=480) with canvas.sync(): canvas.draw_circle(x=100, y=100, radius=100, fill='red') sleep(1) canvas.draw_circle(x=300, y=300, radius=50, fill='blue')

Both circles will now be shown simultaneously after a 1 second delay when the with block exits.