1 Pynche - The PYthonically Natural Color and Hue Editor
3 Contact: Barry A. Warsaw
4 Email: bwarsaw@python.org
9 Pynche is a color editor based largely on a similar program that I
10 originally wrote back in 1987 for the Sunview window system. That
11 editor was called ICE, the Interactive Color Editor. I'd always
12 wanted to port this program to X but didn't feel like hacking X
13 and C code to do it. Fast forward many years, to where Python +
14 Tkinter provides such a nice programming environment, with enough
15 power, that I finally buckled down and re-implemented it. I
16 changed the name because these days, too many other systems have
19 Pynche should work with Python 1.5.2, 2.0, or 2.1, using Tk 8.0.x.
20 It's been tested on Solaris 2.6, Windows NT 4, and various Linux
21 distros. You'll want to be sure to have at least Tk 8.0.3 for
22 Windows. Also, Pynche is very colormap intensive, so it doesn't
23 work very well on 8-bit graphics cards; 24bit+ graphics cards are
24 so cheap these days, I'll probably never "fix" that.
26 Pynche must find a text database of colors names in order to
27 provide `nearest' color matching. Pynche is distributed with an
28 rgb.txt file from the X11R6.4 distribution for this reason, along
29 with other "Web related" database (see below). You can use a
30 different file with the -d option. The file xlicense.txt contains
31 the license only for rgb.txt and both files are in the X/
34 Pynche is pronounced: Pin'-chee
39 On Unix, start it by running the `pynche' script. On Windows, run
40 pynche.pyw to inhibit the console window. When run from the
41 command line, the following options are recognized:
45 Alternate location of the color database file. Without this
46 option, the first valid file found will be used (see below).
50 Alternate location of the persistent initialization file. See
51 the section on Persistency below.
55 Ignore the persistent initialization file when starting up.
56 Pynche will still write the current option settings to the
57 persistent init file when it quits.
61 Print the help message.
64 a Tk color name or #rrggbb color spec to be used as the
65 initially selected color. This overrides any color saved in
66 the persistent init file. Since `#' needs to be escaped in
67 many shells, it is optional in the spec (e.g. #45dd1f is the
71 Running as a Modal Dialog
73 Pynche can be run as a modal dialog, inside another application,
74 say as a general color chooser. In fact, Grail 0.6 uses Pynche
75 and a future version of IDLE may as well. Pynche supports the API
76 implemented by the Tkinter standard tkColorChooser module, with a
77 few changes as described below. By importing pyColorChooser from
78 the Pynche package, you can run
80 pyColorChooser.askcolor()
82 which will popup Pynche as a modal dialog, and return the selected
85 There are some UI differences when running as a modal
86 vs. standalone. When running as a modal, there is no "Quit" menu
87 item under the "File" menu. Instead there are "Okay" and "Cancel"
90 When "Okay" is hit, askcolor() returns the tuple
94 where r, g, and b are red, green, and blue color values
95 respectively (in the range 0 to 255). "name" will be a color name
96 from the color database if there is an exact match, otherwise it
97 will be an X11 color spec of the form "#rrggbb". Note that this
98 is different than tkColorChooser, which doesn't know anything
101 askcolor() supports the following optional keyword arguments:
104 the color to set as the initial selected color
107 the master window to use as the parent of the modal
108 dialog. Without this argument, pyColorChooser will create
109 it's own Tkinter.Tk instance as the master. This may not
113 similar to the --database option, the value must be a
117 similar to the --initfile option, the value must be a
121 similar to the --ignore flag, the value is a boolean
124 When this is true, the "name" field in the return tuple
125 will always be a color spec of the form "#rrggbb". It
126 will not return a color name even if there is a match;
127 this is so pyColorChooser can exactly match the API of
130 [*] these arguments must be specified the first time
131 askcolor() is used and cannot be changed on subsequent calls.
134 The Colorstrip Window
136 The top part of the main Pynche window contains the "variation
137 strips". Each strip contains a number of "color chips". The
138 strips always indicate the currently selected color by a highlight
139 rectangle around the selected color chip, with an arrow pointing
140 to the chip. Each arrow has an associated number giving you the
141 color value along the variation's axis. Each variation strip
142 shows you the colors that are reachable from the selected color by
143 varying just one axis of the color solid.
145 For example, when the selected color is (in Red/Green/Blue
146 notation) 127/127/127, the Red Variations strip shows you every
147 color in the range 0/127/127 to 255/127/127. Similarly for the
148 green and blue axes. You can select any color by clicking on its
149 chip. This will update the highlight rectangle and the arrow, as
150 well as other displays in Pynche.
152 Click on "Update while dragging" if you want Pynche to update the
153 selected color while you drag along any variation strip (this will
154 be a bit slower). Click on "Hexadecimal" to display the arrow
157 There are also two shortcut buttons in this window, which
158 auto-select Black (0/0/0) and White (255/255/255).
163 In the lower left corner of the main window you see two larger
164 color chips. The Selected chip shows you a larger version of the
165 color selected in the variation strips, along with its X11 color
166 specification. The Nearest chip shows you the closest color in
167 the X11 database to the selected color, giving its X11 color name.
168 Clicking on the Nearest color chip selects that color. Color
169 distance is calculated in the 3D space of the RGB color solid and
170 if more than one color name is the same distance from the selected
171 color, the first one found will be chosen.
173 Note that there may be more than one X11 color name for the same
174 RGB value. In that case, the first one found in the text database
175 is designated the "primary" name, and this is shown under the
176 Nearest chip. The other names are "aliases" and they are visible
177 in the Color List Window (see below).
182 At the lower right of the main window are three entry fields.
183 Here you can type numeric values for any of the three color axes.
184 Legal values are between 0 and 255, and these fields do not allow
185 you to enter illegal values. You must hit Enter or Tab to select
188 Click on "Update while typing" if you want Pynche to select the
189 color on every keystroke (well, every one that produces a legal
190 value!) Click on "Hexadecimal" to display and enter color values
196 There are three secondary windows which are not displayed by
197 default. You can bring these up via the "View" menu on the main
203 The "Text Window" allows you to see what effects various colors
204 have on the standard Tk text widget elements. In the upper part
205 of the window is a plain Tk text widget and here you can edit the
206 text, select a region of text, etc. Below this is a button "Track
207 color changes". When this is turned on, any colors selected in
208 the other windows will change the text widget element specified in
209 the radio buttons below. When this is turned off, text widget
210 elements are not affected by color selection.
212 You can choose which element gets changed by color selection by
213 clicking on one of the radio buttons in the bottom part of this
214 window. Text foreground and background affect the text in the
215 upper part of the window. Selection foreground and background
216 affect the colors of the primary selection which is what you see
217 when you click the middle button (depending on window system) and
218 drag it through some text.
220 The Insertion is the insertion cursor in the text window, where
221 new text will be inserted as you type. The insertion cursor only
225 The Color List Window
227 The "Color List" window shows every named color in the color name
228 database (this window may take a while to come up). In the upper
229 part of the window you see a scrolling list of all the color names
230 in the database, in alphabetical order. Click on any color to
231 select it. In the bottom part of the window is displayed any
232 aliases for the selected color (those color names that have the
233 same RGB value, but were found later in the text database). For
234 example, find the color "Black" and you'll see that its aliases
235 are "gray0" and "grey0".
237 If the color has no aliases you'll see "<no aliases>" here. If you
238 just want to see if a color has an alias, and do not want to select a
239 color when you click on it, turn off "Update on Click".
241 Note that the color list is always updated when a color is selected
242 from the main window. There's no way to turn this feature off. If
243 the selected color has no matching color name you'll see
244 "<no matching color>" in the Aliases window.
249 The "Details" window gives you more control over color selection
250 than just clicking on a color chip in the main window. The row of
251 buttons along the top apply the specified increment and decrement
252 amounts to the selected color. These delta amounts are applied to
253 the variation strips specified by the check boxes labeled "Move
254 Sliders". Thus if just Red and Green are selected, hitting -10
255 will subtract 10 from the color value along the red and green
256 variation only. Note the message under the checkboxes; this
257 indicates the primary color level being changed when more than one
258 slider is tied together. For example, if Red and Green are
259 selected, you will be changing the Yellow level of the selected
262 The "At Boundary" behavior determines what happens when any color
263 variation hits either the lower or upper boundaries (0 or 255) as
264 a result of clicking on the top row buttons:
267 When the increment or decrement would send any of the tied
268 variations out of bounds, the entire delta is discarded.
271 When the increment or decrement would send any of the tied
272 variations out of bounds, the out of bounds value is wrapped
273 around to the other side. Thus if red were at 238 and +25
274 were clicked, red would have the value 7.
277 When the increment or decrement would send any of the tied
278 variations out of bounds, all tied variations are wrapped as
279 one, so as to preserve the distance between them. Thus if
280 green and blue were tied, and green was at 238 while blue was
281 at 223, and +25 were clicked, green would be at 15 and blue
285 When the increment or decrement would send any of the tied
286 variations out of bounds, the out of bounds variation is set
287 to the ceiling of 255 or floor of 0, as appropriate. In this
288 way, all tied variations are squashed to one edge or the
291 The top row buttons have the following keyboard accelerators:
293 -25 == Shift Left Arrow
294 -10 == Control Left Arrow
297 +10 == Control Right Arrow
298 +25 == Shift Right Arrow
301 Keyboard Accelerators
303 Alt-w in any secondary window dismisses the window. In the main
304 window it exits Pynche (except when running as a modal).
306 Alt-q in any window exits Pynche (except when running as a modal).
311 Pynche remembers various settings of options and colors between
312 invocations, storing these values in a `persistent initialization
313 file'. The actual location of this file is specified by the
314 --initfile option (see above), and defaults to ~/.pynche.
316 When Pynche exits, it saves these values in the init file, and
317 re-reads them when it starts up. There is no locking on this
318 file, so if you run multiple instances of Pynche at a time, you
319 may clobber the init file.
321 The actual options stored include
323 - the currently selected color
325 - all settings of checkbox and radio button options in all windows
327 - the contents of the text window, the current text selection and
328 insertion point, and all current text widget element color
331 - the name of the color database file (but not its contents)
333 You can inhibit Pynche from reading the init file by supplying the
334 --ignore option on the command line. However, you cannot suppress
335 the storing of the settings in the init file on Pynche exit. If
336 you really want to do this, use /dev/null as the init file, using
340 Color Name Database Files
342 Pynche uses a color name database file to calculate the nearest
343 color to the selected color, and to display in the Color List
344 view. Several files are distributed with Pynche, described
345 below. By default, the X11 color name database file is selected.
348 html40colors.txt -- the HTML 4.0 guaranteed color names
350 websafe.txt -- the 216 "Web-safe" colors that Netscape and MSIE
351 guarantee will not be dithered. These are specified in #rrggbb
352 format for both values and names
354 webcolors.txt -- The 140 color names that Tim Peters and his
355 sister say NS and MSIE both understand (with some controversy over
358 namedcolors.txt -- an alternative set of Netscape colors.
360 You can switch between files by choosing "Load palette..." from
361 the "File" menu. This brings up a standard Tk file dialog.
362 Choose the file you want and then click "Ok". If Pynche
363 understands the format in this file, it will load the database and
364 update the appropriate windows. If not, it will bring up an error
370 Here's a brief list of things I want to do (some mythical day):
372 - Better support for resizing the top level windows
374 - More output views, e.g. color solids
376 - Have the notion of a `last color selected'; this may require a
379 - Support setting the font in the text view
381 - Support distutils setup.py for installation
383 I'm open to suggestions!
388 indent-tabs-mode: nil