468,537 Members | 2,284 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,537 developers. It's quick & easy.

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...
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
Jul 18 '05 #1
1 2882
On Fri, 05 Nov 2004 19:50:34 GMT, Matt Garman <fa**@not-real.bogus> wrote:
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


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
Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Edmond Ho | last post: by
2 posts views Thread by marco | last post: by
reply views Thread by Matt Garman | last post: by
1 post views Thread by Jerry Fleming | last post: by
6 posts views Thread by James T. Dennis | last post: by
9 posts views Thread by billiejoex | last post: by
5 posts views Thread by 7stud | last post: by
7 posts views Thread by byte8bits | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.