wx.ColourDatabase

The documentation for the above wx.ColourDatabase — wxPython Phoenix 4.2.0 documentation

states " There is one predefined, global instance of this class called wx.TheColourDatabase"

Is this still true; I cannot get a reference to it

It seems you need to create a wx.App object to be able to get a reference:

>>> import wx
>>> wx.TheColourDatabase
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'wx' has no attribute 'TheColourDatabase'
>>> 
>>> app=wx.App()
>>> wx.TheColourDatabase
<wx._core.ColourDatabase object at 0x7f9a48e11f30>
>>> 

Calling wx.TheColourDatabase.Find() for some colours can give different results to just passing the colour name to wx.Colour().

e.g.


import wx
import wx.lib.colourdb as cdb

app = wx.App()
col_db = wx.TheColourDatabase

name = "SEA GREEN"

colour = col_db.Find(name)
print(colour, colour.IsOk())

colour2 = wx.Colour(name)
print(colour2, colour2.IsOk())

# cdb.updateColourDB()
# colourList = cdb.getColourList()
# print(colourList)

This outputs:

(35, 142, 107, 255) True
(46, 139, 87, 255) True

The differences were discussed in the following (closed) bug report:

EDIT: If you update TheColourDatabase from wx.lib.colourdb, then it gives the same results:

import wx
import wx.lib.colourdb as cdb

app = wx.App()
col_db = wx.TheColourDatabase

name = "SEA GREEN"

colour = col_db.Find(name)
print(colour, colour.IsOk())

colour2 = wx.Colour(name)
print(colour2, colour2.IsOk())

# Update TheColourDatabase from wx.lib.colourdb
cdb.updateColourDB()
# colourList = cdb.getColourList()
# print(colourList)

colour3 = col_db.Find(name)
print(colour3, colour3.IsOk())

This outputs:

(35, 142, 107, 255) True
(46, 139, 87, 255) True
(46, 139, 87, 255) True

in order not to ruin the feeling of the underlying OS it may be more advisable to use only the system colours like wx.SystemSettings.GetColour(wx.SYS_COLOUR_LISTBOX) :wink:

Yahoo, I like all these answers; Thank you very much

If you grind through the colour database, you can get a definitive list of defined colours on your machine.
Which can then be checked using Find(colour_name)

import wx
app=wx.App()
print(wx.version())
found_colour_names = []
print("\n"+ f"{'Colour name':<25} {'Red':<6} {'Green':<6} {'Blue'}" + "\n")
cols = wx.ColourDatabase()

for r in range(256):
    for g in range(256):
        for b in range(256):
            c = wx.Colour(r,g,b)
            x = cols.FindName(c)
            if x:
                print(f"{x:<25} {c.red:<6} {c.green:<6} {c.blue}")
                found_colour_names.append(x)
print("\nAlphabetical list\n")
for colour_name in sorted(found_colour_names):
    colour = cols.Find(colour_name)
    print(f"{colour_name:<25} {colour.red:<6} {colour.green:<6} {colour.blue:<6} {colour.IsOk()}")

On my box this gives me:

4.2.0 gtk3 (phoenix) wxWidgets 3.2.0

Colour name               Red    Green  Blue

BLACK                     0      0      0
BLUE                      0      0      255
SLATE BLUE                0      127    255
GREEN                     0      255    0
SPRING GREEN              0      255    127
CYAN                      0      255    255
NAVY                      35     35     142
STEEL BLUE                35     107    142
FOREST GREEN              35     142    35
SEA GREEN                 35     142    107
DARK GREY                 47     47     47
MIDNIGHT BLUE             47     47     79
DARK GREEN                47     79     47
DARK SLATE GREY           47     79     79
MEDIUM BLUE               50     50     204
SKY BLUE                  50     153    204
LIME GREEN                50     204    50
MEDIUM AQUAMARINE         50     204    153
CORNFLOWER BLUE           66     66     111
MEDIUM SEA GREEN          66     111    66
INDIAN RED                79     47     47
VIOLET                    79     47     79
DARK OLIVE GREEN          79     79     47
DIM GREY                  84     84     84
CADET BLUE                95     159    159
MEDIUM GREY               100    100    100
DARK SLATE BLUE           107    35     142
MEDIUM FOREST GREEN       107    142    35
SALMON                    111    66     66
DARK TURQUOISE            112    147    219
AQUAMARINE                112    219    147
MEDIUM TURQUOISE          112    219    219
MEDIUM SLATE BLUE         127    0      255
MEDIUM SPRING GREEN       127    255    0
GREY                      128    128    128
FIREBRICK                 142    35     35
MAROON                    142    35     107
SIENNA                    142    107    35
LIGHT STEEL BLUE          143    143    188
PALE GREEN                143    188    143
MEDIUM ORCHID             147    112    219
GREEN YELLOW              147    219    112
DARK ORCHID               153    50     204
YELLOW GREEN              153    204    50
BLUE VIOLET               159    95     159
KHAKI                     159    159    95
BROWN                     165    42     42
TURQUOISE                 173    234    234
PURPLE                    176    0      255
LIGHT BLUE                191    216    216
LIGHT GREY                192    192    192
ORANGE                    204    50     50
VIOLET RED                204    50     153
GOLD                      204    127    50
THISTLE                   216    191    216
WHEAT                     216    216    191
MEDIUM VIOLET RED         219    112    147
ORCHID                    219    112    219
TAN                       219    147    112
GOLDENROD                 219    219    112
PLUM                      234    173    234
MEDIUM GOLDENROD          234    234    173
RED                       255    0      0
ORANGE RED                255    0      127
MAGENTA                   255    0      255
LIGHT MAGENTA             255    119    255
CORAL                     255    127    0
PINK                      255    192    203
YELLOW                    255    255    0
WHITE                     255    255    255

