Why do libraries use named colors ?

hello,

With a lot of struggling I got the named colors working,
but I doubt it's correct, because for every conversion I've to create a ColourDatabase object ?

          if colordlg.ShowModal() == wx.ID_OK:
              # get the new color and store it
              cdb = wx.ColourDatabase()
              JG.Scope_Signal_Color [S] = \
                  cdb.FindName ( colordlg.GetColourData().GetColour().Get())

And Now I've got it working,
it's not working very well,
a lot of colors can not be found,
so in general you don't get what you selected with the colordialog.

And now I wonder why some libraries (like plot) require named colors !!
Some arguments against:
- I can't imagine that named colors are faster than normal RGB tupples.
- Names can contain typos, while RGB colors always return a valid value.
- I (like a few other people) are not familiar with those fancy color names,
but we all know the numbers 0 to 255
- If a library want to support named colors, besides RGB tupples,
looks like peanuts to me.

So I can't think of any reason why to use named colors only as a library input,
what am I missing ?

cheers,
Stef Mientki

Stef Mientki wrote:

hello,

With a lot of struggling I got the named colors working,
but I doubt it's correct, because for every conversion I've to create a ColourDatabase object ?

No, there is a singleton called wx.TheColourDatabase that you can use if needed, but you really don't need to. There is an "alternate constructor" for the wx.Colour class that will use the color db for you:

  c = wx.NamedColour('blue')

Or through the magic of SWIG typemaps you can just use the string anywhere that a wx.Colour is expected by a C++ method:

  window.SetBackgroundColour('blue')

The typemap also allows for an html-like RGB hex string:

  window.SetForegroundColour('#ff0000')

or a 3-tuple of integers:

  pen = wx.Pen( (0, 255, 0), 1 )

and finally, you can of course always construct a wx.Colour using the integer RGB values:

  c = wx.Colour(128, 255, 64)

         if colordlg.ShowModal() == wx.ID_OK:
             # get the new color and store it
             cdb = wx.ColourDatabase()
             JG.Scope_Signal_Color [S] = \
                 cdb.FindName ( colordlg.GetColourData().GetColour().Get())

And Now I've got it working,
it's not working very well,
a lot of colors can not be found,
so in general you don't get what you selected with the colordialog.

Why do you need to store the name? Why not just use the color's RGB values?

And now I wonder why some libraries (like plot) require named colors !!
Some arguments against:
- I can't imagine that named colors are faster than normal RGB tupples.
- Names can contain typos, while RGB colors always return a valid value.
- I (like a few other people) are not familiar with those fancy color names,
but we all know the numbers 0 to 255
- If a library want to support named colors, besides RGB tupples,
looks like peanuts to me.

I know some of them have had this limitation, but plot doesn't. It uses code like this to allow you to either pass a color name or a wx.Colour object:

         colour = self.attributes['colour']
         ...
         if not isinstance(colour, wx.Colour):
             colour = wx.NamedColour(colour)
         pen = wx.Pen(colour, width, style)

···

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

Robin Dunn wrote:

And now I wonder why some libraries (like plot) require named colors !!

I know some of them have had this limitation, but plot doesn't.

and for the record, neither does FloatCanvas -- all the examples used color names, 'cause they make more sense to me, but the user can pass in any of the other forms that wx understands (rgb triples, etc)

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Christopher Barker wrote:

Robin Dunn wrote:

And now I wonder why some libraries (like plot) require named colors !!

I know some of them have had this limitation, but plot doesn't.

and for the record, neither does FloatCanvas -- all the examples used color names, 'cause they make more sense to me, but the user can pass in any of the other forms that wx understands (rgb triples, etc)

hi Chris,
I didn't forget FloatCanvas :wink:
I'm almost finished with the embedding of my 'Oscilloscope' module into my application,
I didn't make a choice yet of the display component, and used "pyplot" for the current tests.
I've to decide yet, if I leave pyplot in for the moment,
or that I'm making a new implementation
and will choose between pyplot / floatcanvas / Jean-Michels's scope / "my-own".
that deriving my own from the simplest of the above mentioned,
seems the best solution.
But if you see how much trouble I have with colors,
I'm not sure this is a good way to go :wink:

cheers,
Stef

···

From my desired specifications,

-Chris

Robin,

thanks for the great overview of the color aspects.

<snip>

         if colordlg.ShowModal() == wx.ID_OK:
             # get the new color and store it
             cdb = wx.ColourDatabase()
             JG.Scope_Signal_Color [S] = \
                 cdb.FindName ( colordlg.GetColourData().GetColour().Get())

And Now I've got it working,
it's not working very well,
a lot of colors can not be found,
so in general you don't get what you selected with the colordialog.

Why do you need to store the name? Why not just use the color's RGB values?

Well that was my question :wink:
But now you're asking, we're on the same level again :wink:

I know some of them have had this limitation, but plot doesn't. It uses code like this to allow you to either pass a color name or a wx.Colour object:

Aha, now I see it's my fault:
I used this "beautiful but completely unreadable" syntax:

  wx.colordlg.GetColourData().GetColour().Get()

which returns a tuple and not a color property,
I had to use the much better readable :wink:

  wx.colordlg.GetColourData().GetColour()

cheers,
Stef