ipycanvas
ipycanvas copied to clipboard
Race condition in Pattern creation from Image widget
There is a race condition in the Pattern object creation from an Image widget.
Setting fill_style = pattern just after creating the pattern results in the fill_style to not be properly set. This seems to happen a lot more in JupyterLab than Jupyter Notebook.
We can fix it by making the style set async.
For reproducing this:
from ipywidgets import Image
from ipycanvas import Canvas, hold_canvas
import urllib.request
urllib.request.urlretrieve('https://github.com/martinRenou/ipycanvas/raw/master/examples/sprites/smoke_texture0.png', 'smoke_texture0.png')
sprite = Image.from_file('smoke_texture0.png')
canvas = Canvas(width=200, height=200)
pattern = canvas.create_pattern(sprite)
canvas.fill_style = pattern
canvas.fill_rect(0, 0, canvas.width, canvas.height)
canvas