By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,369 Members | 1,253 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,369 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.