1998-01-27 03:19:00 +00:00
|
|
|
|
#! /usr/bin/env python
|
|
|
|
|
|
|
|
|
|
"""Pynche: The PYthon Natural Color and Hue Editor.
|
|
|
|
|
|
|
|
|
|
Pynche is based largely on a similar color editor I wrote years ago for the
|
|
|
|
|
Sunview window system. That editor was called ICE: the Interactive Color
|
|
|
|
|
Editor. I'd always wanted to port the editor to X but didn't feel like
|
|
|
|
|
hacking X and C code to do it. Fast forward many years, to where Python +
|
1998-09-28 16:28:04 +00:00
|
|
|
|
Tkinter provides such a nice programming environment, with enough power, that
|
|
|
|
|
I finally buckled down and implemented it. I changed the name because these
|
|
|
|
|
days, too many other systems have the acronym `ICE'.
|
1998-01-27 03:19:00 +00:00
|
|
|
|
|
1998-09-28 16:28:04 +00:00
|
|
|
|
This program currently requires Python 1.5 with Tkinter. It has only been
|
|
|
|
|
tested on Solaris 2.6. Feedback is greatly appreciated. Send email to
|
|
|
|
|
bwarsaw@python.org
|
1998-01-31 23:39:28 +00:00
|
|
|
|
|
1998-09-28 16:28:04 +00:00
|
|
|
|
Usage: %(PROGRAM)s [-d file] [-h] [initialcolor]
|
1998-01-27 03:19:00 +00:00
|
|
|
|
|
|
|
|
|
Where:
|
1998-09-28 16:28:04 +00:00
|
|
|
|
--database file
|
|
|
|
|
-d file
|
|
|
|
|
Alternate location of a color database file
|
1998-02-11 18:56:13 +00:00
|
|
|
|
|
1998-01-27 03:19:00 +00:00
|
|
|
|
--help
|
|
|
|
|
-h
|
|
|
|
|
print this message
|
|
|
|
|
|
1998-09-28 16:28:04 +00:00
|
|
|
|
initialcolor
|
|
|
|
|
initial color, as a color name or #RRGGBB format
|
|
|
|
|
|
1998-01-27 03:19:00 +00:00
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
__version__ = '1.0'
|
|
|
|
|
|
1998-01-31 23:39:28 +00:00
|
|
|
|
import sys
|
|
|
|
|
import getopt
|
|
|
|
|
import ColorDB
|
|
|
|
|
from Tkinter import *
|
|
|
|
|
from PyncheWidget import PyncheWidget
|
1998-09-28 16:28:04 +00:00
|
|
|
|
from Switchboard import Switchboard
|
1998-01-31 23:39:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PROGRAM = sys.argv[0]
|
|
|
|
|
|
|
|
|
|
# Milliseconds between interrupt checks
|
|
|
|
|
KEEPALIVE_TIMER = 500
|
|
|
|
|
|
|
|
|
|
# Default locations of rgb.txt or other textual color database
|
|
|
|
|
RGB_TXT = [
|
|
|
|
|
# Solaris OpenWindows
|
|
|
|
|
'/usr/openwin/lib/rgb.txt',
|
|
|
|
|
# add more here
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def usage(status, msg=''):
|
|
|
|
|
if msg:
|
|
|
|
|
print msg
|
|
|
|
|
print __doc__ % globals()
|
|
|
|
|
sys.exit(status)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app = None
|
|
|
|
|
|
|
|
|
|
def keepalive():
|
1998-09-28 16:28:04 +00:00
|
|
|
|
# Exercise the Python interpreter regularly so keyboard interrupts get
|
1998-01-31 23:39:28 +00:00
|
|
|
|
# through.
|
|
|
|
|
app.tk.createtimerhandler(KEEPALIVE_TIMER, keepalive)
|
|
|
|
|
|
|
|
|
|
|
1998-09-28 16:28:04 +00:00
|
|
|
|
def finished(event=None):
|
|
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
|
|
|
1998-01-31 23:39:28 +00:00
|
|
|
|
def main():
|
|
|
|
|
global app
|
|
|
|
|
|
|
|
|
|
try:
|
1998-09-28 16:28:04 +00:00
|
|
|
|
opts, args = getopt.getopt(
|
|
|
|
|
sys.argv[1:],
|
|
|
|
|
'hd:',
|
|
|
|
|
['database=', 'help'])
|
1998-01-31 23:39:28 +00:00
|
|
|
|
except getopt.error, msg:
|
|
|
|
|
usage(1, msg)
|
|
|
|
|
|
1998-09-28 16:28:04 +00:00
|
|
|
|
if len(args) == 0:
|
|
|
|
|
initialcolor = 'grey50'
|
|
|
|
|
elif len(args) == 1:
|
|
|
|
|
initialcolor = args[0]
|
|
|
|
|
else:
|
1998-01-31 23:39:28 +00:00
|
|
|
|
usage(1)
|
|
|
|
|
|
|
|
|
|
for opt, arg in opts:
|
|
|
|
|
if opt in ('-h', '--help'):
|
|
|
|
|
usage(0)
|
1998-09-28 16:28:04 +00:00
|
|
|
|
elif opt in ('-d', '--database'):
|
|
|
|
|
RGB_TXT.insert(0, arg)
|
1998-01-31 23:39:28 +00:00
|
|
|
|
|
|
|
|
|
# create the windows and go
|
|
|
|
|
for f in RGB_TXT:
|
|
|
|
|
try:
|
|
|
|
|
colordb = ColorDB.get_colordb(f)
|
|
|
|
|
break
|
|
|
|
|
except IOError:
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
raise IOError('No color database file found')
|
|
|
|
|
|
1998-09-28 16:28:04 +00:00
|
|
|
|
app = Tk(className='Pynche')
|
|
|
|
|
app.protocol('WM_DELETE_WINDOW', finished)
|
1998-01-31 23:39:28 +00:00
|
|
|
|
app.title('Pynche %s' % __version__)
|
1998-09-28 16:28:04 +00:00
|
|
|
|
app.iconname('Pynche')
|
1998-01-31 23:39:28 +00:00
|
|
|
|
app.tk.createtimerhandler(KEEPALIVE_TIMER, keepalive)
|
1998-02-11 18:56:13 +00:00
|
|
|
|
|
|
|
|
|
# get triplet for initial color
|
|
|
|
|
try:
|
|
|
|
|
red, green, blue = colordb.find_byname(initialcolor)
|
|
|
|
|
except ColorDB.BadColor:
|
|
|
|
|
# must be a #rrggbb style color
|
|
|
|
|
try:
|
|
|
|
|
red, green, blue = ColorDB.rrggbb_to_triplet(initialcolor)
|
|
|
|
|
except ColorDB.BadColor:
|
1998-09-28 16:28:04 +00:00
|
|
|
|
print 'Bad initial color, using default: %s' % initialcolor
|
|
|
|
|
initialcolor = 'grey50'
|
|
|
|
|
try:
|
|
|
|
|
red, green, blue = ColorDB.rrggbb_to_triplet(initialcolor)
|
|
|
|
|
except ColorDB.BadColor:
|
|
|
|
|
usage(1, 'Cannot find an initial color to use')
|
|
|
|
|
|
|
|
|
|
s = Switchboard(app, colordb, red, green, blue)
|
1998-01-31 23:39:28 +00:00
|
|
|
|
try:
|
|
|
|
|
keepalive()
|
|
|
|
|
app.mainloop()
|
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
main()
|