[pygtk] Generating theme-compatible colors

Samuel Abels newsgroups at debain.org
Tue Feb 17 09:12:55 WST 2009


Hi,

I am looking for a way to automatically get a set of related colors that
go well with the current theme. Because multiple sets of colors are
needed, I can't simply use the theme color.

(Explanation: I am writing an application in which colored boxes are
added into a text field, and the colors of each box are picked
automatically depending on the user who added them.)

Has anyone done this before me? My current (braindead) approach looks
like this:

palette = [(0.12, 0.29, 0.49),
           ...
           (1.0,  0.90, 0.34)]
def from_string(string, n_colors = 3): 
    first = string.__hash__() % (len(palette) - n_colors)
    if n_colors == 1:
        return palette[first]
    return [palette[i] for i in range(first, first + n_colors)]

This somewhat works, but the colors often don't go well with each other,
and a white box may be invisible on a theme in which textview widgets
have a white background.

Any idea how to do this properly?

-Samuel



More information about the pygtk mailing list