473,769 Members | 1,637 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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


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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4373
by: Edmond Ho | last post by:
Hi, I'm having trouble with a small curses program. I'm associate a pad with a panel. As I understand, a pad is supposed to be just a window with an arbitrary size. That seems to imply that a pad can be treated like a normal window when working with panels. I have this code: #!/usr/bin/env python import curses import curses.panel
2
4091
by: marco | last post by:
Hello, I having a problem creating directories with Python 2.3.4 (compiled with gcc 3.2.2, under Linux 2.4.20-31.9). I'm writing a plugin which works in the following way: GUI -- talks to --> Perl backend Perl backend -- talks to --> Python plugin Python plugin -- talks to --> Python script
0
1876
by: Matt Garman | last post by:
I'd like to write a class or module in python that allows me to do on-the-fly color changing in the curses module. I'm thinking about something along the lines of this: addstr(y, x, 'hello', brightyellow, blue) The module would automatically interpret the above as curses.init_pair(i, curses.COLOR_YELLOW, curses.COLOR_BLUE)
3
2821
by: Matt Garman | last post by:
I'm working on a curses-based application in Python. I've implemented what I call a "Chooser" (a fancy name for a menu): ---> 1. Choice 1 <--- 2. Choice 2 3. Choice 3 So the user can use the arrow keys to change choices. When he hits enter, the screen is re-drawn with a new interface. When that interface is quit, the screen should return to the Chooser, exactly
1
3696
by: Jerry Fleming | last post by:
Hi, I have wrote a game with python curses. The problem is that I want to confirm before quitting, while my implementation doesn't seem to work. Anyone can help me? #!/usr/bin/python # # Brick & Ball in Python # by Jerry Fleming <jerryfleming@etang.com>
6
1391
by: James T. Dennis | last post by:
Tonight I discovered something odd in the __doc__ for tempfile as shipped with Python 2.4.4 and 2.5: it says: This module also provides some data items to the user: TMP_MAX - maximum number of names that will be tried before giving up. template - the default prefix for all temporary names. You may change this to control the default prefix.
9
3755
by: billiejoex | last post by:
Hi there. I'm trying to generate a brand new file with a unique name by using tempfile.mkstemp(). In conjunction I used os.fdopen() to get a wrapper around file properties (write & read methods, and so on...) but 'name' attribute does not contain the correct file name. Why? <fdopen> Moreover, I'd like to know if I'm doing fine. Does this approach avoid
5
6330
by: 7stud | last post by:
I can't see to get any y, x coordinates to work with curses. Here is an example: import curses def my_program(screen): while True: ch = screen.getch() if ch == ord("q"): break
7
578
by: byte8bits | last post by:
Wondering if someone would help me to better understand tempfile. I attempt to create a tempfile, write to it, read it, but it is not behaving as I expect. Any tips? <open file '<fdopen>', mode 'w+b' at 0xab364968> 0 0 0
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10211
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9994
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9863
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8870
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7408
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6673
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3561
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.