Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Python3 curses behavior

Reply
Thread Tools

Python3 curses behavior

 
 
Vlasov Vitaly
Guest
Posts: n/a
 
      02-09-2013
Hello.

I found strange behavior of curses module, that i can't understand. I initialize screen with curses.initscr(), then i create subwin of screen with screen.subwin(my_subwin_sizes). After that i fill subwin with my_char in for-loop. On last char in last line subwin.addch() raises exception.

This is my problem. Why? How to fix it?

(If i will ignore exception, then last char will be displayed)

Here simple example:
http://pastebin.com/SjyMsHZB

Thank You!
 
Reply With Quote
 
 
 
 
Chris Angelico
Guest
Posts: n/a
 
      02-09-2013
On Sat, Feb 9, 2013 at 10:23 PM, Vlasov Vitaly <(E-Mail Removed)> wrote:
> Hello.
>
> I found strange behavior of curses module, that i can't understand. I initialize screen with curses.initscr(), then i create subwin of screen with screen.subwin(my_subwin_sizes). After that i fill subwin with my_char in for-loop. On last char in last line subwin.addch() raises exception.
>
> This is my problem. Why? How to fix it?
>
> (If i will ignore exception, then last char will be displayed)
>
> Here simple example:
> http://pastebin.com/SjyMsHZB


What exception is being raised? That's kinda the most important part here

ChrisA
 
Reply With Quote
 
 
 
 
Vlasov Vitaly
Guest
Posts: n/a
 
      02-09-2013
суббота, 9 февраля 2013*г., 15:28:51 UTC+4 пользователь Chris Angelico написал:
> On Sat, Feb 9, 2013 at 10:23 PM, Vlasov Vitaly <(E-Mail Removed)> wrote:
>
> > Hello.

>
> >

>
> > I found strange behavior of curses module, that i can't understand. I initialize screen with curses.initscr(), then i create subwin of screen withscreen.subwin(my_subwin_sizes). After that i fill subwin with my_char in for-loop. On last char in last line subwin.addch() raises exception.

>
> >

>
> > This is my problem. Why? How to fix it?

>
> >

>
> > (If i will ignore exception, then last char will be displayed)

>
> >

>
> > Here simple example:

>
> > http://pastebin.com/SjyMsHZB

>
>
>
> What exception is being raised? That's kinda the most important part here
>
>
>
> ChrisA


curses.error <-- all curses-related exception
Exception text: curses.error: 'addch() returned ERR'
 
Reply With Quote
 
Vlasov Vitaly
Guest
Posts: n/a
 
      02-09-2013
суббота, 9 февраля 2013*г., 15:28:51 UTC+4 пользователь Chris Angelico написал:
> On Sat, Feb 9, 2013 at 10:23 PM, Vlasov Vitaly <(E-Mail Removed)> wrote:
>
> > Hello.

>
> >

>
> > I found strange behavior of curses module, that i can't understand. I initialize screen with curses.initscr(), then i create subwin of screen withscreen.subwin(my_subwin_sizes). After that i fill subwin with my_char in for-loop. On last char in last line subwin.addch() raises exception.

>
> >

>
> > This is my problem. Why? How to fix it?

>
> >

>
> > (If i will ignore exception, then last char will be displayed)

>
> >

>
> > Here simple example:

>
> > http://pastebin.com/SjyMsHZB

>
>
>
> What exception is being raised? That's kinda the most important part here
>
>
>
> ChrisA


curses.error <-- all curses-related exception
Exception text: curses.error: 'addch() returned ERR'
 
Reply With Quote
 
Terry Reedy
Guest
Posts: n/a
 
      02-09-2013
On 2/9/2013 6:23 AM, Vlasov Vitaly wrote:
> Hello.
>
> I found strange behavior of curses module, that i can't understand. I
> initialize screen with curses.initscr(), then i create subwin of
> screen with screen.subwin(my_subwin_sizes). After that i fill subwin
> with my_char in for-loop. On last char in last line subwin.addch()
> raises exception.


I have never used curses but I have used text screens. I suspect that
addch moves the cursor to the position beyond where the character is
added, but there is no such position. I remember having problems writing
to the last char of a 24x80 screen without getting either a scroll or
beep if scrolling was disabled.

> This is my problem. Why? How to fix it?


Perhaps this will help:
window.leaveok(yes)
If yes is 1, cursor is left where it is on update, instead of being at
“cursor position.” This reduces cursor movement where possible. If
possible the cursor will be made invisible.

> (If i will ignore exception, then last char will be displayed)


Otherwise, just catch the exception, as you already discovered.

> Here simple example: http://pastebin.com/SjyMsHZB


--
Terry Jan Reedy


 
Reply With Quote
 
Vlasov Vitaly
Guest
Posts: n/a
 
      02-10-2013
