Hi,
I have always found the list of wx.NamedCoulour's tricky.
1) It does not contain all the 16 std base colours (colours
components with 0, 128 and 255 values for RGB)
2) Some name are quite strange, the salmon colour has more to do
with the skin of the fish than with the meat.
Anyway. Some time ago, I wrote a small app, which displays all the
wx.NamedCoulour's. Here it is.
Jean-Michel Fauth, Switzerland.
# -*- coding: iso-8859-1 -*-
···
#--------------------------------------------------------------------
# Name: essaiwxNamedColour2.py
# Purpose: ....
# Author: Jean-Michel Fauth, Switzerland
# Copyright: (c) 2002-2004 Jean-Michel Fauth
# Licence: GPL
#--------------------------------------------------------------------
# os dev: w2k
# py dev: Python 2.4.1
# wx dev: wxPython 2.6.1
# Revision: 18 August 2005
#--------------------------------------------------------------------
import wx
#-------------------------------------------------------------------
#liste des couleurs de wx.NamedColour
AllColourNames = [
'AQUAMARINE',
'BLACK',
'BLUE',
'BLUE VIOLET',
'BROWN',
'CADET BLUE',
'CORAL',
'CORNFLOWER BLUE',
'CYAN',
'DARK GREY',
'DARK GREEN',
'DARK OLIVE GREEN',
'DARK ORCHID',
'DARK SLATE BLUE',
'DARK SLATE GREY',
'DARK TURQUOISE',
'DIM GREY',
'FIREBRICK',
'FOREST GREEN',
'GOLD',
'GOLDENROD',
'GREY',
'GREEN',
'GREEN YELLOW',
'INDIAN RED',
'KHAKI',
'LIGHT BLUE',
'LIGHT GREY',
'LIGHT STEEL BLUE',
'LIME GREEN',
'MAGENTA',
'MAROON',
'MEDIUM AQUAMARINE',
'MEDIUM BLUE',
'MEDIUM FOREST GREEN',
'MEDIUM GOLDENROD',
'MEDIUM ORCHID',
'MEDIUM SEA GREEN',
'MEDIUM SLATE BLUE',
'MEDIUM SPRING GREEN',
'MEDIUM TURQUOISE',
'MEDIUM VIOLET RED',
'MIDNIGHT BLUE',
'NAVY',
'ORANGE',
'ORANGE RED',
'ORCHID',
'PALE GREEN',
'PINK',
'PLUM',
'PURPLE',
'RED',
'SALMON',
'SEA GREEN',
'SIENNA',
'SKY BLUE',
'SLATE BLUE',
'SPRING GREEN',
'STEEL BLUE',
'TAN',
'THISTLE',
'TURQUOISE',
'VIOLET',
'VIOLET RED',
'WHEAT',
'WHITE',
'YELLOW',
'YELLOW GREEN'
]
#-------------------------------------------------------------------
def xorColour(wxcol):
r, g, b = wxcol.Red(), wxcol.Green(), wxcol.Blue()
xor_r, xor_g, xor_b = r ^ 255, g ^ 255, g ^ 255
if (abs(r - xor_r) == 1) and (abs(g - xor_g) == 1) and (abs(b - xor_b) == 1):
xor_r, xor_g, xor_b = 255, 255, 255
return wx.Colour(red=xor_r, green=xor_g, blue=xor_b)
#-------------------------------------------------------------------
class MyWin(wx.Window):
def __init__(self, parent, id, pos, size, style):
wx.Window.__init__(self, parent, id, pos, size, style)
self.SetBackgroundColour(wx.NamedColour('WHITE'))
self.Bind(wx.EVT_PAINT, self.OnPaint)
def OnPaint(self, event):
dc = wx.PaintDC(self)
dc.BeginDrawing()
#--------------
dc.SetBrush(wx.Brush(wx.WHITE, wx.SOLID))
dc.SetPen(wx.Pen(wx.BLACK, 1, wx.SOLID))
dc.SetFont(wx.Font(9, wx.DEFAULT, wx.NORMAL, wx.NORMAL, False, 'Arial'))
#~ dc.SetTextForeground(wx.WHITE)
dcwi, dche = dc.GetSize()
nrow, ncol = 10, 7
dx, dy = float(dcwi) / ncol, float(dche) / nrow
for r in range(nrow):
for c in range(ncol):
x1, y1 = c * dx, r * dy
x2, y2 = (c + 1) * dx, (r + 1) * dy
x1, y1, x2, y2 = int(x1), int(y1), int(x2), int(y2)
n = (r * ncol) + c
if n < len(AllColourNames):
colname = AllColourNames[n]
wxcol = wx.NamedColour(colname)
dc.SetBrush(wx.Brush(wxcol, wx.SOLID))
dc.SetPen(wx.Pen(wxcol, 1, wx.SOLID))
dc.DrawRectangle(x1, y1, x2 - x1, y2 - y1)
twi, the = dc.GetTextExtent(colname)
xm, ym = x1 + (x2 - x1) / 2, y1 + (y2 - y1) / 2
wxxorcol = xorColour(wxcol)
dc.SetTextForeground(wxxorcol)
dc.DrawText(colname, xm - twi / 2, ym - the / 2)
#~ print n
#--------------
dc.EndDrawing()
#-------------------------------------------------------------------
class MyPanel(wx.Panel):
def __init__(self, parent, id):
wx.Panel.__init__(self, parent, id, wx.DefaultPosition, wx.DefaultSize)
cwi, che = parent.GetClientSize()
gap = 0
self.win = MyWin(self, -1, (gap, gap), (cwi - 2 * gap, che - 2 * gap), style=wx.NO_BORDER)
#-------------------------------------------------------------------
class MyFrame(wx.Frame):
def __init__(self, parent, id):
sty = wx.SYSTEM_MENU | wx.CAPTION | wx.MINIMIZE_BOX | wx.CLOSE_BOX
s = __file__
wx.Frame.__init__(self, parent, id, s, (0, 0), (1024, 700), style=sty)
#~ wx.Frame.__init__(self, parent, id, s, (0, 0), (800, 600), style=sty)
self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
self.panel = MyPanel(self, -1)
def OnCloseWindow(self, event):
self.Destroy()
#-------------------------------------------------------------------
class MyApp(wx.App):
def OnInit(self):
frame = MyFrame(None, -1)
frame.Show(True)
self.SetTopWindow(frame)
return True
#-------------------------------------------------------------------
def ClearRedColour(wxcol):
return wx.Colour(red=0, green=wxcol.Green(), blue=wxcol.Blue())
def main():
app = MyApp(0)
app.MainLoop()
#-------------------------------------------------------------------
if __name__ == '__main__' :
main()
#-------------------------------------------------------------------
#~ ColourDatabaseDict = {
#~ AQUAMARINE (112, 219, 147)
#~ BLACK (0, 0, 0)
#~ BLUE (0, 0, 255)
#~ BLUE VIOLET (159, 95, 159)
#~ BROWN (165, 42, 42)
#~ CADET BLUE (95, 159, 159)
#~ CORAL (255, 127, 0)
#~ CORNFLOWER BLUE (66, 66, 111)
#~ CYAN DARK GREY (66, 66, 111)
#~ DARK GREEN (47, 79, 47)
#~ DARK OLIVE GREEN (79, 79, 47)
#~ DARK ORCHID (153, 50, 204)
#~ DARK SLATE BLUE (107, 35, 142)
#~ DARK SLATE GREY (47, 79, 79)
#~ DARK TURQUOISE (112, 147, 219)
#~ DIM GREY (84, 84, 84)
#~ FIREBRICK (142, 35, 35)
#~ FOREST GREEN (35, 142, 35)
#~ GOLD (204, 127, 50)
#~ GOLDENROD (219, 219, 112)
#~ GREY (128, 128, 128)
#~ GREEN (0, 255, 0)
#~ GREEN YELLOW (147, 219, 112)
#~ INDIAN RED (79, 47, 47)
#~ KHAKI (159, 159, 95)
#~ LIGHT BLUE (191, 216, 216)
#~ LIGHT GREY (192, 192, 192)
#~ LIGHT STEEL BLUE (143, 143, 188)
#~ LIME GREEN (50, 204, 50)
#~ MAGENTA (255, 0, 255)
#~ MAROON (142, 35, 107)
#~ MEDIUM AQUAMARINE (50, 204, 153)
#~ MEDIUM BLUE (50, 50, 204)
#~ MEDIUM FOREST GREEN (107, 142, 35)
#~ MEDIUM GOLDENROD (234, 234, 173)
#~ MEDIUM ORCHID (147, 112, 219)
#~ MEDIUM SEA GREEN (66, 111, 66)
#~ MEDIUM SLATE BLUE (127, 0, 255)
#~ MEDIUM SPRING GREEN (127, 255, 0)
#~ MEDIUM TURQUOISE (112, 219, 219)
#~ MEDIUM VIOLET RED (219, 112, 147)
#~ MIDNIGHT BLUE (47, 47, 79)
#~ NAVY (35, 35, 142)
#~ ORANGE (204, 50, 50)
#~ ORANGE RED (255, 0, 127)
#~ ORCHID (219, 112, 219)
#~ PALE GREEN (143, 188, 143)
#~ PINK (188, 143, 234)
#~ PLUM (234, 173, 234)
#~ PURPLE (176, 0, 255)
#~ RED (255, 0, 0)
#~ SALMON (111, 66, 66)
#~ SEA GREEN (111, 66, 66)
#~ SIENNA (142, 107, 35)
#~ SKY BLUE (50, 153, 204)
#~ SLATE BLUE (0, 127, 255)
#~ SPRING GREEN (0, 255, 127)
#~ STEEL BLUE (35, 107, 142)
#~ TAN (219, 147, 112)
#~ THISTLE (216, 191, 216)
#~ TURQUOISE (173, 234, 234)
#~ VIOLET (79, 47, 79)
#~ VIOLET RED (204, 50, 153)
#~ WHEAT (216, 216, 191)
#~ WHITE (255, 255, 255)
#~ YELLOW (255, 255, 0)
#~ YELLOW GREEN (153, 204, 50)
#eof-------------------------------------------------------------------