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