Forum Archive

Always checking text field

techteej

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.

Dann239

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

JonB

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)

ccc

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.

techteej

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
ccc

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

techteej

@ccc Right here ;)

ccc

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

techteej

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