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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Matt Garman

    #1

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

    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...
    addStuffToStdSc r()

    # 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...
    subWindowRoutin e()

    # 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:

    addStuffToStdSc r()

    tmpfile = tempfile.Tempor aryFile()
    stdscr.putwin(t mpfile)

    subWindowRoutin e()

    stdscr = curses.getwin(t mpfile)
    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
  • Matt Garman

    #2
    Re: tempfile and curses (putwin() and getwin())

    On Fri, 05 Nov 2004 19:50:34 GMT, Matt Garman <fake@not-real.bogus> wrote:[color=blue]
    > addStuffToStdSc r()
    >
    > tmpfile = tempfile.Tempor aryFile()
    > stdscr.putwin(t mpfile)
    >
    > subWindowRoutin e()
    >
    > stdscr = curses.getwin(t mpfile)
    > stdscr.refresh( )
    >
    > Then an exception is thrown and I get the following message:
    >
    > stdscr.refresh( )
    > _curses.error: refresh() for a pad requires 6 arguments[/color]

    I figured out that I need to add the following before calling
    getwin():

    tmpfile.seek(0)

    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

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

    Comment

    Working...