Curses set bright and dark backgrounds - python

For this, it might be useful to note that I'm running python on a Mac in xterm-color
I'm trying to build a chess game with curses in Python, but I can't figure out how to set the color pairs to use bright black or bright white (so I can have better contrast between board and pieces.) The terminal shows the bright colors as being the color + 8 (so the 8-15 range,) but if I try to use those, I get back init_pair() returned ERR (For example, in:)
curses.init_pair(1, 0, 15)
I also thought that using the A_BOLD and A_BLINK attributes might let me set bright colors in curses, but that doesn't appear to have any effect. For example:
pad.addstr(y, x, "qwert", curses.color_pair(1)|curses.A_BOLD)
What do I need to do to get these colors?
Edit:
It turns out that I had a wrong setting in the terminal ("Use bright colors for bold text" was unchecked,) but I still don't seem to have any way to set a bright background color.

I still don't seem to have any way to set a bright background color.
This question is old, but in case someone will look for answer to it, you just have to combine curses.A_BOLD with curses.A_REVERSE, for example:
curses.init_pair(1, curses.COLOR_GREEN, curses.color_BLACK);
// Pair with green as a foreground color and black as a background
curses.color_pair(1);
// Pair with light green as a background color and black as a foreground
curses.color_pair(1) | curses.A_BOLD | curses.REVERSE;
... and now you have 2 × more pairs :)

In this case, the issue is simply that I had "Use bright colors for bold text" unchecked (oops, I was messing with the settings for the wrong terminal style.) It is somewhat worrying that I might not be able to rely on users having these settings on Mac OS however.

Related

Set the background of python console to an rgb value?

I'm working on a little side project console-based python script. I'm using a module called rich to add colours but i was wondering if you could also set the background colour as well.
I know the color command exists but it's very limited.
Any help would be appreciated!
This will change the background to yellow on supported consoles:
print("\033]11;#ffff00\007")
The pattern is: "\033]11;#rrggbb\007", where rr, gg and bb are the red, green and blue values in hexadecimal ranging from 0x00 to 0xFF.

What is the simplest way to detect color in Python?

I'm trying to write a Python program that detects the color of a portion of the screen and puts it in a conditional. The easiest way, I would think, would be to detect the color underneath the cursor (which would work perfectly with my program), but I can't find many up-to-date resources on that. I would like to be able to have the RGB, HEX, or some other type of value in a variable. Some ways that would work for my program: detecting the color under the cursor, detecting the color of a certain pixel, or detecting the color of a portion of pixels. Thanks for your help!

How to change font colour and size of Python Shell

I am using Python 3 and I am not sure if this is a possible query because I've searching it up and I couldn't find a solution. My question is, I want to learn how to change colour and size of my output.
How to make the size bigger or smaller?
Able to make the font size big
How to change the background colour of shell?
Able to make the background colour, for example, right now, it's all white but I want it black.
How to change the output colour of shell?
I would love to see colourful fonts operating in black background shell
I hope there is a solution to this! Thanks in advance
I know about the color part, but I came for the size.
To start off with, to close the color, use \u001b[0m. If you don't use this, all text will become the color that you started with until you close it.
Green is\u001b[32m
Black is\u001b[30m
Pink is \u001b[35m
There are much more, but is you experiment with different numbers, you can highlight and do different colors.
To make a sentence with color, format it like this:
print("\u001b[35mHi, coders. This is pink output.\u001b[0m")
Test that code. it will come out in pink.

Python ANSI Colour codes transparent background

I was wondering if it was possible to set the background colour of text, using ANSI colour codes, to transparent, or just the colour of the terminal, so you can use colours without having to deal with the background colour not being the right colour.
You can do this by ending the escape code using 49m. For example, red text on a transparent background would be \033[1;31;49m.
Happy colouring!

Get the background color of a widget - really

I'm having trouble getting the actual background color of widgets.
In my special case I'm having trouble with widgets within a QTabWidget.
This is on Windows7.
So classic widgets have some greyish background, whereas widgets within a tab are generally drawn with a white background.
I tried:
def bgcolor(widget):
color = widget.palette().color(widget.backgroundRole()) # version 1
color = widget.palette().color(QtGui.QPalette.Background) # version 2
rgba = color.red(), color.green(), color.blue(), color.alpha()
return rgba
which is pretty much what I could figure out myself from the Qt documentation and what google and SO give.
But, this just doesn't work.
I'm testing widgets inside and outside of a TabWidget and the function above returns identical colors for obviously differently colored widgets.
Namely it always returns the greyish color, even for the plain white colored widgets within the tab.
Am I missing something here?
EDIT:
My problem is when using matplotlib, matplotlib draws figures with a "none" facecolor with the wrong background color when embedded in a QTabWidget: grey, even though the parent widget is white.
To fix this I wanted to get the background color of the widget and set it as background color for the figure.
Though this may be a matplotlib issue, I guessed this would be the quickest workaround.
As I noticed I couldn't get the proper color, I became insistent :)
The palette is returning the correct colours.
The mistake you're probably making is that you're assuming "background" always means the same thing for all widgets. Let's take an unmodified QListWidget as an example. On a desktop with a traditional light-coloured scheme, this will probably appear as a white viewport inside a 3D sunken panel. But if you query the "background" for this widget, you will see something like this:
>>> widget = QtGui.QListWidget()
>>> widget.palette().color(QtGui.QPalette.Background).name()
'#edecec'
which is obviously not white. So Background is the wrong color role to query for this widget. Instead, it looks like Base might be more appropriate:
>>> widget.palette().color(QtGui.QPalette.Base).name()
'#ffffff'
It's worth noting that the documentation for color roles states that Background and Foreground are obsolete values, with Window and WindowText being recommended instead. Perhaps this is because the former terms are now considered to be misleading.
UPDATE:
On platforms which use pixmap-based styling, some of the reported palette colours will not match the visual appearance of a widget. This issue specifically affects Windows and OSX, and so may explain why you are not able to get the apparent background colour of tabs. This issue is documented in a Qt FAQ, which also gives some possible solutions (although the QProxyStyle option is supported in PyQt5 but not PyQt4).

Categories