curses errors on addch to a subwin

This is the place for queries that don't fit in any of the other categories.

curses errors on addch to a subwin

Postby pnelsonsr » Tue Dec 17, 2013 8:29 pm

I've been working with curses and I ran across a problem that I'm hoping that I'm doing something wrong.

The problem setup is using curses create a stdscr and then put a subwin (win1) on that screen (with box() borders). Then try to add a character ('x') to the bottom right corner of win1 (which is the last row and the last character). The code to show this follows:
Code: Select all
#!/bin/python
import curses
def main(stdscr) :
  stdscr=curses.initscr()
  curses.start_color()
  stdscr.clear()
  stdscr.refresh()
  win1=stdscr.subwin(5,40,0,0)
  win1.box()
  win1.refresh()
  win1.addch(4,38,'x')
  win1.refresh()
  curses.napms(1000)
  win1.addch(4,39,'x')
  win1.refresh()
  curses.napms(5000)
if __name__ == '__main__':
  curses.wrapper(main)

This produces an error:
Code: Select all
Traceback (most recent call last):
  File "./smalltest3", line 35, in <module>
    curses.wrapper(main)
  File "/usr/lib/python2.7/curses/wrapper.py", line 43, in wrapper
    return func(stdscr, *args, **kwds)
  File "./smalltest3", line 15, in main
    win1.addch(4,39,'x')
_curses.error: addch() returned ERR

The curses.napms(500) and curses.napms(5000) simply hold the screen for a few seconds so you can see it. So am I doing something wrong?

Note: I updated the above because I found that the problem is any window so I just got rid of the second window (win2), but I kept the box in win1 to show that its the last character of the last line in the window (win1).
pnelsonsr
 
Posts: 25
Joined: Thu Dec 12, 2013 12:48 am

Re: curses errors on addch to a subwin

Postby pnelsonsr » Tue Dec 17, 2013 9:25 pm

I found a way to insert a character by changing

Code: Select all
win1.addch(4,39,'x')
with
Code: Select all
win1.insch(4,38,'x')

So i guess I can put a check in any code to push text to a window and if it is the last character of the last row use insch() instead of addch().
pnelsonsr
 
Posts: 25
Joined: Thu Dec 12, 2013 12:48 am


Return to General Coding Help

Who is online

Users browsing this forum: Google [Bot] and 6 guests