1 """Pynche -- The PYthon Natural Color and Hue Editor.
4 Email: bwarsaw@python.org
5 Version: %(__version__)s
7 Pynche is based largely on a similar color editor I wrote years ago for the
8 Sunview window system. That editor was called ICE: the Interactive Color
9 Editor. I'd always wanted to port the editor to X but didn't feel like
10 hacking X and C code to do it. Fast forward many years, to where Python +
11 Tkinter provides such a nice programming environment, with enough power, that
12 I finally buckled down and implemented it. I changed the name because these
13 days, too many other systems have the acronym `ICE'.
15 This program currently requires Python 1.5 with Tkinter. It has only been
16 tested on Solaris 2.6. Feedback is greatly appreciated. Send email to
19 Usage: %(PROGRAM)s [-d file] [-i file] [-X] [-v] [-h] [initialcolor]
24 Alternate location of a color database file
28 Alternate location of the initialization file. This file contains a
29 persistent database of the current Pynche options and color. This
30 means that Pynche restores its option settings and current color when
31 it restarts, using this file (unless the -X option is used). The
36 Ignore the initialization file when starting up. Pynche will still
37 write the current option settings to this file when it quits.
41 print the version number
48 initial color, as a color name or #RRGGBB format
59 from PyncheWidget
import PyncheWidget
60 from Switchboard
import Switchboard
61 from StripViewer
import StripViewer
62 from ChipViewer
import ChipViewer
63 from TypeinViewer
import TypeinViewer
69 # Default locations of rgb.txt or other textual color database
72 '/usr/openwin/lib/rgb.txt',
73 # The X11R6.4 rgb.txt file
74 os
.path
.join(sys
.path
[0], 'X/rgb.txt'),
81 return string
.rstrip(__doc__
% globals())
84 def usage(status
, msg
=''):
92 def initial_color(s
, colordb
):
93 # function called on every color
94 def scan_color(s
, colordb
=colordb
):
96 r
, g
, b
= colordb
.find_byname(s
)
97 except ColorDB
.BadColor
:
99 r
, g
, b
= ColorDB
.rrggbb_to_triplet(s
)
100 except ColorDB
.BadColor
:
101 return None, None, None
104 # First try the passed in color
105 r
, g
, b
= scan_color(s
)
107 # try the same color with '#' prepended, since some shells require
108 # this to be escaped, which is a pain
109 r
, g
, b
= scan_color('#' + s
)
111 print 'Bad initial color, using gray50:', s
112 r
, g
, b
= scan_color('gray50')
114 usage(1, 'Cannot find an initial color to use')
120 def build(master
=None, initialcolor
=None, initfile
=None, ignore
=None):
121 # create the windows and go
124 colordb
= ColorDB
.get_colordb(f
)
130 usage(1, 'No color database file found, see the -d option.')
132 # create all output widgets
133 s
= Switchboard(colordb
, not ignore
and initfile
)
135 # create the application window decorations
136 app
= PyncheWidget(__version__
, s
, master
=master
)
139 s
.add_view(StripViewer(s
, w
))
140 s
.add_view(ChipViewer(s
, w
))
141 s
.add_view(TypeinViewer(s
, w
))
143 # get the initial color as components and set the color on all views. if
144 # there was no initial color given on the command line, use the one that's
145 # stored in the option database
146 if initialcolor
is None:
147 optiondb
= s
.optiondb()
148 red
= optiondb
.get('RED')
149 green
= optiondb
.get('GREEN')
150 blue
= optiondb
.get('BLUE')
151 # but if there wasn't any stored in the database, use grey50
152 if red
is None or blue
is None or green
is None:
153 red
, green
, blue
= initial_color('grey50', colordb
)
155 red
, green
, blue
= initial_color(initialcolor
, colordb
)
156 s
.update_views(red
, green
, blue
)
163 except KeyboardInterrupt:
170 opts
, args
= getopt
.getopt(
173 ['database=', 'initfile=', 'ignore', 'help', 'version'])
174 except getopt
.error
, msg
:
180 initialcolor
= args
[0]
185 initfile
= os
.path
.expanduser('~/.pynche')
186 for opt
, arg
in opts
:
187 if opt
in ('-h', '--help'):
189 elif opt
in ('-v', '--version'):
191 Pynche -- The PYthon Natural Color and Hue Editor.
192 Contact: Barry Warsaw
193 Email: bwarsaw@python.org
194 Version: %s''' % __version__
196 elif opt
in ('-d', '--database'):
197 RGB_TXT
.insert(0, arg
)
198 elif opt
in ('-X', '--ignore'):
200 elif opt
in ('-i', '--initfile'):
203 app
, sb
= build(initialcolor
=initialcolor
,
210 if __name__
== '__main__':