As promised, here’s the update.
@david.wylie’s first recommendation (raising an alert and processing the server call from there) appears to work as expected. That said, it introduces a good amount of complexity, and (unfortunately for me) I’d need to do quite a bit of refactoring to deploy it successfully in my app.
@alcampopiano’s idea didn’t work out. The with
context works great with Notifications, but it doesn’t disable other interactions while inside the with
block. Users were still able to click buttons visible in the background of the notification. Using an alert in a with
context didn’t work at all - once the alert is called, further processing seems to be suspended until the alert is dismissed. So, while it did raise an alert and prevent interaction, it didn’t allow the server call to proceed.
I also took a shot in the dark and tried something like this, but I couldn’t get it working:
with alert(content=content_blocking_form()):
anvil.server.call('foo_bar')
self.raise_event('x-close-alert', value=None)
After all that, I wound up skipping both notifications and alerts, and instead I recursively disable/enable all buttons from a MainForm method (I have a multi-page app with shared nav that’s owned by a form called MainForm
).
The MainForm
method looks like this:
def recursively_toggle_buttons(self, component, enabled):
if isinstance(component, Button):
component.enabled = enabled
elif isinstance(component, (self.__class__, ColumnPanel, FlowPanel, DataGrid, DataRowPanel, LinearPanel, XYPanel, GridPanel)):
for cmp in component.get_components():
self.recursively_toggle_buttons(cmp, enabled)
And then my interaction handler contains something like this:
get_open_form().recursively_toggle_buttons(
get_open_form(),
enabled=False
)
anvil.server.call('foo_bar', active_flags=active_flags_list)
get_open_form().recursively_toggle_buttons(
get_open_form(),
enabled=True
)
This has the effect of disabling all buttons while the server call executes and then re-enabling them all when it’s done. It’s not ideal since I may need some custom handling for specific buttons in the future, but it does the trick for now.
I think there’s a feature request in here: a flag to disable user interactions while inside a with Notification():
context. Thoughts?
Further ideas/improvements welcome. Thanks again for your help.