Drawing on a canvas inside a Repeating Panel

Hi, I’ve noticed some odd behaviour which might be a bug (and might be my misunderstanding!)

I have a form with a canvas in it. I can draw onto my canvas within the form_show() method of my form.
(See the form FormWithCanvas in my project below). So far, if I set FormWithCanvas as my Startup Form, I can see the canvas with drawing on it. Great!

Next, I want to repeat my initial form a number of times in another form. (See FormRepeating)
When I try to do this (and set FormRepeating as my Startup Form), my canvas(es) remain blank. I have a print statement that shows that the FormWithCanvas.form_show() is being called for each of my repeating components, but nothing appears on any canvas.

Here is a minimal example to show the behaviour:
https://anvil.works/build#clone:GX5P53ZWXMLCC6OU=46O2NOK4BMV54WTNBKGCAGLC

Hi @brendon_yenson,

Welcome to the forum!

Thanks for posting this, I have raised it as a bug to be fixed. The issue comes from trying to change the canvas component with a show event on the form. If you draw the canvas upon the startup forms __init__ and the canvas’ reset event then it works.

Here is a workaround:
https://anvil.works/build#clone:OOIFOHMPHK6LOSFC=IB5MATDRHO5Z2SUCNQ3OFNRL

For the workaround I changed the following:

  • I removed the show event handler in FormWithCanvas
  • I removed the show event handler in FormRepeating
  • I removed the show event handler of the canvas_1 component in FormWithCanvas
  • Added form_show to the reset event handler of the canvas_1 component in FormWithCanvas
  • Added a form_show call to the FormRepeating __init__

I hope that helps.

1 Like

Hi Ryan,

Thanks for that, much appreciated. Also for the speedy response and workaround :slight_smile:

I am really enjoying using Anvil for my hobby project, it’s awesome having the productivity gains from python in a webapp/database setting. It’s like MS Access for the modern age.

Cheers,
Brendon

PS: Oh, I have another bug report coming soon… in the Data Grid, showing/hiding rows and pagination interact in strange ways. Off the top of my head, I’m going to guess that the pagination uses the visible flag on the row. But I’ll start a new thread for that one.

Hi @brendon_yenson,

No problem, it’s great to hear you’re enjoying Anvil.

Happy to investigate any bugs you find.

Thanks,
Ryan