[Tutor] curses.wrapper() question
Alex from Caustic Creations
alex@caustic-creations.com
Thu Jul 17 17:27:12 2003
Hello,
I'm trying to learn python because I would like to create a simple cash
register application using curses. I read the curses howto and the
reference manual and both refer to the curses.wrapper function. The
advantages of using the wrapper are significant, yet I can't seem to
call it up properly.
I've included my "test.py" program - a compilation of all of the
statements in the curses howto so I could see and play around with their
effects. If anyone can find the time, could someone alter this little
demo program using the curses wrapper to illustrate its correct use?
Thanks so much in advance,
Alex
#### Begin Code
#!/usr/bin/python
#
# Alex's first attemopts at writing a curses interface using python
import curses
stdscr = curses.initscr()
curses.start_color()
curses.noecho()
curses.cbreak()
stdscr.keypad(1)
def newWindow():
begin_x = 20 ; begin_y = 7
height = 5 ; width = 40
win = curses.newwin(height, width, begin_y, begin_x)
return
stdscr.refresh()
newWindow()
# Windows and Pad test
pad = curses.newpad(100,100)
for y in range(0,100):
for x in range(0,100):
try: pad.addch(y,x, ord('a') + (x*x+y*y) % 26)
except curses.error: pass
pad.refresh(0,0, 5,5, 20,75)
# Display "Current Mode" line att he top of the screen
stdscr.addstr(0, 0, "Current mode: Typing mode",
curses.A_BOLD)
stdscr.refresh()
# Coloured text test
stdscr.refresh()
curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_BLACK)
stdscr.addstr( 0,80, "Pretty text", curses.color_pair(1) )
stdscr.refresh()
# Keyboard input test
while 1:
c = stdscr.getch()
if c == ord('p'): stdscr.addstr( 2,60, "You typed the letter p",
curses.color_pair(1) )
elif c == ord('q'): break
elif c == curses.KEY_HOME: x=y=0
# Ending curses politely
curses.nocbreak(); stdscr.keypad(0); curses.echo()
curses.endwin()
#### End Code