473,654 Members | 3,253 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Searching for a working example of a curses application that resizes in xterm

Hi together,

can someone provide an example of a curses application that works in a
xterm that can be resized?

I could not find any working example yet...

Thanks in advance,
Sebastian 'Schwerdy' Schwerdhöfer

Sep 19 '05 #1
4 4120
Am Mon, 19 Sep 2005 03:40:38 -0700 schrieb schwerdy:
Hi together,

can someone provide an example of a curses application that works in a
xterm that can be resized?

I could not find any working example yet...


Hi,

You should find this in the C source of "mutt" or "less".

HTH,
Thomas
--
Thomas Güttler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de
Spam Catcher: ni************* *@thomas-guettler.de

Sep 19 '05 #2
sc******@web.de wrote:
can someone provide an example of a curses application that works in a
xterm that can be resized?


googling for "python sigwinch curses" brings up a considerable
number of related stuff, including

http://dbforums.com/archive/97/2002/07/4/439799

and

http://groups.google.com/group/comp....fa595d97e90040

and a couple of related bug reports and discussions about why
they're not bugs, plus the source code for a couple of curses-
based Python programs.

</F>

Sep 19 '05 #3
On 2005-09-19, sc******@web.de <sc******@web.d e> wrote:
can someone provide an example of a curses application that works in a
xterm that can be resized?


I'm afraid I can't post the entire program, but what you need
to do is to catch the WINCH signal and set a flag which is
checked by your main "event" loop and handled. Here's the
basic C code:

static void sigwinchHandler (int sig)
{
(void) sig;
sigwinchReceive d = 1;
}

static void clipWindows(voi d)
{
tCh *ch;
int x,y,rows,cols;

for (ch = chlist; ch != NULL; ch = ch->next)
{
getbegyx(ch->win,y,x);
getmaxyx(ch->win,rows,cols) ;
clipwin(&rows,& cols,&y,&x);
moveWindow(ch,r ows,cols,y,x);
}
}
main()
{
[...]
sigact.sa_handl er = sigwinchHandler ;
s = sigaction(SIGWI NCH, &sigact, NULL);
assert(s==0);
// start up curses
while (1)
{
// do stuff
if (sigwinchReceiv ed)
{
struct winsize size;
if (ioctl(fileno(s tdout), TIOCGWINSZ, &size) == 0)
{
resizeterm(size .ws_row, size.ws_col);
clipWindows();
}
sigwinchReceive d = 0;
}
}
}

--
Grant Edwards grante Yow! If I am elected no
at one will ever have to do
visi.com their laundry again!
Sep 19 '05 #4
Thanks, but I had already read these discussions (hope the grammar is
correct...), and thought I understood them. But my exact problem: If I
resize a xterm, in most cases curses prints crap (if it does not crash
python). And I could not find any python-curses application that is
displayed correctly after a terminal resize.

I hope nobody will kill me, 'cause I'm a spammer; here is my example:

------
import curses

def gettermres():
"""
returns the current terminal size in columns and lines
"""
import struct, fcntl, sys, termios
lines, cols = struct.unpack(" HHHH",
fcntl.ioctl(sys .stdout.fileno( ),termios.TIOCG WINSZ, struct.pack("HH HH",
0, 0, 0, 0)))[:2]
return cols, lines

def splitwin(scr, extend1, axis=0, isPercent=True,
useFullScreen=F alse):
"""
splits the scr in 2 windows and return both
extend1 is the size of the first window
axis=0 --> split horizontal
axis=1 --> split vertical
if isPercent is False, extend1 will be interpreted as absolut size
"""
if isPercent and not 0 < extend1 < 100:
raise "extend1 must be between 0 and 100"
if not axis in (0,1):
raise "axis must be 0 or 1"

if useFullScreen:
res = [0,0]
res[1], res[0] = gettermres()
pos = (0,0)
else:
res = scr.getmaxyx()
pos = scr.getbegyx()

size1 = list(res)
size2 = list(res)

if isPercent:
totallen = float(res[axis])
size1[axis] = int( totallen*extend 1 / 100 )
else:
size1[axis] = extend1

size2[axis] = res[axis] - size1[axis]
start1 = list(pos)
start2 = list(pos)
start2[axis] = size1[axis]

win1 = curses.newwin(s ize1[0], size1[1], start1[0], start1[1])
win2 = curses.newwin(s ize2[0], size2[1], start2[0], start2[1])

return win1, win2

def startcurses(std scr):
curses.use_defa ult_colors() # transparency
curses.init_pai r(2, curses.COLOR_GR EEN, -1)

while 1:
curses.setupter m()
winTop, winBottom = splitwin(stdscr , 80, useFullScreen=T rue)
winLeft, winRight = splitwin(winTop , 50, 1)
winLeft.border( )
winLeft.noutref resh()
winRight.border ()
winRight.addstr (1,1,"hallo", curses.color_pa ir(2))
winRight.noutre fresh()
winBottom.borde r()
winBottom.noutr efresh()
curses.doupdate ()
k = winLeft.getch()
if k == ord('q'):
break

curses.wrapper( startcurses)
------

Sep 20 '05 #5

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

Similar topics

3
2746
by: Brian | last post by:
Hello; I'm writing a program with curses in python and having a bit of trouble understanding how to use unittest. So far, I have used testing successfully -- as long as the report goes to stdout (or does unittest write to stderr?) The curses part of the program seems to affect unittest's writing of the report. The screen is not what the report expects, so a lot of information is in the wrong place after the program exits. (I actually...
0
1866
by: Matt Garman | last post by:
I'd like to write a class or module in python that allows me to do on-the-fly color changing in the curses module. I'm thinking about something along the lines of this: addstr(y, x, 'hello', brightyellow, blue) The module would automatically interpret the above as curses.init_pair(i, curses.COLOR_YELLOW, curses.COLOR_BLUE)
3
2803
by: harold fellermann | last post by:
Hi all, I want to use curses in a server application that provides a GUI for telnet clients. Therefore, I need the functionality to open and handle several screens. Concerning http://dickey.his.com/ncurses/ncurses-intro.html#init this can be done using the function newterm(type,ofp,ifp). However, this function seems not to be defined in the python library. Does anyone know how this can be done in python?
0
1262
by: Rob Thomas | last post by:
Hey guys, Having a problem with a script using the curses module... It works fine if I start it like so: screen python script.py However, if I want to start it in detached mode (i restart it every day through cron, so I need to be able to do this), like so:
30
6083
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
3685
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>
1
9146
by: Nick ! | last post by:
Chris Share <usenet at caesium.me.ukwrote: http://web.cs.mun.ca/~rod/ncurses/ncurses.html#xterm says "The ncurses library does not catch 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...
0
968
by: skip | last post by:
I have a fairly simple curses app which is giving me this error: addstr() returned ERR I'm trapping it and continuing. I can see that *some* of my addstring calls succeed. This one happens to be screen.addstr(row, 39, "|") where row is 3. After the screen was cleared two other calls to addstr
1
2354
by: Michael Goerz | last post by:
Hi, I'm trying to print out text in color. As far as I know, curses is the only way to do that (or not?). So, what I ultimately want is a curses terminal that behaves as closely as possible as a normal terminal, i.e. it breaks lines and scrolls automatically, so that I can implement a function myprint(color, text) that does what print() does, only in color. So, my first tests brought up some problems:
0
8294
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8816
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8709
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...
1
8494
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8596
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
4150
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...
1
2719
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
1
1924
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1597
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.