-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathncurse_test.py
More file actions
executable file
·91 lines (72 loc) · 3.6 KB
/
Copy pathncurse_test.py
File metadata and controls
executable file
·91 lines (72 loc) · 3.6 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env python
'''
CREDIT: Derived from https://bitbucket.org/npcole/npyscreen/src/default/examples/EXAMPLE-multiple-screens.py
Copyright (c) 2004--2009, Nicholas P. S. Cole (n@npcole.com)
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER ''AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
'''
import npyscreen
import curses
class MyTestApp(npyscreen.NPSAppManaged):
def onStart(self):
npyscreen.setTheme(npyscreen.Themes.ElegantTheme)
# 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="NORMAL",)
self.addForm("SECOND", MainForm, name="Screen 2", color="IMPORTANT",)
# This one will be re-created each time it is edited.
self.addFormClass("ABOUT", MainForm, name="Screen 3", color="WARNING",)
def onCleanExit(self):
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(npyscreen.ActionFormV2):
def create(self):
self.add(npyscreen.TitleText, name="Text:", value="Press ^T to change screens")
self.add_handlers({"^T": self.change_forms})
if(self.name == "Screen 1"):
self.add(npyscreen.CheckBox)
def on_ok(self):
# TODO: Print something if OK button is pressed:
print("print")
def on_cancel(self):
# Exit the application if the cancel 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 = "ABOUT"
else:
change_to = "MAIN"
# Tell the MyTestApp object to change forms.
self.parentApp.change_form(change_to)
def handle_mouse_event(self, mouse_event):
mouse_id, rel_x, rel_y, z, bstate = self.interpret_mouse_event(mouse_event)
# Do things here...
def main():
TA = MyTestApp()
TA.run()
if __name__ == '__main__':
main()