I can't see to get any y, x coordinates to work with curses. Here is
an example:
import curses
def my_program(scre en):
while True:
ch = screen.getch()
if ch == ord("q"):
break
if ch <= 255:
screen.addstr(3 0, 10, "*%s*" % chr(ch))
screen.refresh( )
curses.wrapper( my_program)
Here is the result:
Traceback (most recent call last):
File "2pythontest.py ", line 12, in ?
curses.wrapper( my_program)
File "/Library/Frameworks/Python.framewor k/Versions/2.4//lib/
python2.4/curses/wrapper.py", line 44, in wrapper
return func(stdscr, *args, **kwds)
File "2pythontest.py ", line 9, in my_program
screen.addstr(3 0, 10, "*%s*" % chr(ch))
_curses.error: addstr() returned ERR 5 6329
7stud <bb**********@y ahoo.comwrote:
>I can't see to get any y, x coordinates to work with curses. Here is an example:
import curses
def my_program(scre en):
while True:
ch = screen.getch()
if ch == ord("q"):
break
if ch <= 255:
screen.addstr(3 0, 10, "*%s*" % chr(ch))
screen.refresh( )
curses.wrapper (my_program)
Don't you want mvaddstr? (And remember that y comes first.)
--
Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Hi,
Thanks for the response.
On Sep 16, 8:41 pm, Tim Roberts <t...@probo.com wrote:
Don't you want mvaddstr?
import curses
def my_program(scre en):
while True:
ch = screen.getch()
if ch == ord("q"):
break
if ch <= 255:
screen.mvaddstr (30, 10, "*%s*" % chr(ch))
screen.refresh( )
curses.wrapper( my_program)
Traceback (most recent call last):
File "2pythontest.py ", line 13, in ?
curses.wrapper( my_program)
File "/Library/Frameworks/Python.framewor k/Versions/2.4//lib/
python2.4/curses/wrapper.py", line 44, in wrapper
return func(stdscr, *args, **kwds)
File "2pythontest.py ", line 10, in my_program
screen.mvaddstr (5, 5, "*%s*" % chr(ch))
AttributeError: mvaddstr
> (And remember that y comes first.)
--
>>I can't seem to get any y, x coordinates to work with curses.
However, while changing things around, I discovered what is causing
the error: the coordinate 30, 10 is off my screen. When I change the
y, x coordinates to 5, 10, then the program executes as it should.
However, now I am having a problem trying to set the color of the text
that is output:
import curses
def my_program(scre en):
while True:
ch = screen.getch()
if ch == ord("q"):
break
if ch <= 255:
output = "*%s*" % chr(ch)
screen.addstr(5 , 5, output, curses.COLOR_RE D)
screen.refresh( )
curses.wrapper( my_program)
A strange thing is happening. The integer value of the constant
curses.COLOR_RE D is 1, and when I type in a character, 1 is getting
added to the character's ascii code. For instance, if I type in an
'h', then an 'i' displays on the screen--and in white, not red.
I did some testing and has_colors() returns True, but I still can't
get the curses output to show up in red. The tutorial:
Curses Programming with Python
A.M. Kuchling, Eric S. Raymond
says:
To use color, you must call the start_color() function soon after
calling initscr(), to initialize the default color set (the
curses.wrapper. wrapper() function does this automatically). Once
that's done, the has_colors() function returns TRUE if the terminal in
use can actually display color.
Another thing that is strange: that paragraph uses the syntax
curses.wrapper. wrapper(). And the docs say this:
--------
6.17 curses.wrapper -- Terminal handler for curses programs
New in version 1.6.
This module supplies one function, wrapper()...
--------
which implies that I should be using the syntax
curses.wrapper. wrapper() in my code. But I get an error when I try
it:
Traceback (most recent call last):
File "2pythontest.py ", line 16, in ?
curses.wrapper. wrapper(my_prog ram)
AttributeError: 'function' object has no attribute 'wrapper'
I get the same error if add the import statement:
import curses.wrapper
I'm using an intel mac if that makes any difference.
On Sep 17, 7:21 am, 7stud <bbxx789_0...@y ahoo.comwrote:
Hi,
Thanks for the response.
On Sep 16, 8:41 pm, Tim Roberts <t...@probo.com wrote:
Don't you want mvaddstr?
import curses
def my_program(scre en):
while True:
ch = screen.getch()
if ch == ord("q"):
break
if ch <= 255:
screen.mvaddstr (30, 10, "*%s*" % chr(ch))
screen.refresh( )
curses.wrapper( my_program)
Traceback (most recent call last):
File "2pythontest.py ", line 13, in ?
curses.wrapper( my_program)
File "/Library/Frameworks/Python.framewor k/Versions/2.4//lib/
python2.4/curses/wrapper.py", line 44, in wrapper
return func(stdscr, *args, **kwds)
File "2pythontest.py ", line 10, in my_program
screen.mvaddstr (5, 5, "*%s*" % chr(ch))
AttributeError: mvaddstr
(And remember that y comes first.)
--
>I can't seem to get any y, x coordinates to work with curses.
However, while changing things around, I discovered what is causing
the error: the coordinate 30, 10 is off my screen. When I change the
y, x coordinates to 5, 10, then the program executes as it should.
However, now I am having a problem trying to set the color of the text
that is output:
import curses
def my_program(scre en):
while True:
ch = screen.getch()
if ch == ord("q"):
break
if ch <= 255:
output = "*%s*" % chr(ch)
screen.addstr(5 , 5, output, curses.COLOR_RE D)
screen.refresh( )
curses.wrapper( my_program)
A strange thing is happening. The integer value of the constant
curses.COLOR_RE D is 1, and when I type in a character, 1 is getting
added to the character's ascii code. For instance, if I type in an
'h', then an 'i' displays on the screen--and in white, not red.
I did some testing and has_colors() returns True, but I still can't
get the curses output to show up in red. The tutorial:
Curses Programming with Python
A.M. Kuchling, Eric S. Raymond
says:
To use color, you must call the start_color() function soon after
calling initscr(), to initialize the default color set (the
curses.wrapper. wrapper() function does this automatically). Once
that's done, the has_colors() function returns TRUE if the terminal in
use can actually display color.
Another thing that is strange: that paragraph uses the syntax
curses.wrapper. wrapper(). And the docs say this:
--------
6.17 curses.wrapper -- Terminal handler for curses programs
New in version 1.6.
This module supplies one function, wrapper()...
--------
which implies that I should be using the syntax
curses.wrapper. wrapper() in my code. But I get an error when I try
it:
Traceback (most recent call last):
File "2pythontest.py ", line 16, in ?
curses.wrapper. wrapper(my_prog ram)
AttributeError: 'function' object has no attribute 'wrapper'
I get the same error if add the import statement:
import curses.wrapper
I'm using an intel mac if that makes any difference.
Ok. This works:
import curses
import curses.wrapper
def my_program(scre en):
curses.init_pai r(1, curses.COLOR_RE D, curses.COLOR_BL ACK)
while True:
ch = screen.getch()
if ch == ord("q"):
break
if ch <= 255:
output = "*%s*" % chr(ch)
screen.addstr(5 , 5, output, curses.color_pa ir(1))
screen.refresh( )
curses.wrapper( my_program)
On Sep 17, 9:50 am, 7stud <bbxx789_0...@y ahoo.comwrote:
Ok. This works:
import curses
import curses.wrapper
Oops. That second import statement isn't necessary.
7stud wrote:
However, now I am having a problem trying to set the color of the text
that is output:
import curses
def example(screen) :
if curses.has_colo rs():
curses.init_pai r(1, curses.COLOR_GR EEN, curses.COLOR_BL ACK)
curses.init_pai r(2, curses.COLOR_YE LLOW, curses.COLOR_BL ACK)
curses.init_pai r(3, curses.COLOR_RE D, curses.COLOR_BL ACK)
screen.addstr(1 , 1, 'Hello', curses.color_pa ir(1))
screen.addstr(1 , 7, 'World', curses.color_pa ir(2))
screen.addstr(1 , 12, '!!!', curses.color_pa ir(3) + curses.A_BOLD)
else:
screen.addstr(1 , 1, 'You don\'t have colors enabled. :(')
screen.addstr(3 , 0, '<Press any key to continue>')
screen.refresh( )
screen.getch()
if __name__ == '__main__':
curses.wrapper( example)
Ian This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: J Turner |
last post by:
Hello,
I'm playing with a python-based shell, which uses (guess what?) python as
it's scripting language, for iterative invocation, environment
variables, etc.
Everything was going well, until I moved beyond sys.readline() into
curses territory to flesh out the line-editing capabilities. Curses
always seems to get me.
|
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
|
by: Riccardo Galli |
last post by:
Hi,
I'm writing some widgets in curses.
Actually I'm trying to write a combobox. To do so, I need to create a pad
inside a panel, so that I can hide/show it.
I can't do it.
I can create a normal pad, but if I try to create it using "subpad" from a
window I get
_curses_panel.error: curses function returned NULL
|
by: Matthew Alton |
last post by:
The appended program freaks python 2.2 & 2.3 completely out. To
reproduce the wierdness: i) copy the source to a file called
consarn.py ii) $ python consarn.py; iii) the program is now doing a
getch(); iv) hit a key; v) the program locks up, the interptreter is
now munching on the CPU; vi) kill the interpreter from another shell;
vii) scratch head and wonder why neither of the mutually exclusive
clauses in the _io() member function...
|
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)
| |
by: schwerdy |
last post by:
Hi together,
can someone provide an example of a curses application that works in a
xterm that can be resized?
I could not find any working example yet...
Thanks in advance,
Sebastian 'Schwerdy' Schwerdhöfer
|
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>
|
by: Simon Morgan |
last post by:
Hi,
I'm having trouble with the following code. The problem is that the value
read by getch() when I hit the up or down keys doesn't match curses.KEY_UP
or curses.KEY_DOWN respectively. Other keys, such as 'z' in my example
code, work fine.
I only seem to have this problem when dealing with newly created windows
and not with the standard/default/root one created by curses.wrapper() and
passed to main().
|
by: Gasten |
last post by:
Hello.
The last weeks I've been coding a roguelike (you know, like nethack) in
python using the nCurses library. Some week ago I ran into a problem:
When I made the object for messagebar-output, I found a bug that I
can't figure out (believe me; I've tried everything and asked for help
several times on the IRC-channel).
The updateMsg() and iMsg() takes a list of message-lines as argument
(or process a string to a list), and it'll output...
|
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,...
|
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...
| |
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...
|
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...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| | |