我正在使用npyscreen构建一个简单的应用程序来构建精美的菜单。正如文档所说,我使用switchForm()
检索到的方法self.parentApp
来更改当前显示的表单。但是,当被调用时,splash.show_splash()
什么都没有发生(应用程序退出,因为setNextForm
is None
)。
如何正确切换表格?
源代码 :
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()