суббота, 9 февраля 2013*г., 23:22:47 UTC+4 пользователь Terry Reedy написал:
> On 2/9/2013 6:23 AM, Vlasov Vitaly wrote:
>
> > Hello.

>
> >

>
> > I found strange behavior of curses module, that i can't understand. I

>
> > initialize screen with curses.initscr(), then i create subwin of

>
> > screen with screen.subwin(my_subwin_sizes). After that i fill subwin

>
> > with my_char in for-loop. On last char in last line subwin.addch()

>
> > raises exception.

>
>
>
> I have never used curses but I have used text screens. I suspect that
>
> addch moves the cursor to the position beyond where the character is
>
> added, but there is no such position. I remember having problems writing
>
> to the last char of a 24x80 screen without getting either a scroll or
>
> beep if scrolling was disabled.
>
>
>
> > This is my problem. Why? How to fix it?

>
>
>
> Perhaps this will help:
>
> window.leaveok(yes)
>
> If yes is 1, cursor is left where it is on update, instead of being at
>
> “cursor position.” This reduces cursor movement where possible. If
>
> possible the cursor will be made invisible.
>
>
>
> > (If i will ignore exception, then last char will be displayed)

>
>
>
> Otherwise, just catch the exception, as you already discovered.
>
>
>
> > Here simple example: http://pastebin.com/SjyMsHZB

>
>
>
> --
>
> Terry Jan Reedy


Thank you.

I tried everything in my test script.
win.leaveok() - no effect
curses.cur_vis() - no effect
win.scrollok() - start newline and place cursor on it

It's only one last option:
on last line last char try/except with pass.
 
Reply With Quote
 
Vlasov Vitaly
Guest
Posts: n/a
 
      02-10-2013
суббота, 9 февраля 2013*г., 23:22:47 UTC+4 пользователь Terry Reedy написал:
> On 2/9/2013 6:23 AM, Vlasov Vitaly wrote:
>
> > Hello.

>
> >

>
> > I found strange behavior of curses module, that i can't understand. I

>
> > initialize screen with curses.initscr(), then i create subwin of

>
> > screen with screen.subwin(my_subwin_sizes). After that i fill subwin

>
> > with my_char in for-loop. On last char in last line subwin.addch()

>
> > raises exception.

>
>
>
> I have never used curses but I have used text screens. I suspect that
>
> addch moves the cursor to the position beyond where the character is
>
> added, but there is no such position. I remember having problems writing
>
> to the last char of a 24x80 screen without getting either a scroll or
>
> beep if scrolling was disabled.
>
>
>
> > This is my problem. Why? How to fix it?

>
>
>
> Perhaps this will help:
>
> window.leaveok(yes)
>
> If yes is 1, cursor is left where it is on update, instead of being at
>
> “cursor position.” This reduces cursor movement where possible. If
>
> possible the cursor will be made invisible.
>
>
>
> > (If i will ignore exception, then last char will be displayed)

>
>
>
> Otherwise, just catch the exception, as you already discovered.
>
>
>
> > Here simple example: http://pastebin.com/SjyMsHZB

>
>
>
> --
>
> Terry Jan Reedy


Thank you.

I tried everything in my test script.
win.leaveok() - no effect
curses.cur_vis() - no effect
win.scrollok() - start newline and place cursor on it

It's only one last option:
on last line last char try/except with pass.
 
Reply With Quote
 
Dan Stromberg
Guest
Posts: n/a
 
      02-11-2013
Sent from my android phone.
On Feb 10, 2013 2:09 PM, "Vlasov Vitaly" <(E-Mail Removed)> wrote:
>
> , 9 2013 ., 23:22:47 UTC+4 Terry Reedy

:
> > On 2/9/2013 6:23 AM, Vlasov Vitaly wrote:

>
> > --
> >
> > Terry Jan Reedy

>
> Thank you.
>
> I tried everything in my test script.
> win.leaveok() - no effect
> curses.cur_vis() - no effect
> win.scrollok() - start newline and place cursor on it
>
> It's only one last option:
> on last line last char try/except with pass.


I doubt this is a Python 2 or Python 3 problem; historically some terminal
types curses supports could not fill the lower right-most character cell
without causing an undesired scroll of the screen by one line. So portable
curses programs avoid filling that spot with anything.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: is the same betweent python3 and python3.2? Andrew Berg Python 0 06-16-2012 11:11 AM
Quirky Curses behavior?? Eric Armstrong Ruby 2 07-21-2006 07:14 AM
Re: Replacing curses (Was: Re: Problem with curses and UTF-8) Jean-Paul Calderone Python 2 02-09-2006 08:29 AM
python3: 'where' keyword Andrey Tatarinov Python 97 01-16-2005 12:04 PM
undefined behavior or not undefined behavior? That is the question Mantorok Redgormor C Programming 70 02-17-2004 02:46 PM



Advertisments