saving curses screen state (putwin() and getwin() again)

M

Matt Garman

I'm working on a curses-based application in Python. I've
implemented what I call a "Chooser" (a fancy name for a menu):

---> 1. Choice 1 <---
2. Choice 2
3. Choice 3

So the user can use the arrow keys to change choices. When he hits
enter, the screen is re-drawn with a new interface. When that
interface is quit, the screen should return to the Chooser, exactly
as it was left.

So my strategy is to call putwin() before going to the new
interface, and call getwin() after returning from the previous
interface.

This works as described the *first* time, but subsequent calls to
getwin() return the window that was saved with the first call to
putwin(). I.e., it's as though only the first call to putwin() has
any effect.

Any thoughts?

Thanks!
Matt
 
M

Mike Meyer

Matt Garman said:
I'm working on a curses-based application in Python. I've
implemented what I call a "Chooser" (a fancy name for a menu):

---> 1. Choice 1 <---
2. Choice 2
3. Choice 3

So the user can use the arrow keys to change choices. When he hits
enter, the screen is re-drawn with a new interface. When that
interface is quit, the screen should return to the Chooser, exactly
as it was left.

So my strategy is to call putwin() before going to the new
interface, and call getwin() after returning from the previous
interface.

This works as described the *first* time, but subsequent calls to
getwin() return the window that was saved with the first call to
putwin(). I.e., it's as though only the first call to putwin() has
any effect.

Any thoughts?

Yes. Show us some code, please. There are any number of bugs that
could cause this behavior, and it'd be easier to narrow things down if
we knew what you were actually doing.

<mike
 
D

Douglas Soares de Andrade

Can you release a source code for this program ? Im wanting to use curses and
python, but havent found any doc.

Thanks !


Em Qua 10 Nov 2004 04:48, Matt Garman escreveu:
 
M

Matt Garman

Yes. Show us some code, please. There are any number of bugs that
could cause this behavior, and it'd be easier to narrow things
down if we knew what you were actually doing.

I was hoping that the error was well-known or obvious and that
wouldn't be necessary.

Anyway, I posted some code that exhibits this behavior on my
website, http://www.raw-sewage.net/

Specifically, download the following files (and save in a common
directory):

http://raw-sewage.net/newwin.py
http://raw-sewage.net/curseschooser.py
http://raw-sewage.net/cursescolors.py

Then run the script "newwin.py". You are initially presented with
an option menu; the selection is controlled by either the up and
down arrow keys or 'j' and 'k'.

Example run to duplicate buggy behavior:

1. Run newwin.py, arrow down to option '3', press enter
2. The screen will redraw; press 'q' to go back to the menu
3. The screen should appear in the state you left it when you
pressed enter from the option menu (i.e. choice 3 selected)
4. Now choose option 5, press enter
5. The alternate screen appears, press 'q' to quit it
6. Now, the screen will re-draw as it did in step (3) above,
i.e. choice 3 is highlighted, *not* choice 5 where you left
off
7. But, if you use the up/down arrow keys, you'll realize that
the option menu thinks it left off on choice 5 (even though
it's not highlighted).

The behavior is consistent on my Linux box, running the following
version of Python:

Python 2.3.4 (#1, Oct 17 2004, 14:17:06)
[GCC 3.3.4 20040623 (Gentoo Linux 3.3.4-r1, ssp-3.3.2-2, pie-8.7.6)]
on linux2

Thanks again!
Matt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,740
Latest member
AdolphBig6

Latest Threads

Top