[wxPython] colourdb and wxTheColourDatabase

wxTheColourDatabase class in wxWindows has two methods for converting
between RGB values and named colors.

  FindColour
  FindName

Both return NULL if a match isn't found. These look like the methods I need,
but they don't appear to be exposed by wxPython. The colourdb.py file does
have getColourInfoList() which could be used to do some equivelant functions
for FindColour and FindName. The search is made more complex though, because
the r, g, b values are not stored as a tuple. Perhaps a lambda or list
comprehension or something could be used to make a sensible search,
otherwise it might be nice to have the list stored as a nested list:
  ("SNOW", (255, 250, 250)),
or dictionary
  "SNOW":(255, 250, 250),

That might break some existing programs (yes?), so I lean towards adding
utility functions to colourdb.py to provide the equivelant of FindColour and
FindName, which also avoids the need for a program to create their own copy
of the colour list.

There is also wxNamedColour

wx.wxNamedColour('dark magenta')

which appears to work, except that if you pass it a non-existant named color
you get back (0, 0, 0) rather than None.

wx.wxNamedColour('bad color')

(0, 0, 0)

Other suggestions?

ka

BTW, part of the reason I want these methods is that I'm thinking of adding
a NamedColorDialog to PythonCard. I think this would be generally useful at
the wxWindows/wxPython level since only the Mac has a named color picker as
part of the OS and I'm not sure that the Mac one matches web named colors
and of course it isn't cross-platform.

Robin, what do you think of a wxNamedColorDialog (wxNamedColourDialog)?

ka

···

-----Original Message-----
From: wxpython-users-admin@lists.wxwindows.org
[mailto:wxpython-users-admin@lists.wxwindows.org]On Behalf Of Kevin
Altis
Sent: Saturday, January 05, 2002 12:12 PM
To: Wxpython-Users
Subject: [wxPython] colourdb and wxTheColourDatabase

wxTheColourDatabase class in wxWindows has two methods for converting
between RGB values and named colors.

  FindColour
  FindName

Both return NULL if a match isn't found. These look like the
methods I need,
but they don't appear to be exposed by wxPython. The colourdb.py file does
have getColourInfoList() which could be used to do some
equivelant functions
for FindColour and FindName. The search is made more complex
though, because
the r, g, b values are not stored as a tuple. Perhaps a lambda or list
comprehension or something could be used to make a sensible search,
otherwise it might be nice to have the list stored as a nested list:
  ("SNOW", (255, 250, 250)),
or dictionary
  "SNOW":(255, 250, 250),

That might break some existing programs (yes?), so I lean towards adding
utility functions to colourdb.py to provide the equivelant of
FindColour and
FindName, which also avoids the need for a program to create
their own copy
of the colour list.

There is also wxNamedColour

wx.wxNamedColour('dark magenta')

which appears to work, except that if you pass it a non-existant
named color
you get back (0, 0, 0) rather than None.

>>> wx.wxNamedColour('bad color')
(0, 0, 0)

Other suggestions?

ka

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwindows.org
http://lists.wxwindows.org/mailman/listinfo/wxpython-users

wxTheColourDatabase class in wxWindows has two methods for converting
between RGB values and named colors.

  FindColour
  FindName

Both return NULL if a match isn't found. These look like the methods I

need,

but they don't appear to be exposed by wxPython.

They are, see wxPython/src/gdi.i.

from wxPython.wx import *
cdb = wxTheColourDatabase
c = cdb.FindColour("Light blue")
c.__class__

<class wxPython.gdi.wxColourPtr at 008AF804>

c

(191, 216, 216)

cdb.FindName(c)

'LIGHT BLUE'

cdb.FindName(wxRED)

'RED'

c2 = cdb.FindColour("bogus blue")
repr(c2)

'None'

The colourdb.py file does
have getColourInfoList() which could be used to do some equivelant

functions

for FindColour and FindName. The search is made more complex though,

because

the r, g, b values are not stored as a tuple. Perhaps a lambda or list
comprehension or something could be used to make a sensible search,
otherwise it might be nice to have the list stored as a nested list:
  ("SNOW", (255, 250, 250)),
or dictionary
  "SNOW":(255, 250, 250),

They are the way they are so they can be used as an arg tuple for
wxTheColourDatabase.Append in updateColourDB.

That might break some existing programs (yes?), so I lean towards adding
utility functions to colourdb.py to provide the equivelant of FindColour

and

FindName, which also avoids the need for a program to create their own

copy

of the colour list.

There is also wxNamedColour

wx.wxNamedColour('dark magenta')

which appears to work, except that if you pass it a non-existant named

color

you get back (0, 0, 0) rather than None.

What you get is a wxColour object, wxNamedColour is a constructor for
wxColour. (wxColour has a __str__ method that converts to a tuple of
(GetRed(), GetGreen(), GetBlue()).)

>>> wx.wxNamedColour('bad color')
(0, 0, 0)

Other suggestions?

c = wxNamedColour("skdfghdskfh")
c

(0, 0, 0)

c.Ok()

0

···

--
Robin Dunn
Software Craftsman
robin@AllDunn.com Java give you jitters?
http://wxPython.org Relax with wxPython!

BTW, part of the reason I want these methods is that I'm thinking of

adding

a NamedColorDialog to PythonCard. I think this would be generally useful

at

the wxWindows/wxPython level since only the Mac has a named color picker

as

part of the OS and I'm not sure that the Mac one matches web named colors
and of course it isn't cross-platform.

Robin, what do you think of a wxNamedColorDialog (wxNamedColourDialog)?

Sounds like a nice thing to have.

···

--
Robin Dunn
Software Craftsman
robin@AllDunn.com Java give you jitters?
http://wxPython.org Relax with wxPython!