0

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.

flyboy
  • 21
  • 2

2 Answers2

0

I'm still digging, but I have discovered that it appears safe_to_exit is not implemented on all widgets. Changing the widget from "TitleText" to "Textfield" resulted in the validations code firing.

flyboy
  • 21
  • 2
0

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
flyboy
  • 21
  • 2