Pynche - The PYthonically Natural Color and Hue EditorContact: Barry A. WarsawEmail: bwarsaw@python.orgVersion: 1.3IntroductionPynche is a color editor based largely on a similar program that Ioriginally wrote back in 1987 for the Sunview window system. Thateditor was called ICE, the Interactive Color Editor. I'd alwayswanted to port this program to X but didn't feel like hacking Xand C code to do it. Fast forward many years, to where Python +Tkinter provides such a nice programming environment, with enoughpower, that I finally buckled down and re-implemented it. Ichanged the name because these days, too many other systems havethe acronym `ICE'.Pynche should work with any variant of Python after 1.5.2(e.g. 2.0.1 and 2.1.1), using Tk 8.0.x. It's been tested onSolaris 2.6, Windows NT 4, and various Linux distros. You'll wantto be sure to have at least Tk 8.0.3 for Windows. Also, Pynche isvery colormap intensive, so it doesn't work very well on 8-bitgraphics cards; 24bit+ graphics cards are so cheap these days,I'll probably never "fix" that.Pynche must find a text database of colors names in order toprovide `nearest' color matching. Pynche is distributed with anrgb.txt file from the X11R6.4 distribution for this reason, alongwith other "Web related" database (see below). You can use adifferent file with the -d option. The file xlicense.txt containsthe license only for rgb.txt and both files are in the X/subdirectory.Pynche is pronounced: Pin'-cheeRunning StandaloneOn Unix, start it by running the `pynche' script. On Windows, runpynche.pyw to inhibit the console window. When run from thecommand line, the following options are recognized:--database file-d fileAlternate location of the color database file. Without thisoption, the first valid file found will be used (see below).--initfile file-i fileAlternate location of the persistent initialization file. Seethe section on Persistency below.--ignore-XIgnore the persistent initialization file when starting up.Pynche will still write the current option settings to thepersistent init file when it quits.--help-hPrint the help message.initialcolora Tk color name or #rrggbb color spec to be used as theinitially selected color. This overrides any color saved inthe persistent init file. Since `#' needs to be escaped inmany shells, it is optional in the spec (e.g. #45dd1f is thesame as 45dd1f).Running as a Modal DialogPynche can be run as a modal dialog, inside another application,say as a general color chooser. In fact, Grail 0.6 uses Pyncheand a future version of IDLE may as well. Pynche supports the APIimplemented by the Tkinter standard tkColorChooser module, with afew changes as described below. By importing pyColorChooser fromthe Pynche package, you can runpyColorChooser.askcolor()which will popup Pynche as a modal dialog, and return the selectedcolor.There are some UI differences when running as a modalvs. standalone. When running as a modal, there is no "Quit" menuitem under the "File" menu. Instead there are "Okay" and "Cancel"buttons.When "Okay" is hit, askcolor() returns the tuple((r, g, b), "name")where r, g, and b are red, green, and blue color valuesrespectively (in the range 0 to 255). "name" will be a color namefrom the color database if there is an exact match, otherwise itwill be an X11 color spec of the form "#rrggbb". Note that thisis different than tkColorChooser, which doesn't know anythingabout color names.askcolor() supports the following optional keyword arguments:colorthe color to set as the initial selected colormaster[*]the master window to use as the parent of the modaldialog. Without this argument, pyColorChooser will createits own Tkinter.Tk instance as the master. This may notbe what you want.databasefilesimilar to the --database option, the value must be afile nameinitfile[*]similar to the --initfile option, the value must be afile nameignore[*]similar to the --ignore flag, the value is a booleanwantspecWhen this is true, the "name" field in the return tuplewill always be a color spec of the form "#rrggbb". Itwill not return a color name even if there is a match;this is so pyColorChooser can exactly match the API oftkColorChooser.[*] these arguments must be specified the first timeaskcolor() is used and cannot be changed on subsequent calls.The Colorstrip WindowThe top part of the main Pynche window contains the "variationstrips". Each strip contains a number of "color chips". Thestrips always indicate the currently selected color by a highlightrectangle around the selected color chip, with an arrow pointingto the chip. Each arrow has an associated number giving you thecolor value along the variation's axis. Each variation stripshows you the colors that are reachable from the selected color byvarying just one axis of the color solid.For example, when the selected color is (in Red/Green/Bluenotation) 127/127/127, the Red Variations strip shows you everycolor in the range 0/127/127 to 255/127/127. Similarly for thegreen and blue axes. You can select any color by clicking on itschip. This will update the highlight rectangle and the arrow, aswell as other displays in Pynche.Click on "Update while dragging" if you want Pynche to update theselected color while you drag along any variation strip (this willbe a bit slower). Click on "Hexadecimal" to display the arrownumbers in hex.There are also two shortcut buttons in this window, whichauto-select Black (0/0/0) and White (255/255/255).The Proof WindowIn the lower left corner of the main window you see two largercolor chips. The Selected chip shows you a larger version of thecolor selected in the variation strips, along with its X11 colorspecification. The Nearest chip shows you the closest color inthe X11 database to the selected color, giving its X11 colorspecification, and below that, its X11 color name. When theSelected chip color exactly matches the Nearest chip color, youwill see the color name appear below the color specification forthe Selected chip.Clicking on the Nearest color chip selects that color. Colordistance is calculated in the 3D space of the RGB color solid andif more than one color name is the same distance from the selectedcolor, the first one found will be chosen.Note that there may be more than one X11 color name for the sameRGB value. In that case, the first one found in the text databaseis designated the "primary" name, and this is shown under theNearest chip. The other names are "aliases" and they are visiblein the Color List Window (see below).Both the color specifications and color names are selectable forcopying and pasting into another window.The Type-in WindowAt the lower right of the main window are three entry fields.Here you can type numeric values for any of the three color axes.Legal values are between 0 and 255, and these fields do not allowyou to enter illegal values. You must hit Enter or Tab to selectthe new color.Click on "Update while typing" if you want Pynche to select thecolor on every keystroke (well, every one that produces a legalvalue!) Click on "Hexadecimal" to display and enter color valuesin hex.Other ViewsThere are three secondary windows which are not displayed bydefault. You can bring these up via the "View" menu on the mainPynche window.The Text WindowThe "Text Window" allows you to see what effects various colorshave on the standard Tk text widget elements. In the upper partof the window is a plain Tk text widget and here you can edit thetext, select a region of text, etc. Below this is a button "Trackcolor changes". When this is turned on, any colors selected inthe other windows will change the text widget element specified inthe radio buttons below. When this is turned off, text widgetelements are not affected by color selection.You can choose which element gets changed by color selection byclicking on one of the radio buttons in the bottom part of thiswindow. Text foreground and background affect the text in theupper part of the window. Selection foreground and backgroundaffect the colors of the primary selection which is what you seewhen you click the middle button (depending on window system) anddrag it through some text.The Insertion is the insertion cursor in the text window, wherenew text will be inserted as you type. The insertion cursor onlyhas a background.The Color List WindowThe "Color List" window shows every named color in the color namedatabase (this window may take a while to come up). In the upperpart of the window you see a scrolling list of all the color namesin the database, in alphabetical order. Click on any color toselect it. In the bottom part of the window is displayed anyaliases for the selected color (those color names that have thesame RGB value, but were found later in the text database). Forexample, find the color "Black" and you'll see that its aliasesare "gray0" and "grey0".If the color has no aliases you'll see "<no aliases>" here. If youjust want to see if a color has an alias, and do not want to select acolor when you click on it, turn off "Update on Click".Note that the color list is always updated when a color is selectedfrom the main window. There's no way to turn this feature off. Ifthe selected color has no matching color name you'll see"<no matching color>" in the Aliases window.The Details WindowThe "Details" window gives you more control over color selectionthan just clicking on a color chip in the main window. The row ofbuttons along the top apply the specified increment and decrementamounts to the selected color. These delta amounts are applied tothe variation strips specified by the check boxes labeled "MoveSliders". Thus if just Red and Green are selected, hitting -10will subtract 10 from the color value along the red and greenvariation only. Note the message under the checkboxes; thisindicates the primary color level being changed when more than oneslider is tied together. For example, if Red and Green areselected, you will be changing the Yellow level of the selectedcolor.The "At Boundary" behavior determines what happens when any colorvariation hits either the lower or upper boundaries (0 or 255) asa result of clicking on the top row buttons:StopWhen the increment or decrement would send any of the tiedvariations out of bounds, the entire delta is discarded.Wrap AroundWhen the increment or decrement would send any of the tiedvariations out of bounds, the out of bounds value is wrappedaround to the other side. Thus if red were at 238 and +25were clicked, red would have the value 7.Preserve DistanceWhen the increment or decrement would send any of the tiedvariations out of bounds, all tied variations are wrapped asone, so as to preserve the distance between them. Thus ifgreen and blue were tied, and green was at 238 while blue wasat 223, and +25 were clicked, green would be at 15 and bluewould be at 0.SquashWhen the increment or decrement would send any of the tiedvariations out of bounds, the out of bounds variation is setto the ceiling of 255 or floor of 0, as appropriate. In thisway, all tied variations are squashed to one edge or theother.The top row buttons have the following keyboard accelerators:-25 == Shift Left Arrow-10 == Control Left Arrow-1 == Left Arrow+1 == Right Arrow+10 == Control Right Arrow+25 == Shift Right ArrowKeyboard AcceleratorsAlt-w in any secondary window dismisses the window. In the mainwindow it exits Pynche (except when running as a modal).Alt-q in any window exits Pynche (except when running as a modal).PersistencyPynche remembers various settings of options and colors betweeninvocations, storing these values in a `persistent initializationfile'. The actual location of this file is specified by the--initfile option (see above), and defaults to ~/.pynche.When Pynche exits, it saves these values in the init file, andre-reads them when it starts up. There is no locking on thisfile, so if you run multiple instances of Pynche at a time, youmay clobber the init file.The actual options stored include- the currently selected color- all settings of checkbox and radio button options in all windows- the contents of the text window, the current text selection andinsertion point, and all current text widget element colorsettings.- the name of the color database file (but not its contents)You can inhibit Pynche from reading the init file by supplying the--ignore option on the command line. However, you cannot suppressthe storing of the settings in the init file on Pynche exit. Ifyou really want to do this, use /dev/null as the init file, using--initfile.Color Name Database FilesPynche uses a color name database file to calculate the nearestcolor to the selected color, and to display in the Color Listview. Several files are distributed with Pynche, describedbelow. By default, the X11 color name database file is selected.Other files:html40colors.txt -- the HTML 4.0 guaranteed color nameswebsafe.txt -- the 216 "Web-safe" colors that Netscape and MSIEguarantee will not be dithered. These are specified in #rrggbbformat for both values and nameswebcolors.txt -- The 140 color names that Tim Peters and hissister say NS and MSIE both understand (with some controversy overAliceBlue).namedcolors.txt -- an alternative set of Netscape colors.You can switch between files by choosing "Load palette..." fromthe "File" menu. This brings up a standard Tk file dialog.Choose the file you want and then click "Ok". If Pyncheunderstands the format in this file, it will load the database andupdate the appropriate windows. If not, it will bring up an errordialog.To DoHere's a brief list of things I want to do (some mythical day):- Better support for resizing the top level windows- More output views, e.g. color solids- Have the notion of a `last color selected'; this may require anew output view- Support setting the font in the text view- Support distutils setup.py for installationI'm open to suggestions!Local Variables:indent-tabs-mode: nilEnd:
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。