npcole / npyscreen

Automatically exported from code.google.com/p/npyscreen
Other
481 stars 109 forks source link

Unable to change forms in beforeEditing() method #113

Open grasshopper139 opened 3 years ago

grasshopper139 commented 3 years ago

I have a form that does some API calls before calling the editing loop. If an exception is thrown, I want the parentApp to immediately switch to the MAIN form, however, it simply ignores the form switch and continues on with the method.

def beforeEditing(self):
    try:
        some_API_call()
    except something:
        self.parentApp.switchForm('MAIN')
jbrunner commented 3 years ago

As a workaround I solved this by overriding the edit method:

def beforeEditing(self):
    try:
        some_API_call()
        self._destroyMe = False
    except something:
        self.parentApp.setNextForm('MAIN')
        self._destroyMe = True

def edit(self):
    if not self._destroyMe:
        return super().edit()