Curses and resizing windows

Chris Share usenet at caesium.me.uk
Mon Jun 21 22:45:13 EDT 2004


I've been writing an application using curses, and have been trying to
handle resizing the terminal, if running in xterm or similar. Increasing
the window size is working perfectly, however shrinking it is not
working at all. No matter how much I shrink the window, the size
returned by getmaxyx() does not change. However as soon as I increase it
again, it works fine. 

I've tracked the problem down to the fact I have created a window
derived from stdscr. A small script showing the effect is at the end of
this post. 

Can anyone suggest how to solve this problem, that doesn't involve not
making a derwin of stdscr?

I've been googling for hours, but found nothing to help.

Python version is 2.3.4 on debian testing.

chris

#!/usr/bin/python
import curses, sys

def init_display(stdscr):
    stdscr.clear()
    stdscr.refresh()
    size = stdscr.getmaxyx()
    sys.stderr.write("Now %u x %u\n" % (size[1],size[0]))
    rootwin = stdscr.derwin(20, 50, 0, 0)
    return rootwin

def main(stdscr):
    rootwin = init_display(stdscr)
    while 1:
        input = rootwin.getch()
        if ( input == curses.KEY_RESIZE):
            init_display(stdscr)
        elif input == ord("q"):
            sys.exit()
        rootwin.refresh()

curses.wrapper(main)



More information about the Python-list mailing list