1
"""Pynche -- The PYthon Natural Color and Hue Editor.
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 2.2 with Tkinter.
17
Usage: %(PROGRAM)s [-d file] [-i file] [-X] [-v] [-h] [initialcolor]
22
Alternate location of a color database file
26
Alternate location of the initialization file. This file contains a
27
persistent database of the current Pynche options and color. This
28
means that Pynche restores its option settings and current color when
29
it restarts, using this file (unless the -X option is used). The
34
Ignore the initialization file when starting up. Pynche will still
35
write the current option settings to this file when it quits.
39
print the version number and exit
46
initial color, as a color name or #RRGGBB format
56
from PyncheWidget import PyncheWidget
57
from Switchboard import Switchboard
58
from StripViewer import StripViewer
59
from ChipViewer import ChipViewer
60
from TypeinViewer import TypeinViewer
65
AUTHNAME = 'Barry Warsaw'
66
AUTHEMAIL = 'barry@python.org'
68
# Default locations of rgb.txt or other textual color database
71
'/usr/openwin/lib/rgb.txt',
73
'/usr/lib/X11/rgb.txt',
74
# The X11R6.4 rgb.txt file
75
os.path.join(sys.path[0], 'X/rgb.txt'),
81
# Do this because PyncheWidget.py wants to get at the interpolated docstring
82
# too, for its Help menu.
84
return __doc__ % globals()
87
def usage(code, msg=''):
95
def initial_color(s, colordb):
96
# function called on every color
97
def scan_color(s, colordb=colordb):
99
r, g, b = colordb.find_byname(s)
100
except ColorDB.BadColor:
102
r, g, b = ColorDB.rrggbb_to_triplet(s)
103
except ColorDB.BadColor:
104
return None, None, None
107
# First try the passed in color
108
r, g, b = scan_color(s)
110
# try the same color with '#' prepended, since some shells require
111
# this to be escaped, which is a pain
112
r, g, b = scan_color('#' + s)
114
print('Bad initial color, using gray50:', s)
115
r, g, b = scan_color('gray50')
117
usage(1, 'Cannot find an initial color to use')
123
def build(master=None, initialcolor=None, initfile=None, ignore=None,
125
# create all output widgets
126
s = Switchboard(not ignore and initfile)
127
# defer to the command line chosen color database, falling back to the one
128
# in the .pynche file.
130
dbfile = s.optiondb().get('DBFILE')
131
# find a parseable color database
136
while colordb is None:
138
colordb = ColorDB.get_colordb(dbfile)
139
except (KeyError, IOError):
144
dbfile = files.pop(0)
146
usage(1, 'No color database file found, see the -d option.')
147
s.set_colordb(colordb)
149
# create the application window decorations
150
app = PyncheWidget(__version__, s, master=master)
153
# these built-in viewers live inside the main Pynche window
154
s.add_view(StripViewer(s, w))
155
s.add_view(ChipViewer(s, w))
156
s.add_view(TypeinViewer(s, w))
158
# get the initial color as components and set the color on all views. if
159
# there was no initial color given on the command line, use the one that's
160
# stored in the option database
161
if initialcolor is None:
162
optiondb = s.optiondb()
163
red = optiondb.get('RED')
164
green = optiondb.get('GREEN')
165
blue = optiondb.get('BLUE')
166
# but if there wasn't any stored in the database, use grey50
167
if red is None or blue is None or green is None:
168
red, green, blue = initial_color('grey50', colordb)
170
red, green, blue = initial_color(initialcolor, colordb)
171
s.update_views(red, green, blue)
178
except KeyboardInterrupt:
185
opts, args = getopt.getopt(
188
['database=', 'initfile=', 'ignore', 'help', 'version'])
189
except getopt.error as msg:
195
initialcolor = args[0]
201
initfile = os.path.expanduser('~/.pynche')
202
for opt, arg in opts:
203
if opt in ('-h', '--help'):
205
elif opt in ('-v', '--version'):
207
Pynche -- The PYthon Natural Color and Hue Editor.
208
Contact: %(AUTHNAME)s
210
Version: %(__version__)s""" % globals())
212
elif opt in ('-d', '--database'):
214
elif opt in ('-X', '--ignore'):
216
elif opt in ('-i', '--initfile'):
219
app, sb = build(initialcolor=initialcolor,
228
if __name__ == '__main__':