3
# $Id: ncurses.py 66424 2008-09-13 01:22:08Z andrew.kuchling $
5
# (n)curses exerciser in Python, an interactive test for the curses
6
# module. Currently, only the panel demos are ported.
9
from curses import panel
11
def wGetchar(win = None):
12
if win is None: win = stdscr
25
curses.napms(nap_msec)
28
stdscr.move(curses.LINES - 1, 0)
32
def mkpanel(color, rows, cols, tly, tlx):
33
win = curses.newwin(rows, cols, tly, tlx)
34
pan = panel.new_panel(win)
35
if curses.has_colors():
36
if color == curses.COLOR_BLUE:
37
fg = curses.COLOR_WHITE
39
fg = curses.COLOR_BLACK
41
curses.init_pair(color, fg, bg)
42
win.bkgdset(ord(' '), curses.color_pair(color))
44
win.bkgdset(ord(' '), curses.A_BOLD)
54
num = pan.userptr()[1]
57
win.addstr("-pan%c-" % num)
61
maxy, maxx = win.getmaxyx()
62
for y in range(2, maxy - 1):
63
for x in range(1, maxx - 1):
68
global stdscr, nap_msec, mod
71
mod = ["test", "TEST", "(**)", "*()*", "<-->", "LAST"]
75
for y in range(0, curses.LINES - 1):
76
for x in range(0, curses.COLS):
77
stdscr.addstr("%d" % ((y + x) % 10))
79
p1 = mkpanel(curses.COLOR_RED,
80
curses.LINES // 2 - 2,
86
p2 = mkpanel(curses.COLOR_GREEN,
87
curses.LINES // 2 + 1,
93
p3 = mkpanel(curses.COLOR_YELLOW,
100
p4 = mkpanel(curses.COLOR_BLUE,
101
curses.LINES // 2 - 2,
103
curses.LINES // 2 - 2,
107
p5 = mkpanel(curses.COLOR_MAGENTA,
108
curses.LINES // 2 - 2,
111
curses.COLS // 2 - 2)
122
saywhat("press any key to continue")
125
saywhat("h3 s1 s2 s4 s5;press any key to continue")
135
saywhat("s1; press any key to continue")
140
saywhat("s2; press any key to continue")
145
saywhat("m2; press any key to continue")
146
p2.move(curses.LINES // 3 + 1, curses.COLS // 8)
150
saywhat("s3; press any key to continue")
155
saywhat("m3; press any key to continue")
156
p3.move(curses.LINES // 4 + 1, curses.COLS // 15)
160
saywhat("b3; press any key to continue")
165
saywhat("s4; press any key to continue")
170
saywhat("s5; press any key to continue")
175
saywhat("t3; press any key to continue")
180
saywhat("t1; press any key to continue")
185
saywhat("t2; press any key to continue")
190
saywhat("t3; press any key to continue")
195
saywhat("t4; press any key to continue")
200
for itmp in range(0, 6):
204
saywhat("m4; press any key to continue")
205
w4.move(curses.LINES // 8, 1)
207
p4.move(curses.LINES // 6, itmp * curses.COLS // 8)
208
w5.move(curses.LINES // 6, 1)
213
saywhat("m5; press any key to continue")
214
w4.move(curses.LINES // 6, 1)
216
p5.move(curses.LINES // 3 - 1, itmp * 10 + 6)
217
w5.move(curses.LINES // 8, 1)
222
saywhat("m4; press any key to continue")
223
p4.move(curses.LINES // 6, (itmp + 1) * curses.COLS // 8)
227
saywhat("t5; press any key to continue")
232
saywhat("t2; press any key to continue")
237
saywhat("t1; press any key to continue")
242
saywhat("d2; press any key to continue")
247
saywhat("h3; press any key to continue")
252
saywhat("d1; press any key to continue")
257
saywhat("d4; press any key to continue")
262
saywhat("d5; press any key to continue")
271
# one fine day there'll be the menu at this place
273
curses.wrapper(demo_panels)