Search code examples
pythonnpyscreen

I cannot make safe_to_exit method in npyscreen work


I think I missing something very basic but I cannot make this function work.
I am running python 3.6.12 on Redhat with npyscreen 4.10.5. My expectation is that the safe_to_exit function could be used to validate any input immediately when the user exits the field (using the tab key) but I cannot make it fire at all. Possibly I have misunderstood this completely. Here is my test code, cut down to make it as simple as possible:

import npyscreen

def test1(*args):
    F = npyscreen.Form(name='My Test Application')
    Field1 = F.add(npyscreen.TitleText, name="My Test Field")
    Field1.safe_to_exit = Field1_Validations
    F.edit()
    return Field1.value

def Field1_Validations():
    npyscreen.notify_confirm("Safe to exit")
    return True


if __name__ == '__main__':
    onefield = npyscreen.wrapper_basic(test1)
    print("Results are : {} ".format(onefield))

Any pointers would be greatly appreciated.


Solution

  • After much hair pulling I worked it out. They syntax is (applying to the code sample above):

    self.Field1.entry_widget.safe_to_exit = Field1_Validations