Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Can I use a Delegate to interact with another control, and if so, how?
-
I have a view. On the view, I have a textfield and a button. Until the textfield has text, the button is disabled. Currently, I have to enter text into the textfield and THEN press Enter in order to trigger the textfield action to enable the button.
Is there a way to use the
textview_did_end_editing
method to enable the button? -
You can use
textfield_did_change
:class TextDelegate (object): def textfield_did_change(self, textfield): view = textfield.superview button = view['button'] button.enabled = textfield.text != ''
-
Perfect answer, Omega0.
I usually make the main View the delegate of the various subviews because then you have all other UI elements directly available without redirection.
If the main View is the textfield's delegate then the above code becomes a oneliner:
class MyMainView(ui.View): [ ... ] def textfield_did_change(self, textfield): self.button.enabled = textfield.text != ''
-
Thanks!