Do not fire the form_show event when visible is assigned the same value

Is there a good reason for the form_show event to be fired when a visible component is set to visible?

If yes, then please ignore this FR.

I can’t think find any good reason, but I have a good reason for form_show not to be fired: it causes execution of code that has already been executed.

I have created this little helper function:

def set_visible(comp, visible):
    if comp.visible != visible:
        comp.visible = visible

Then I have replaced a bunch of:

self.comp.visible = visible

With:

set_visible(self.comp, visible)

And the number of form_show events fired has decreased and the app is snappier.


EDIT
It’s worse than I thought :frowning:

I have a column panel cp1 containing a column panel cp2 containing a datagrid containing a repeating panel containing row item forms.

When items are added to the repeating panel, their form_show events are fired as expected.
When cp1.visible and cp2.visible are set to False, the datagrid is invisible.
When cp1.visible is set to True, cp2 is still invisible and so are its descendants, but the form_show events of the repeating panel items are all fired.

Is this a feature request or a bug?

Here is a little test app:
https://anvil.works/build#clone:4IWL4XN76PHYLXGX=UVLD2HQMKPTVHAYG6AAI2ED6

1 Like

form_show seems to be serving multiple purposes, here.

  1. A (very necessary) opportunity to do post-__init__ setup. __init__ is just too soon for some things.
  2. A way to get notified when visibility changes.

Triggering form_show, even when visible is not changing, seems to be a way to handle #1.

For backwards-compatibility, this probably can’t change. However, a new event, e.g., visible_changed, would let the code easily distinguish the two cases.

Alternatively, the form_show event parameters might be tweaked to allow the handler to distinguish between the cases.