473,387 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

curses and use_default_colors()

I am attempting to write a curses-based program. I would like to use
the default terminal background rather than a black one (a significant
difference with transluscent terminals, regardless of one's opinion of
them).

It appears that in the C ncurses interface, this is accomplished via
use_default_colors() and assume_default_colors(). However, these
functions don't seem to have parallels in the python binding. Is there
some way to accomplish what I want?

Thanks,

--
Brian
Jul 18 '05 #1
5 4390
Brian Victor <bh**@psu.edu> wrote in message news:<sl*****************@pa-steclge-u3-c3b-133.stcgpa.adelphia.net>...
I am attempting to write a curses-based program. I would like to use
the default terminal background rather than a black one (a significant
difference with transluscent terminals, regardless of one's opinion of
them).

<snip>

I don't know how much this'll help, but my home-brewed curses TextApp
class has a white-on-blue default, and TextApp.startWin() contains
these lines (inter alia) ...

# ... blah, blah, blah.
curses.start_color()
curses.init_pair(1, curses.COLOR_WHITE, curses.COLOR_BLUE)
# ... blah, blah, blah ...
self.scrn = self.stdscr.subwin(self.height, self.width, 0, 0)
self.scrn.bkgd(curses.color_pair(1))
# Blah, blah, blah ...

Fwiw

Chris
Jul 18 '05 #2
Chris Reay wrote:
Brian Victor <bh**@psu.edu> wrote in message
news:<sl*****************@pa-steclge-u3-c3b-133.stcgpa.adelphia.net>...
I am attempting to write a curses-based program. I would like to use
the default terminal background rather than a black one (a significant
difference with transluscent terminals, regardless of one's opinion of
them).

I don't know how much this'll help, but my home-brewed curses TextApp
class has a white-on-blue default, and TextApp.startWin() contains
these lines (inter alia) ...

[snip]

Thanks, but that's not quite what I'm looking for. Getting a solid
background isn't a problem. Getting a subtly textured background to
show through (or other windows on Mac) seems to be a bit tricker.

Still hoping someone will hop in with "just use this curses extension"
or "you can write a wrapper around that one function and integrate it
with python's curses like this." But thanks for the input, anyway!

--
Brian
Jul 18 '05 #3
Brian Victor wrote:
Still hoping someone will hop in with "just use this curses extension"
or "you can write a wrapper around that one function and integrate it
with python's curses like this." But thanks for the input, anyway!


I guess that someone is me. I love replying to my own posts...

I just hacked this bit of code up and it seems to do the trick.
importing usedefault and calling usedefault.use_default_colors() sets
color pair 0 to use the default colors for the terminal. This allows
translucency on terminals that support it. The packaging could use some
work, but the following should be enough to get future readers going.

This is the first C extension I've written, and it's almost straight
from the docs. If anyone has any pointers, I'd be happy to hear them.

usedefault.c
#v+
#include <Python.h>
#include <ncurses.h>

static PyObject *
pyuse_default_colors(PyObject *self, PyObject *args)
{
use_default_colors();
Py_INCREF(Py_None);
return Py_None;
}

static PyMethodDef SpamMethods[] = {
{"use_default_colors", pyuse_default_colors, METH_VARARGS,
"Use Default Colors."},
{NULL, NULL, 0, NULL} /* Sentinel */
};

/* PyMODINIT_FUNC */
/* The docs say to use the above, but it doesn't exist in my copy of
* Python.h. */
void initusedefault()
{
(void) Py_InitModule("usedefault", SpamMethods);
}
#v-

setup.py
#v+
from distutils.core import setup, Extension

module1 = Extension('usedefault',
libraries = ["ncurses"],
sources = ['usedefault.c'])

setup (name = 'usedefault',
version = '1.0',
description = 'Use default colors in curses',
ext_modules = [module1])
#v-

--
Brian
Jul 18 '05 #4
On Wed, 30 Jul 2003 17:34:29 GMT,
Brian Victor <bh**@psu.edu> wrote:
static PyObject *
pyuse_default_colors(PyObject *self, PyObject *args)
{
use_default_colors();
Py_INCREF(Py_None);
return Py_None;
}

static PyMethodDef SpamMethods[] = {
{"use_default_colors", pyuse_default_colors, METH_VARARGS,
"Use Default Colors."},
{NULL, NULL, 0, NULL} /* Sentinel */
Use METH_NOARGS instead of METH_VARARGS; as written, this code will accept
any number of arguments to the Python use_default_colors() method and not
raise any error. An alternative would be to leave METH_VARARGS and put "if
(!PyArg_NoArgs(args)) return NULL;" in pyuse_default_colors(); this would
work with older versions of Python at the cost of being slightly slower.

I'll add this function to the curses module, so at least it'll be in 2.4;
thanks for writing it. Anyone know if it's possible to test it on MacOS X?
Does the Terminal support transparency?

--amk
};

/* PyMODINIT_FUNC */
/* The docs say to use the above, but it doesn't exist in my copy of
* Python.h. */
void initusedefault()
{
(void) Py_InitModule("usedefault", SpamMethods);
}
#v-

setup.py
#v+
from distutils.core import setup, Extension

module1 = Extension('usedefault',
libraries = ["ncurses"],
sources = ['usedefault.c'])

setup (name = 'usedefault',
version = '1.0',
description = 'Use default colors in curses',
ext_modules = [module1])
#v-

Jul 18 '05 #5
Brian Victor wrote:
Interestingly, both Terminal and iTerm seem to make everything
transparent, so use_default_colors has no significant effect. That is,
a black background is indistinguishable from a transparent/default
background.


I forgot to mention that I hit a compile error on OSX's ncurses header
file. I believe it came from the December dev tools. It dealt with
redefining wchar_t:

#ifndef _WCHAR_T
typedef unsigned long wchar_t;
#endif /* _WCHAR_T */

I have no idea why the mac version does that (fink's does also). My
linux copy of the headers has nothing like that. #defining _WCHAR_T
before including ncurses.h fixed that, but I don't know if that's a
permanent solution. FWIW, I was doing this with python 2.3a1.

--
Brian
Jul 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
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...
1
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...
0
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...
0
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',...
4
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...
1
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 # #...
3
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...
7
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...
5
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
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.