omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    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?

    Pythonista
    3
    4
    2730
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • robinsiebler112
      robinsiebler112 last edited by

      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?

      1 Reply Last reply Reply Quote 0
      • Omega0
        Omega0 last edited by

        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 != ''
        
        1 Reply Last reply Reply Quote 0
        • ccc
          ccc last edited by

          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 != ''
          
          1 Reply Last reply Reply Quote 0
          • robinsiebler112
            robinsiebler112 last edited by

            Thanks!

            1 Reply Last reply Reply Quote 0
            • First post
              Last post
            Powered by NodeBB Forums | Contributors