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.


    Question About Delegates in UI

    Pythonista
    3
    5
    2733
    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.
    • AtomBombed
      AtomBombed last edited by

      I am currently making a note writing application that will pop up as a sheet over the script that you are currently editing as a workflow to make it possible to write notes about your script, without needing to leave your script. (None of this matters, just some background.)

      I am wondering how to make a delegate work for a view that has been made using the UI editor, and not created through the script as "ui.Button(title="button)". I really need this to use the delegate to find out when text has been inserted into a TextView. That way, every time the text changes on the TextView, I will have the delegate run the appropriate function to change the text of a label to display the total amount of characters on the TextView currently.

      So basically: I want to figure out how to make delegates work for views created via UI designer, and not created through the script. That's all I need.

      <b>PLEASE POST CODE EXAMPLES, SO I CAN SEE WHAT IS GOING ON WITH THE CODE.</b>

      Much appreciated,
      Sean.

      1 Reply Last reply Reply Quote 1
      • Webmaster4o
        Webmaster4o last edited by

        Say you make the view in the UI editor. Name the textfield something specific. I'll assume it's called my_textfield. Now, with code, you can say

        import ui 
        v=ui.load_view()
        text=v['my_textfield']
        text.delegate=DELEGATE_NAME_HERE
        

        You will have to write the delegate with code, in case that's what you're asking. You can't create the delegate in the UI editor.

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

          You might want to check out the ui-tutorial in the Pythonista-Tools repo.

          1 Reply Last reply Reply Quote 1
          • ccc
            ccc last edited by

            import console, ui
            
            class MyTextViewDelegate(object):
                def textview_did_change(self, textview):
                    console.hud_alert('{} characters'.format(len(textview.text)))
            
            v = ui.load_view()  # the .pyui file needs a ui.TextView named 'textview1'
            v.name = 'Character Count'
            v['textview1'].delegate = MyTextViewDelegate()
            v.present('sheet')
            
            1 Reply Last reply Reply Quote 0
            • AtomBombed
              AtomBombed last edited by

              OH MY GOSH! Thank you so much. I can't believe I didn't think they'do be listed as a list ready for "getitem". I kept getting a "getitem" error because I was using it in the wrong terminology. I really appreciate your help! This is so nice. You guys are the best.

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