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_editingmethod to enable the button?
You can use
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 != ''