I’m working with a new custom component that is, at its core, a repeating panel with doodads tacked on. The form shown in the list needs to come from the app using the component, not from the component itself, so I gave the custom component a display_form
property and set its type to Form
.
This setup gives a really nice drop down selection of all available forms in the app, but when I assign one and run the app, the property’s value is the form name as a str
rather than the form itself. Is there a way that I can find the form object I want in the app using this name only? I know that I can pass the form objects necessary via code during __init__
and suchlike, but I was hoping that I could have a more GUI-oriented approach to this component.
Also, and this is a small thing, but once I’ve assigned a form from my app to this property, I can’t change the property back to None
(blank drop down) using the GUI. I don’t know if that feature would be generally desirable, but it would be of some benefit for this particular component.
I’ve figured out a way to get a form from the string provided through my display_form
property, but it’s not an optimal solution by far.
if isinstance(self.display_form, str):
open_form(self.display_form)
self.display_form = get_open_form().__class__
get_open_form().clear()
So this basically opens the form during the app’s __init__
, stores its class, and then clears the contents of the opened form so there’s hopefully no flickering going on. This works simply as a proof of concept, but I think in the end that having to mess around with the GUI to find a form instance is going to cause a lot of issues.
I’m still looking, mostly trying to dig through globals()
and the anvil
package itself to see what I can find, but I’m still stumped for a good option.
This is an impressive workaround! I think the real answer here is to get the __import__
function working in Skulpt, so you can import forms by name.
Just a heads up: “Form” properties can be set either to a string or to a class; I think the correct answer will probably involve making the runtime deliver a class object to you by default.
(They’re not well-documented API surface yet; I’d forgotten that was even an option in the Custom Component settings!)
1 Like
Yeah, that’s kind of what I was thinking would have to be done too, though the notion of just being able to set two drop downs at design time and forgetting about it is very appealing. I’ve had a couple other ideas, but they all involve some amount of compliant design from the person using the component. I think that ultimately just having the designer set the properties at runtime is going to be the cheapest solution until a design time option is found.
Thanks for the feedback!