I'm just learning how to use the color database, and ran across this thread, poking around in search of hints and examples. So, now you know that I am not an expert on this topic, but I will tell you what I have discovered so far.
I do not think you need to do wx.lib.colourdb.updateColourDB (). I do not use it, and for me the database seems to be already populated. On my Ubuntu 12.04 system with wxPy 2.8.? The database is initialized to 630 colors without this command. If you use the wx.lib.colourdb.updateColourDB () command and then count the colors, I get only 630 colors. If I print a list of color names, the list seems to have the same colors in it regardless of whether I issue the command wx.lib.colourdb.updateColourDB () or not.
I also had a problem with colors that were all white, but I tried to access the colors by increasing the index in a for loop. I am writing an application that makes two-dimensional pie charts, trying to assign canvas brush colors to fill in fill sectors with different colors. I used the first 6 colors on the list (for the 6 sector cake) and found that the whole cake was white. In the end, I looked at the list of colors (DuHHH!) And found a problem ... the first 7 or so colors are just a few different shades of white and so similar to each other, they seem to be exactly the same colors.
I found 2 different solutions to this "all white" problem. The first solution involves shuffling the color list with Python random.shuffle (sequence).
import wx from random import shuffle, seed from wx.lib.colourdb import getColourList class MyFrame(wx.Frame): def __init__(self, parent, id, title): wx.Frame.__init__(self, parent, id, title, size=(1000, 1000))
Try something like above the first with the first comment as it is, and then with it without comment. I think you find a list printed in a for loop will be exactly the same in both cases.
Later in my application, I run a loop to draw pie sectors on wx.PaintDC. I can do this in different ways, depending on whether I am shuffling the list of colors. Shuffling distributes white (ish) colors randomly throughout the list, so all sectors are filled with different colors. Here is the relevant piece of code.
dc = wx.PaintDC(self.panel) for i in range(sector_count): dc.SetBrush(wx.Brush(self.colors[i])) DrawNextPieSector(dc)
Another solution I found was to not shuffle the list of colors and instead multiply the loop index by a constant in the brush destination as follows.
dc.SetBrush(wx.Brush(self.colors[i * 10]))
The above operator selects every 10th color, which means that the first sector will always be white, and the rest will be different colors.
Shuffling the list takes about 2 seconds on my old computer, but it is slow. Each time the application is running, the sectors have different colors than in the previous one. This may or may not be desirable, depending on what the application should do.
I want the sectors to be the same color every time the application starts, because the end user wants to associate a specific color with a specific data set. For this reason, I use the second approach. This is faster, but limits the application to 63 colors if the index factor is 10, as in the example above. I suppose I could change the cycle a bit and change the factor for every 6th iteration or something like that, but 63 colors are enough for me.