473,765 Members | 2,034 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Curses and resizing windows

Chris Share <usenet at caesium.me.ukwr ote:
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.

odd (thanks for the example - I don't know if this is a problem in
ncurses or in the python interface to it, but will check/see).
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.

probably should report it as a bug (so it's not overlooked).

--
Thomas E. Dickey
http://invisible-island.net
ftp://invisible-island.net
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
displayed--is that a function of curses or the xterm?
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.p y -run the program without hooking SIGWINCH
curses_resize.p y 1 -run the program with hooking SIGWINCH
"""
import sys, curses, signal, time

def sigwinch_handle r(n, frame):
curses.endwin()
curses.initscr( )

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__=='__ma in__':
if len(sys.argv)== 2 and sys.argv[1]=="1":
signal.signal(s ignal.SIGWINCH, sigwinch_handle r)
curses.wrapper( main)

If you run this without sigwinch then the line never gets resized, but
if you do then it works fine. What we can glean from this is that
stdscr only reads off it's size upon initialization. This behaviour
may seem a bit strange, but 1) it's legacy and 2) avoids breaking the
semantics of windows (which don't change size on their own).

The "curses.initscr ()" part is kind of unhappy though. It modifies the
stdscr variable without us explicitly assigning anything (but I can't
think of any other way to do it, beyond making stdscr a global, and
that feels worse) and will break if initscr() ever returns a new
Window structure instead of just updating and returning the old one.
Does anyone have any tips for how to structure this so that the screen
can actually be assigned to?

In conclusion, it's not a bug, it's a feature. Joy! The workaround is
to write a sigwinch_handle r that at least does `endwin(); initscr()`.

Sorry for reviving an old thread, but it doesn't seem the issue was
ever resolved (the thread doesn't go anywhere and there's no warning
about this in the docs that I noticed).

(please CC: me if anyone cares, I'm not on the list)

-Nick Guenther
Feb 28 '07 #1
1 9169
Nick ! <ko****@gmail.c omwrote:
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/...tional_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.p y -run the program without hooking SIGWINCH
curses_resize.p y 1 -run the program with hooking SIGWINCH
"""
import sys, curses, signal, time
def sigwinch_handle r(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__=='__ma in__':
if len(sys.argv)== 2 and sys.argv[1]=="1":
signal.signal(s ignal.SIGWINCH, sigwinch_handle r)
curses.wrapper( main)
--
Thomas E. Dickey
http://invisible-island.net
ftp://invisible-island.net
Feb 28 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1647
by: jbi130 | last post by:
I've built a small curses app with an IRC like interface (not for IRC tho). The last remaining item is to handle resizing the terminal on SIGWINCH. I've tried a few things and everything is failing. I first try to resize my root window using resize() but then my calls to resize other windows usually fail.. Whats the proper or common way to handle a resize? I added on the ncurses extention resizeterm() to _cursesmodule.c and that...
3
2822
by: Abhijit Soman | last post by:
Where can i find curses module for windows? I have pdcurses library on windows. But python binary doesnot include curses module. Thanks, Abhijit
1
911
by: Chris Share | last post by:
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...
1
3295
by: Riccardo Galli | last post by:
Hi, I'm writing some widgets in curses. Actually I'm trying to write a combobox. To do so, I need to create a pad inside a panel, so that I can hide/show it. I can't do it. I can create a normal pad, but if I try to create it using "subpad" from a window I get _curses_panel.error: curses function returned NULL
10
2845
by: Michael | last post by:
I am having a hard time trying to find out how to stop windows from line wrapping using the curses library. Does anyone know how? Thanks, Michael
30
6116
by: Ian Ward | last post by:
When I run the following code in a terminal with the encoding set to UTF-8 I get garbage on the first line, but the correct output on the second. import curses s = curses.initscr() s.addstr('\xc3\x85 U+00C5 LATIN CAPITAL LETTER A WITH RING ABOVE\n') s.addstr('\xc3\xa5 U+00F5 LATIN SMALL LETTER O WITH TILDE') s.refresh() s.getstr()
1
3694
by: Jerry Fleming | last post by:
Hi, I have wrote a game with python curses. The problem is that I want to confirm before quitting, while my implementation doesn't seem to work. Anyone can help me? #!/usr/bin/python # # Brick & Ball in Python # by Jerry Fleming <jerryfleming@etang.com>
7
2854
by: Gasten | last post by:
Hello. The last weeks I've been coding a roguelike (you know, like nethack) in python using the nCurses library. Some week ago I ran into a problem: When I made the object for messagebar-output, I found a bug that I can't figure out (believe me; I've tried everything and asked for help several times on the IRC-channel). The updateMsg() and iMsg() takes a list of message-lines as argument (or process a string to a list), and it'll output...
15
4814
by: pinkfloydhomer | last post by:
I need to develop a cross-platform text-mode application. I would like to do it in Python and I would like to use a mature text-mode library for the UI stuff. The obvious choice, I thought, was ncurses. But as far as I can tell, it is not available for Python on Windows? Is there a workaround? Or are there alternative libraries that might be used instead of (n)curses? I know I can use (n)curses on *nix and console on Windows etc., but...
0
9568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10007
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9835
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5276
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3924
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.