1

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()
D D
  • 37
  • 3

1 Answers1

1

Actually, I got rid of this problem by doing something following:

class Form1(npyscreen.Form):
    def create(self):
        self.name = "I'm the first form! I am so happy!"

    def afterEditing(self):
        self.parentApp.setNextForm("second")

class Form2(npyscreen.Form):
    def create(self):
        self.name = "Im the second form!"

    def afterEditing(self):
        self.parentApp.setNextForm("MAIN")

class App(npyscreen.NPSAppManaged):
    def onStart(self):
        self.registerForm("MAIN", Form1())
        self.registerForm("second", Form2())

With this, you cans switch between those two forms via clicking the well known "OK" buttons. I mean, it works for me.

EDIT #1: I am sorry, that i answered you 10 months after you've asked for that, but I just started using npyscreen.

EDIT #2: I must say, that npyscreen is a very good way to create python console applications with UI. I tried doing something similar on my own, back in the days when I was obsessed with Python, but you might guess how it went on...

Kazafka
  • 17
  • 5