473,548 Members | 2,704 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

curses and use_default_col ors()

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_col ors() 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 4410
Brian Victor <bh**@psu.edu > wrote in message news:<sl******* **********@pa-steclge-u3-c3b-133.stcgpa.adel phia.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.startWi n() contains
these lines (inter alia) ...

# ... blah, blah, blah.
curses.start_co lor()
curses.init_pai r(1, curses.COLOR_WH ITE, curses.COLOR_BL UE)
# ... blah, blah, blah ...
self.scrn = self.stdscr.sub win(self.height , self.width, 0, 0)
self.scrn.bkgd( curses.color_pa ir(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.adel phia.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.startWi n() 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_c olors(PyObject *self, PyObject *args)
{
use_default_col ors();
Py_INCREF(Py_No ne);
return Py_None;
}

static PyMethodDef SpamMethods[] = {
{"use_default_c olors", pyuse_default_c olors, 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('used efault',
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_c olors(PyObject *self, PyObject *args)
{
use_default_col ors();
Py_INCREF(Py_No ne);
return Py_None;
}

static PyMethodDef SpamMethods[] = {
{"use_default_c olors", pyuse_default_c olors, 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_col ors() 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_c olors(); 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('used efault',
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_col ors has no significant effect. That is,
a black background is indistinguishab le 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
4351
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
1
3283
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
0
1762
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)...
0
1856
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)
4
4112
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
1
3681
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>
3
4848
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...
7
2826
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...
5
6316
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
7518
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7444
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...
0
7711
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. ...
0
7954
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7805
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...
0
6039
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...
1
5367
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...
0
3497
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3478
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.