1 | n/a | #!/usr/bin/env python3 |
---|
2 | n/a | # |
---|
3 | n/a | # $Id: ncurses.py 36559 2004-07-18 05:56:09Z tim_one $ |
---|
4 | n/a | # |
---|
5 | n/a | # Interactive test suite for the curses module. |
---|
6 | n/a | # This script displays various things and the user should verify whether |
---|
7 | n/a | # they display correctly. |
---|
8 | n/a | # |
---|
9 | n/a | |
---|
10 | n/a | import curses |
---|
11 | n/a | from curses import textpad |
---|
12 | n/a | |
---|
13 | n/a | def test_textpad(stdscr, insert_mode=False): |
---|
14 | n/a | ncols, nlines = 8, 3 |
---|
15 | n/a | uly, ulx = 3, 2 |
---|
16 | n/a | if insert_mode: |
---|
17 | n/a | mode = 'insert mode' |
---|
18 | n/a | else: |
---|
19 | n/a | mode = 'overwrite mode' |
---|
20 | n/a | |
---|
21 | n/a | stdscr.addstr(uly-3, ulx, "Use Ctrl-G to end editing (%s)." % mode) |
---|
22 | n/a | stdscr.addstr(uly-2, ulx, "Be sure to try typing in the lower-right corner.") |
---|
23 | n/a | win = curses.newwin(nlines, ncols, uly, ulx) |
---|
24 | n/a | textpad.rectangle(stdscr, uly-1, ulx-1, uly + nlines, ulx + ncols) |
---|
25 | n/a | stdscr.refresh() |
---|
26 | n/a | |
---|
27 | n/a | box = textpad.Textbox(win, insert_mode) |
---|
28 | n/a | contents = box.edit() |
---|
29 | n/a | stdscr.addstr(uly+ncols+2, 0, "Text entered in the box\n") |
---|
30 | n/a | stdscr.addstr(repr(contents)) |
---|
31 | n/a | stdscr.addstr('\n') |
---|
32 | n/a | stdscr.addstr('Press any key') |
---|
33 | n/a | stdscr.getch() |
---|
34 | n/a | |
---|
35 | n/a | for i in range(3): |
---|
36 | n/a | stdscr.move(uly+ncols+2 + i, 0) |
---|
37 | n/a | stdscr.clrtoeol() |
---|
38 | n/a | |
---|
39 | n/a | def main(stdscr): |
---|
40 | n/a | stdscr.clear() |
---|
41 | n/a | test_textpad(stdscr, False) |
---|
42 | n/a | test_textpad(stdscr, True) |
---|
43 | n/a | |
---|
44 | n/a | |
---|
45 | n/a | if __name__ == '__main__': |
---|
46 | n/a | curses.wrapper(main) |
---|