Curses and resizing windows
Thomas Dickey
dickey at saltmine.radix.net
Wed Feb 28 16:01:43 EST 2007
Nick ! <kousue at gmail.com> wrote:
> http://web.cs.mun.ca/~rod/ncurses/ncurses.html#xterm says "The ncurses
> library does not catch [the SIGWINCH aka resizing] signal, because it
> cannot in general know how you want the screen re-painted". First, is
> this really true? When I make my xterms smaller they clip what is
no - given that particular url is a file dating from 1995, it's something
that I overlooked in making corrections here:
http://invisible-island.net/ncurses/ncurses-intro.html
But also note where I link it from:
http://invisible-island.net/ncurses/ncurses.faq.html#additional_reading
> displayed--is that a function of curses or the xterm?
both - xterm sends the signal, and curses receives it.
> Second, if true, it explains /what/ is going on--stdscr, only--, but
> isn't really satisfactory; it doesn't solve the original poster's bug.
> #!/usr/bin/env python
> """
> curses_resize.py -> run the program without hooking SIGWINCH
> curses_resize.py 1 -> run the program with hooking SIGWINCH
> """
> import sys, curses, signal, time
> def sigwinch_handler(n, frame):
> curses.endwin()
> curses.initscr()
Actually I'd expect to see curses.refresh() here - but that may be a quirk
of the python code.
In general, ncurses passes a KEY_RESIZE via the getch() call that the
application (such as python) should process. If it's not reading from
getch(), ncurses' repainting/resizing won't happen.
Also, if you add your own signal handler, ncurses' SIGWINCH catcher won't
work. (I'd recommend chaining the signal handlers, but don't know if
python supports that ;-).
> def main(stdscr):
> """just repeatedly redraw a long string to reveal the window boundaries"""
> while 1:
> stdscr.insstr(0,0,"abcd"*40)
> time.sleep(1)
> if __name__=='__main__':
> if len(sys.argv)==2 and sys.argv[1]=="1":
> signal.signal(signal.SIGWINCH, sigwinch_handler)
> curses.wrapper(main)
--
Thomas E. Dickey
http://invisible-island.net
ftp://invisible-island.net
More information about the Python-list
mailing list