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.


    Always checking text field

    Pythonista
    4
    9
    4731
    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.
    • techteej
      techteej last edited by

      Is there any way to make a function or something that will be running all the time? I want to always be checking if a text field is empty.

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

        Check out the TextField.delegate documentation. This might be what you are looking for.

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

          While you coulda use a threading.Thread or a Timer for example to continually do something in the background, there is not need to do so for your example.

          textfield_did_change gets called whenever you type a key for example, or, well, whenever the textfield changes. So, for example you could ls check whether the textfield is empty within that delegate function, and take whatever action you see fit (enabling another button, etc)

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

            Exactly. See the code at line 34 of https://github.com/humberry/ui-tutorial/blob/master/AreYouEnabledView.py to see how to enable/disable ui.Buttons based on the presence/absence of text in a ui.TextField.

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

              I'm looking to have a table update for every letter typed in the textfield.

              @ccc How would I implement this? Would it be using

              def set_actions(self):
                  # method 2: traversing all subviews
                  for subview in self.subviews:
                      if isinstance(subview, ui.TextField):
                          subview.delegate = self
                      elif isinstance(subview, ui.Button):
                          if subview.name == 'say hi':
                  # method 3: button-specific action methods
                              subview.action = self.say_hi  
                          else:
                              subview.action = self.button_pressed
              
              1 Reply Last reply Reply Quote 0
              • ccc
                ccc last edited by

                @techteej Put some sample code in a GitHub repo and we can edit it together.

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

                  @ccc Right here ;)

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

                    I created a separate NotepadView.py so I did not clobber your original code. it is somewhat workable in its current form.

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

                      Thanks for doing that. Will try to make some improvements then merge with original code.

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