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

Blank canvas, no image data #357

Closed
flsmith opened this issue Sep 10, 2024 · 1 comment
Closed

Blank canvas, no image data #357

flsmith opened this issue Sep 10, 2024 · 1 comment

Comments

@flsmith
Copy link

flsmith commented Sep 10, 2024

When trying to draw anything using ipycanvas in JupyterLab, I'm getting a blank canvas displayed and no image data being stored even with sync_image_data = True. I'm not using Voila here, though the blank canvas display looks similar to #342 and I've tried the solution there.

import numpy as np
from ipycanvas import Canvas

canvas = Canvas(width=200, height=200, sync_image_data = True)

canvas.fill_rect(25, 25, 100, 100)
canvas.clear_rect(45, 45, 60, 60)
canvas.stroke_rect(50, 50, 50, 50)

canvas.get_image_data()
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Cell In[8], line 10
      7 canvas.clear_rect(45, 45, 60, 60)
      8 canvas.stroke_rect(50, 50, 50, 50)
---> 10 canvas.get_image_data()

File [/opt/conda/lib/python3.11/site-packages/ipycanvas/canvas.py:444](https://teachinghub.st-andrews.ac.uk/opt/conda/lib/python3.11/site-packages/ipycanvas/canvas.py#line=443), in _CanvasBase.get_image_data(self, x, y, width, height)
    435 """Return a NumPy array representing the underlying pixel data for a specified portion of the canvas.
    436 
    437 This will throw an error if there is no ``image_data`` to retrieve, this happens when nothing was drawn yet or
   (...)
    441 are (``x + width``, ``y + height``).
    442 """
    443 if self.image_data is None:
--> 444     raise RuntimeError(
    445         "No image data, please be sure that ``sync_image_data`` is set to True"
    446     )
    448 x = int(x)
    449 y = int(y)

RuntimeError: No image data, please be sure that ``sync_image_data`` is set to True

Versions are as follows:

Jupyterlab 4.2.0
ipycanvas 0.13.3
ipywidgets 8.1.2

Any help appreciated, and I'm happy to help get more details.

@flsmith
Copy link
Author

flsmith commented Sep 11, 2024

This was caused by a version difference with the labextension which had previously been installed to ~/.local for some reason; apologies for the false report.

@flsmith flsmith closed this as completed Sep 11, 2024
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

1 participant