Alphabetical list

AQUAMARINE                112    219    147    True
BLACK                     0      0      0      True
BLUE                      0      0      255    True
BLUE VIOLET               159    95     159    True
BROWN                     165    42     42     True
CADET BLUE                95     159    159    True
CORAL                     255    127    0      True
CORNFLOWER BLUE           66     66     111    True
CYAN                      0      255    255    True
DARK GREEN                47     79     47     True
DARK GREY                 47     47     47     True
DARK OLIVE GREEN          79     79     47     True
DARK ORCHID               153    50     204    True
DARK SLATE BLUE           107    35     142    True
DARK SLATE GREY           47     79     79     True
DARK TURQUOISE            112    147    219    True
DIM GREY                  84     84     84     True
FIREBRICK                 142    35     35     True
FOREST GREEN              35     142    35     True
GOLD                      204    127    50     True
GOLDENROD                 219    219    112    True
GREEN                     0      255    0      True
GREEN YELLOW              147    219    112    True
GREY                      128    128    128    True
INDIAN RED                79     47     47     True
KHAKI                     159    159    95     True
LIGHT BLUE                191    216    216    True
LIGHT GREY                192    192    192    True
LIGHT MAGENTA             255    119    255    True
LIGHT STEEL BLUE          143    143    188    True
LIME GREEN                50     204    50     True
MAGENTA                   255    0      255    True
MAROON                    142    35     107    True
MEDIUM AQUAMARINE         50     204    153    True
MEDIUM BLUE               50     50     204    True
MEDIUM FOREST GREEN       107    142    35     True
MEDIUM GOLDENROD          234    234    173    True
MEDIUM GREY               100    100    100    True
MEDIUM ORCHID             147    112    219    True
MEDIUM SEA GREEN          66     111    66     True
MEDIUM SLATE BLUE         127    0      255    True
MEDIUM SPRING GREEN       127    255    0      True
MEDIUM TURQUOISE          112    219    219    True
MEDIUM VIOLET RED         219    112    147    True
MIDNIGHT BLUE             47     47     79     True
NAVY                      35     35     142    True
ORANGE                    204    50     50     True
ORANGE RED                255    0      127    True
ORCHID                    219    112    219    True
PALE GREEN                143    188    143    True
PINK                      255    192    203    True
PLUM                      234    173    234    True
PURPLE                    176    0      255    True
RED                       255    0      0      True
SALMON                    111    66     66     True
SEA GREEN                 35     142    107    True
SIENNA                    142    107    35     True
SKY BLUE                  50     153    204    True
SLATE BLUE                0      127    255    True
SPRING GREEN              0      255    127    True
STEEL BLUE                35     107    142    True
TAN                       219    147    112    True
THISTLE                   216    191    216    True
TURQUOISE                 173    234    234    True
VIOLET                    79     47     79     True
VIOLET RED                204    50     153    True
WHEAT                     216    216    191    True
WHITE                     255    255    255    True
YELLOW                    255    255    0      True
YELLOW GREEN              153    204    50     True

from a button man I’d expected some alpha shades: what’s a button with no gloss? :hugs:

You rapscallion, you! :upside_down_face:

@rolfofsaxony der Georg ist tatsächlich einer RAP-scallion :wave:

@Thom Ja-Ja-Ja! :wink:

@Thom thanks for the age (charming), rocking I’ll try to keep up but otherwise more classic if pos :star_struck: (my real objective was this transition of the Gui since Google & the internet moved the focus to a much more simplistic and content driven one)

Yw and … de-nada. Point taken. Thom out🔌