Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why can not to_file #283

Open
zhijiejia opened this issue Aug 12, 2022 · 5 comments
Open

Why can not to_file #283

zhijiejia opened this issue Aug 12, 2022 · 5 comments

Comments

@zhijiejia
Copy link

zhijiejia commented Aug 12, 2022

canvas = Canvas(width=200, height=200, sync_image_data=True)
canvas.fill_styled_rects(20, 20, 50, 50, color=[0,0,0])
canvas.to_file('test.png')
Traceback (most recent call last):
  File "/home/jzj/test.py", line 58, in <module>
    canvas.to_file('test.png')
  File "/home/jzj/miniconda3/lib/python3.9/site-packages/ipycanvas/canvas.py", line 420, in to_file
    raise RuntimeError(
RuntimeError: No image data to save, please be sure that ``sync_image_data`` is set to True
@martinRenou
Copy link
Collaborator

Thanks for opening an issue.

You need to make sure that the canvas has been updated before being able to to to_file. Try executing the to_file in a separate Notebook cell.

@zhijiejia
Copy link
Author

ok. Does this mean that I can't use ipycanvas in py files, if I want to export pictures (to_file) ?

@martinRenou
Copy link
Collaborator

It is indeed annoying in this case.

I've been thinking of allowing to make the to_file method async:

canvas = Canvas()
# Do drawings
await canvas.to_file('test.png')

But there are limitations in ipykernel and xeus-python that prevent from doing this for now. Hopefully it will be fixed at some point if this gets in: ipython/ipykernel#589

Though there might be other approaches. I'll try a few things when I have time.

@martinRenou
Copy link
Collaborator

ipyvolume seems to have a solution for taking screenshots of a widget: https://github.com/widgetti/ipyvolume/blob/master/ipyvolume/pylab.py#L1260-L1271

Thanks @maartenbreddels

@maartenbreddels
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants