Member Avatar for rbyrd

Is there some place where I can get a list of the "named" colors (i.e., goldenrod) available in wxpython? I'm using osx 10.6.8. Thank you.

Here you go:

''' wx_colourdb_show1.py
show the colours in wxPython's wx.lib.colourdb
the database has 630 named colors
use wx.lib.scrolledpanel.ScrolledPanel and wx.GridSizer
to show the colours and their names
Python 2.7.5
'''

import wx
import wx.lib.scrolledpanel
# note the goofy english spelling
import wx.lib.colourdb

class MyScrolledPanel(wx.lib.scrolledpanel.ScrolledPanel):
    def __init__(self, parent):
        # make the scrolled panel larger than its parent
        wx.lib.scrolledpanel.ScrolledPanel.__init__(self, parent, wx.ID_ANY,
            size=(600, 450), style=wx.TAB_TRAVERSAL|wx.SUNKEN_BORDER)
        # scroll bars won't appear until required
        # default is SetupScrolling(scroll_x=True, scroll_y=True)
        self.SetupScrolling()
        self.SetBackgroundColour("white")

        wx.lib.colourdb.updateColourDB()
        # create a list of all the colours in the colour data base
        #colours = wx.lib.colourdb.getColourList()
        colours = wx.lib.colourdb.getColourInfoList()

        # main sizer
        vsizer = wx.BoxSizer(wx.VERTICAL)

        # wx.GridSizer(rows, cols, vgap, hgap)
        gsizer = wx.GridSizer(len(colours), 3, 2, 2)

        n = 1
        for line in colours:
            #print line,  # eg. line = ('SNOW', 255, 250, 250)
            hexstr = "#%02X%02X%02X" % tuple(line[1:])
            s = "%3d  %s" % (n, line[0])
            t = wx.StaticText(self, wx.ID_ANY, s)
            gsizer.Add(t, 0, wx.ALL, border=2)
            t = wx.StaticText(self, wx.ID_ANY, hexstr)
            gsizer.Add(t, 0, wx.ALL, border=2)
            p = wx.Panel(self, wx.ID_ANY)
            p.SetBackgroundColour(hexstr)
            gsizer.Add(p, 0, wx.ALL|wx.EXPAND, border=2)
            n += 1

        # now add the whole thing to the main sizer and set it
        vsizer.Add(gsizer, 0, wx.ALL|wx.EXPAND, 10)
        self.SetSizer(vsizer)


app = wx.App(0)
# create a frame, no parent, default ID, title, size
caption = "all the colours in wx.lib.colourdb"
frame = wx.Frame(None, wx.ID_ANY, caption, size=(600, 450))
MyScrolledPanel(frame)
frame.Show(True)
app.MainLoop()
Member Avatar for rbyrd

This is wonderful. Thank you so much. I think others will also find this useful.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.