blob: 3eeccbf77747b26516e0abcfa69bcff34c622a63 [file] [log] [blame]
Barry Warsaw516f1891998-01-27 03:19:00 +00001#! /usr/bin/env python
2
3"""Pynche: The PYthon Natural Color and Hue Editor.
4
5Pynche is based largely on a similar color editor I wrote years ago for the
6Sunview window system. That editor was called ICE: the Interactive Color
7Editor. I'd always wanted to port the editor to X but didn't feel like
8hacking X and C code to do it. Fast forward many years, to where Python +
9Tkinter + Pmw provides such a nice programming environment, with enough
10power, that I finally buckled down and implemented it. I changed the name
11because these days, too many other systems have the acronym `ICE'.
12
Barry Warsawf7c1e5a1998-01-31 23:39:28 +000013This program currently requires Python 1.5 with Tkinter. It also requires at
14least Pmw 0.6.1. It has only been tested on Solaris 2.6. Feedback is greatly
15appreciated. Send email to bwarsaw@python.org
16
17Usage: %(PROGRAM)s [-h]
Barry Warsaw516f1891998-01-27 03:19:00 +000018
19Where:
20 --help
21 -h
22 print this message
23
24"""
25
26__version__ = '1.0'
27
Barry Warsawf7c1e5a1998-01-31 23:39:28 +000028import sys
29import getopt
30import Pmw
31import ColorDB
32from Tkinter import *
33from PyncheWidget import PyncheWidget
34
35
36
37PROGRAM = sys.argv[0]
38
39# Milliseconds between interrupt checks
40KEEPALIVE_TIMER = 500
41
42RGBCOLOR = 1
43HSICOLOR = 2
44NAMEDCOLOR = 3
45
46# Default locations of rgb.txt or other textual color database
47RGB_TXT = [
48 # Solaris OpenWindows
49 '/usr/openwin/lib/rgb.txt',
50 # add more here
51 ]
52
53
54
55def usage(status, msg=''):
56 if msg:
57 print msg
58 print __doc__ % globals()
59 sys.exit(status)
60
61
62
63app = None
64
65def keepalive():
66 # Exercise the Python interpreter regularly so keybard interrupts get
67 # through.
68 app.tk.createtimerhandler(KEEPALIVE_TIMER, keepalive)
69
70
71def main():
72 global app
73
74 initialcolor = 'grey50'
75 try:
76 opts, args = getopt.getopt(sys.argv[1:],
77 'hc:',
78 ['color=', 'help'])
79 except getopt.error, msg:
80 usage(1, msg)
81
82 if args:
83 usage(1)
84
85 for opt, arg in opts:
86 if opt in ('-h', '--help'):
87 usage(0)
88 elif opt in ('-c', '--color'):
89 initialcolor = arg
90
91 # create the windows and go
92 for f in RGB_TXT:
93 try:
94 colordb = ColorDB.get_colordb(f)
95 break
96 except IOError:
97 pass
98 else:
99 raise IOError('No color database file found')
100
101 app = Pmw.initialise(fontScheme='pmw1')
102 app.title('Pynche %s' % __version__)
103 app.tk.createtimerhandler(KEEPALIVE_TIMER, keepalive)
104 p = PyncheWidget(colordb, app, color=initialcolor)
105 try:
106 keepalive()
107 app.mainloop()
108 except KeyboardInterrupt:
109 pass
110
111
112
113if __name__ == '__main__':
114 main()