tempfile and curses (putwin() and getwin())

Matt Garman fake at not-real.bogus
Fri Nov 5 14:50:34 EST 2004


I've been working on a curses-based application in Python.  My
application effectively has a series of screens (or windows).  When
one screen closes, the previous screen should be exactly redrawin in
its original state (i.e., before the sub-screen was created).

As far as I can tell, the putwin() and getwin() functions can easily
solve this problem.  So I can do something like this:

    # draw/write some stuff on stdscr...
    addStuffToStdScr()
    
    # save the state of stdscr to a file named 'windata'
    f = open('windata', 'w+b')
    stdscr.putwin(f)
    f.close()
    
    # now create a subwindow (which over-writes some or all
    # of stdscr), and do whatever needs to be done...
    subWindowRoutine()
    
    # resurrect stdscr be reading 'windata'
    f = open('windata', 'r')
    stdscr = curses.getwin(f)
    f.close()
    
    stdscr.refresh()

That works as I expect.  However, I'd like to use the tempfile
module, rather than manage my own window data cache (this data needs
to exist only for the duration of the application).  However, if I
try to use the tempfile module, ala:

    addStuffToStdScr()

    tmpfile = tempfile.TemporaryFile()
    stdscr.putwin(tmpfile)

    subWindowRoutine()

    stdscr = curses.getwin(tmpfile)
    stdscr.refresh()

Then an exception is thrown and I get the following message:

    stdscr.refresh()
    _curses.error: refresh() for a pad requires 6 arguments

Any thoughts as to what I'm doing wrong?  Or can tempfile simply not
be used in such a manner?  Is there a better (or more appropriate
way) to get a generic file buffer?  Or a better way to save screen
state in curses?

Thanks!
Matt

-- 
Matt Garman
email at: http://raw-sewage.net/index.php?file=email



More information about the Python-list mailing list