blob: 403f8b1f9fde2367e1967965dda5bf01d5691d72 [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 +
Barry Warsaw04c78861998-09-28 16:28:04 +00009Tkinter provides such a nice programming environment, with enough power, that
10I finally buckled down and implemented it. I changed the name because these
11days, too many other systems have the acronym `ICE'.
Barry Warsaw516f1891998-01-27 03:19:00 +000012
Barry Warsaw04c78861998-09-28 16:28:04 +000013This program currently requires Python 1.5 with Tkinter. It has only been
14tested on Solaris 2.6. Feedback is greatly appreciated. Send email to
15bwarsaw@python.org
Barry Warsawf7c1e5a1998-01-31 23:39:28 +000016
Barry Warsaw04c78861998-09-28 16:28:04 +000017Usage: %(PROGRAM)s [-d file] [-h] [initialcolor]
Barry Warsaw516f1891998-01-27 03:19:00 +000018
19Where:
Barry Warsaw04c78861998-09-28 16:28:04 +000020 --database file
21 -d file
22 Alternate location of a color database file
Barry Warsaweab81a91998-02-11 18:56:13 +000023
Barry Warsaw516f1891998-01-27 03:19:00 +000024 --help
25 -h
26 print this message
27
Barry Warsaw04c78861998-09-28 16:28:04 +000028 initialcolor
29 initial color, as a color name or #RRGGBB format
30
Barry Warsaw516f1891998-01-27 03:19:00 +000031"""
32
33__version__ = '1.0'
34
Barry Warsawf7c1e5a1998-01-31 23:39:28 +000035import sys
36import getopt
Barry Warsawf7c1e5a1998-01-31 23:39:28 +000037import ColorDB
Barry Warsawf7c1e5a1998-01-31 23:39:28 +000038from PyncheWidget import PyncheWidget
Barry Warsaw04c78861998-09-28 16:28:04 +000039from Switchboard import Switchboard
Barry Warsaw63c9e981998-09-28 23:41:53 +000040from StripViewer import StripViewer
Barry Warsaw4ab5d851998-10-01 16:47:06 +000041from ChipViewer import ChipViewer
42from TypeinViewer import TypeinViewer
Barry Warsawf7c1e5a1998-01-31 23:39:28 +000043
44
45
46PROGRAM = sys.argv[0]
47
Barry Warsawf7c1e5a1998-01-31 23:39:28 +000048# Default locations of rgb.txt or other textual color database
49RGB_TXT = [
50 # Solaris OpenWindows
51 '/usr/openwin/lib/rgb.txt',
52 # add more here
53 ]
54
55
56
57def usage(status, msg=''):
58 if msg:
59 print msg
60 print __doc__ % globals()
61 sys.exit(status)
62
63
64
Barry Warsawf7c1e5a1998-01-31 23:39:28 +000065def main():
Barry Warsawf7c1e5a1998-01-31 23:39:28 +000066 try:
Barry Warsaw04c78861998-09-28 16:28:04 +000067 opts, args = getopt.getopt(
68 sys.argv[1:],
69 'hd:',
70 ['database=', 'help'])
Barry Warsawf7c1e5a1998-01-31 23:39:28 +000071 except getopt.error, msg:
72 usage(1, msg)
73
Barry Warsaw04c78861998-09-28 16:28:04 +000074 if len(args) == 0:
75 initialcolor = 'grey50'
76 elif len(args) == 1:
77 initialcolor = args[0]
78 else:
Barry Warsawf7c1e5a1998-01-31 23:39:28 +000079 usage(1)
80
81 for opt, arg in opts:
82 if opt in ('-h', '--help'):
83 usage(0)
Barry Warsaw04c78861998-09-28 16:28:04 +000084 elif opt in ('-d', '--database'):
85 RGB_TXT.insert(0, arg)
Barry Warsawf7c1e5a1998-01-31 23:39:28 +000086
87 # create the windows and go
88 for f in RGB_TXT:
89 try:
90 colordb = ColorDB.get_colordb(f)
91 break
92 except IOError:
93 pass
94 else:
95 raise IOError('No color database file found')
96
Barry Warsaweab81a91998-02-11 18:56:13 +000097 # get triplet for initial color
98 try:
99 red, green, blue = colordb.find_byname(initialcolor)
100 except ColorDB.BadColor:
101 # must be a #rrggbb style color
102 try:
103 red, green, blue = ColorDB.rrggbb_to_triplet(initialcolor)
104 except ColorDB.BadColor:
Barry Warsaw04c78861998-09-28 16:28:04 +0000105 print 'Bad initial color, using default: %s' % initialcolor
106 initialcolor = 'grey50'
107 try:
108 red, green, blue = ColorDB.rrggbb_to_triplet(initialcolor)
109 except ColorDB.BadColor:
110 usage(1, 'Cannot find an initial color to use')
Barry Warsaweab81a91998-02-11 18:56:13 +0000111
Barry Warsaw63c9e981998-09-28 23:41:53 +0000112 # create all output widgets
Barry Warsaw4ab5d851998-10-01 16:47:06 +0000113 s = Switchboard(colordb)
114
115 # create the application window decorations
116 app = PyncheWidget(__version__, s)
117 parent = app.parent()
118
Barry Warsaw63c9e981998-09-28 23:41:53 +0000119 s.add_view(StripViewer(s, parent))
Barry Warsaw4ab5d851998-10-01 16:47:06 +0000120 s.add_view(ChipViewer(s, parent))
121 s.add_view(TypeinViewer(s, parent))
Barry Warsaw63c9e981998-09-28 23:41:53 +0000122 s.update_views(red, green, blue)
123
Barry Warsawf7c1e5a1998-01-31 23:39:28 +0000124 try:
Barry Warsaw63c9e981998-09-28 23:41:53 +0000125 app.start()
Barry Warsawf7c1e5a1998-01-31 23:39:28 +0000126 except KeyboardInterrupt:
127 pass
128
129
130
131if __name__ == '__main__':
132 main()