TIP #154 Version 1.2: Add Named Colors to Tk

This is not necessarily the current version of this TIP.


TIP:154
Title:Add Named Colors to Tk
Version:$Revision: 1.2 $
Author:Damon Courtney <damon at unreality dot com>
State:Draft
Type:Project
Tcl-Version:8.5
Vote:Pending
Created:Wednesday, 03 September 2003

Abstract

This TIP proposes the addition of a color command at the Tk level to allow developers to create named colors as they can already do with both fonts and images.

Rationale

Named fonts and images go a long way toward making Tk able to modify a lot of options on a global scale simply by adjusting a single item. Tk already simulates some version of named colors on Windows with the use of values like 'SystemButtonFace' and 'SystemWindowFrame'. These color names map to values pre-defined in Windows. On UNIX, we have to kind of fake these things around.

With the addition of a color command, we can simply define default olors in UNIX that correspond to existing named colors on Windows. So, we could create 'SystemButtonFace' as a named color on UNIX, and any Windows program using those color names would port to UNIX without a change (we may do this already. I haven't run Tk on UNIX in some time).

Implementation

I propose the introduction of a new command, 'color':

color <option> ?arg ..?

color create <colorName> ?option ..? Creates a new named color.

Options (for now)

-color <color>

color cget <colorName> <option> Standard function to get an option value.

color configure <colorName> ?option ..? Standard function to configure a color's values.

color exists <colorName> Determine if a named color exists.

color names ?pattern? Returns a list of all named colors, including ones created by Tk.

color delete <colorName> Deletes a named color.

Beyond the color command, we need to implement a default set of standard colors that will exist across all platforms. As proposed by some, I think these should be named Tk*. The current list (reflected in the Windows color list) would be:

TkButtonFace TkButtonText TkDisabledText TkHighlight TkHighlightText TkMenu TkMenuText TkScrollbar TkWindow TkWindowFrame TkWindowText

If there are others, I'm not sure what they are. This list can easily be expanded over time as most of them will be created at the Tcl-level. I also think we need to consider a default color scheme on the UNIX platforms until we work out a way to support the user's native theme. The "Griffin" theme seems a likely candidate. UNIX platforms then need to specify their colors as named colors instead of the hard-coded values they have now (as Windows already does).

I think over time named colors will be enhanced to support a lot more options. I'd really like to have options like -light1, -light2, -dark1, -dark2 to support defining a single color AND its border shadings. This would allow for a lot of flexibility in defining a color, applying it to a button and have all the borders change with it. I think this is out of my skills right now and therefore not part of this TIP.

Copyright

This document has been placed in the public domain.


Powered by TclThis is not necessarily the current version of this TIP.

TIP AutoGenerator - written by Donal K. Fellows