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

Discussion in 'Python' started by Matt Garman, Nov 5, 2004.

  1. Matt Garman

    Matt Garman Guest

    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...

    # save the state of stdscr to a file named 'windata'
    f = open('windata', 'w+b')

    # now create a subwindow (which over-writes some or all
    # of stdscr), and do whatever needs to be done...

    # resurrect stdscr be reading 'windata'
    f = open('windata', 'r')
    stdscr = curses.getwin(f)


    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:


    tmpfile = tempfile.TemporaryFile()


    stdscr = curses.getwin(tmpfile)

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

    _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?

    Matt Garman, Nov 5, 2004
    1. Advertisements

  2. Matt Garman

    Matt Garman Guest

    I figured out that I need to add the following before calling


    Which makes sense; that's why it worked when manually creating the
    temp file---I closed and re-opened that file between the calls to
    putwin() and getwin() (and open() automatically sets the file
    position to zero).

    One of those things that seem obvious in hindsite :)

    Matt Garman, Nov 10, 2004
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.