forked from npcole/npyscreen
-
Notifications
You must be signed in to change notification settings - Fork 2
/
EXAMPLE-multiple-screens.py
executable file
·56 lines (41 loc) · 1.84 KB
/
EXAMPLE-multiple-screens.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python
import osc_npyscreen, curses
class MyTestApp(osc_npyscreen.NPSAppManaged):
def onStart(self):
# When Application starts, set up the Forms that will be used.
# These two forms are persistent between each edit.
self.addForm("MAIN", MainForm, name="Screen 1", color="IMPORTANT",)
self.addForm("SECOND", MainForm, name="Screen 2", color="WARNING", )
# This one will be re-created each time it is edited.
self.addFormClass("THIRD", MainForm, name="Screen 3", color="CRITICAL",)
def onCleanExit(self):
osc_npyscreen.notify_wait("Goodbye!")
def change_form(self, name):
# Switch forms. NB. Do *not* call the .edit() method directly (which
# would lead to a memory leak and ultimately a recursion error).
# Instead, use the method .switchForm to change forms.
self.switchForm(name)
# By default the application keeps track of every form visited.
# There's no harm in this, but we don't need it so:
self.resetHistory()
class MainForm(osc_npyscreen.ActionForm):
def create(self):
self.add(osc_npyscreen.TitleText, name = "Text:", value= "Press ^T to change screens" )
self.add_handlers({"^T": self.change_forms})
def on_ok(self):
# Exit the application if the OK button is pressed.
self.parentApp.switchForm(None)
def change_forms(self, *args, **keywords):
if self.name == "Screen 1":
change_to = "SECOND"
elif self.name == "Screen 2":
change_to = "THIRD"
else:
change_to = "MAIN"
# Tell the MyTestApp object to change forms.
self.parentApp.change_form(change_to)
def main():
TA = MyTestApp()
TA.run()
if __name__ == '__main__':
main()