Mailing List Archive

Question: copy/deepcopy with the curses module?
I'm writing a small program which uses the standard curses module.
While the program runs I show message boxes, sometimes two levels deep. At
this point I have a nice layered display. Good so far. :)

Now, the user interacts with the topmost message box so that it
dissapears. To repaint the screen I'm clearing it and repainting everything
from scratch. The end result is what I want but the performance is, shall
we say, somewhat pitiful. On a fast machine the user probably wouldn't
notice but on a slower machine the user can actually track the progress of
the paint process.

The code is layered like this...

class SIO: <contains methods which interact with curses>
self.stdscr = curses.init...()
self.s = newwin(...)

class MsgBox(DialogContainer):
def __init__(self, Screen, Message):
self.SetProperty("SCREEN", Screen) # Screen points to instance
of SIO


All my classes use the same instance of SIO (which basically provides a
wrapper around displaying text on the console).

What I want to do is get a snapshot of the current SIO instance. This
would allow me to quickly save the current SIO instance in a temp. variable,
do some screen updates, and then quickly repaint the screen by restoring the
SIO instance to it's older value.

I tried to use the Copy module (copy and deepcopy) but it complained
about how it couldn't copy the curses stuff.

Anyone have any pointers? (note: I'd like to do this using the standard
modules which are distributed with Python 1.5.2)


Damond
Question: copy/deepcopy with the curses module? [ In reply to ]
On Sun, 15 Aug 1999 16:51:08 GMT, Damond Walker <dwalker@iximd.com> wrote:
> What I want to do is get a snapshot of the current SIO instance. This
>would allow me to quickly save the current SIO instance in a temp. variable,
>do some screen updates, and then quickly repaint the screen by restoring the
>SIO instance to it's older value.

Here's a suggestion (that I haven't tried): create a new window the
size of the entire screen and render the SIO instance into it; this
should overwrite all the other information on the screen. Then
restore the old display by deleting the new window and refreshing the
screen. Something like 'win = stdscr.newwin(0,0) ; ... do stuff with
win ; del win ; stdscr.refresh()'...

--
A.M. Kuchling http://starship.python.net/crew/amk/
The garden of Destiny. Look behind you: shadow-plays of memory are forever
being enacted, on paths you walked too long ago.
-- From SANDMAN #47: "Brief Lives:7"
Question: copy/deepcopy with the curses module? [ In reply to ]
A.M. Kuchling wrote in message ...
>
>Here's a suggestion (that I haven't tried): create a new window the
>size of the entire screen and render the SIO instance into it; this
>should overwrite all the other information on the screen. Then
>restore the old display by deleting the new window and refreshing the
>screen. Something like 'win = stdscr.newwin(0,0) ; ... do stuff with
>win ; del win ; stdscr.refresh()'...
>


Since I posted the original message I found inch(). I was thinking
about saving the text that is about to be overwritten, and when I'm done
with the current object, just repaint from this buffer. Throw this code
into my class Dialog (which is nothing more than a screen region if you look
at it from a certain standpoint) and it becomes automagic.
Unless, of course, the window will take care of all that for me. I'll
hack it out later tonight. The buffer method would probably be quite slow.
:)
There is nothing stopping me from manhandling the SIO instance for while
there are many objects using it, only one uses it at a time. So it becomes
a matter of cleaning up after myself.

Damond