I am building a simple application using npyscreen to build fancy menus. As the documentation says, I use the switchForm()
method retrieved by self.parentApp
to change the currently displayed form. However, when called in splash.show_splash()
nothing happens (the application quits, since setNextForm
is None
).
How do you properly switch forms?
Source code :
class splash(npyscreen.Form):
def afterEditing(self):
self.parentApp.switchFormPrevious()
def create(self):
self.new_splash = self.add(npyscreen.Pager, values=BANNER)
class whatDo(npyscreen.FormBaseNewWithMenus):
def afterEditing(self):
self.parentApp.setNextForm(None)
def create(self):
self.add(npyscreen.TitlePager, name="Hello")
self.m1 = self.new_menu(name="File", shortcut=None)
self.m1.addItemsFromList([
("M1-A", self.open),
("M1-B", self.new),
("M1-C", self.exit_application),
])
self.m2 = self.new_menu(name="Edit", shortcut=None)
self.m2.addItemsFromList([
("M2-A", self.open),
("M2-B", self.new),
])
self.m3 = self.new_menu(name="Other", shortcut=None)
self.m3.addItemsFromList([
("M3-A", self.open),
("M3-A", self.show_splash)
])
def show_splash(self):
self.parentApp.switchForm('SPLASH')
def exit_application(self):
self.parentApp.switchForm(None)
def open(self):
pass
def new(self):
pass
class MyApplication(npyscreen.NPSAppManaged):
def onStart(self):
self.addForm('MAIN', whatDo, name='Main Menu')
self.addForm('SPLASH', splash, lines=30, name='Splash Form')
if __name__ == '__main__':
TestApp = MyApplication().run()