Barry Warsaw | 516f189 | 1998-01-27 03:19:00 +0000 | [diff] [blame] | 1 | #! /usr/bin/env python |
| 2 | |
| 3 | """Pynche: The PYthon Natural Color and Hue Editor. |
| 4 | |
| 5 | Pynche is based largely on a similar color editor I wrote years ago for the |
| 6 | Sunview window system. That editor was called ICE: the Interactive Color |
| 7 | Editor. I'd always wanted to port the editor to X but didn't feel like |
| 8 | hacking X and C code to do it. Fast forward many years, to where Python + |
Barry Warsaw | 04c7886 | 1998-09-28 16:28:04 +0000 | [diff] [blame] | 9 | Tkinter provides such a nice programming environment, with enough power, that |
| 10 | I finally buckled down and implemented it. I changed the name because these |
| 11 | days, too many other systems have the acronym `ICE'. |
Barry Warsaw | 516f189 | 1998-01-27 03:19:00 +0000 | [diff] [blame] | 12 | |
Barry Warsaw | 04c7886 | 1998-09-28 16:28:04 +0000 | [diff] [blame] | 13 | This program currently requires Python 1.5 with Tkinter. It has only been |
| 14 | tested on Solaris 2.6. Feedback is greatly appreciated. Send email to |
| 15 | bwarsaw@python.org |
Barry Warsaw | f7c1e5a | 1998-01-31 23:39:28 +0000 | [diff] [blame] | 16 | |
Barry Warsaw | 04c7886 | 1998-09-28 16:28:04 +0000 | [diff] [blame] | 17 | Usage: %(PROGRAM)s [-d file] [-h] [initialcolor] |
Barry Warsaw | 516f189 | 1998-01-27 03:19:00 +0000 | [diff] [blame] | 18 | |
| 19 | Where: |
Barry Warsaw | 04c7886 | 1998-09-28 16:28:04 +0000 | [diff] [blame] | 20 | --database file |
| 21 | -d file |
| 22 | Alternate location of a color database file |
Barry Warsaw | eab81a9 | 1998-02-11 18:56:13 +0000 | [diff] [blame] | 23 | |
Barry Warsaw | 516f189 | 1998-01-27 03:19:00 +0000 | [diff] [blame] | 24 | --help |
| 25 | -h |
| 26 | print this message |
| 27 | |
Barry Warsaw | 04c7886 | 1998-09-28 16:28:04 +0000 | [diff] [blame] | 28 | initialcolor |
| 29 | initial color, as a color name or #RRGGBB format |
| 30 | |
Barry Warsaw | 516f189 | 1998-01-27 03:19:00 +0000 | [diff] [blame] | 31 | """ |
| 32 | |
| 33 | __version__ = '1.0' |
| 34 | |
Barry Warsaw | f7c1e5a | 1998-01-31 23:39:28 +0000 | [diff] [blame] | 35 | import sys |
| 36 | import getopt |
Barry Warsaw | f7c1e5a | 1998-01-31 23:39:28 +0000 | [diff] [blame] | 37 | import ColorDB |
Barry Warsaw | f7c1e5a | 1998-01-31 23:39:28 +0000 | [diff] [blame] | 38 | from PyncheWidget import PyncheWidget |
Barry Warsaw | 04c7886 | 1998-09-28 16:28:04 +0000 | [diff] [blame] | 39 | from Switchboard import Switchboard |
Barry Warsaw | 63c9e98 | 1998-09-28 23:41:53 +0000 | [diff] [blame] | 40 | from StripViewer import StripViewer |
Barry Warsaw | 4ab5d85 | 1998-10-01 16:47:06 +0000 | [diff] [blame] | 41 | from ChipViewer import ChipViewer |
| 42 | from TypeinViewer import TypeinViewer |
Barry Warsaw | f7c1e5a | 1998-01-31 23:39:28 +0000 | [diff] [blame] | 43 | |
| 44 | |
| 45 | |
| 46 | PROGRAM = sys.argv[0] |
| 47 | |
Barry Warsaw | f7c1e5a | 1998-01-31 23:39:28 +0000 | [diff] [blame] | 48 | # Default locations of rgb.txt or other textual color database |
| 49 | RGB_TXT = [ |
| 50 | # Solaris OpenWindows |
| 51 | '/usr/openwin/lib/rgb.txt', |
| 52 | # add more here |
| 53 | ] |
| 54 | |
| 55 | |
| 56 | |
| 57 | def usage(status, msg=''): |
Barry Warsaw | 14e2caf | 1998-10-06 15:21:04 +0000 | [diff] [blame^] | 58 | print __doc__ % globals() |
Barry Warsaw | f7c1e5a | 1998-01-31 23:39:28 +0000 | [diff] [blame] | 59 | if msg: |
| 60 | print msg |
Barry Warsaw | f7c1e5a | 1998-01-31 23:39:28 +0000 | [diff] [blame] | 61 | sys.exit(status) |
| 62 | |
| 63 | |
| 64 | |
Barry Warsaw | f7c1e5a | 1998-01-31 23:39:28 +0000 | [diff] [blame] | 65 | def main(): |
Barry Warsaw | f7c1e5a | 1998-01-31 23:39:28 +0000 | [diff] [blame] | 66 | try: |
Barry Warsaw | 04c7886 | 1998-09-28 16:28:04 +0000 | [diff] [blame] | 67 | opts, args = getopt.getopt( |
| 68 | sys.argv[1:], |
| 69 | 'hd:', |
| 70 | ['database=', 'help']) |
Barry Warsaw | f7c1e5a | 1998-01-31 23:39:28 +0000 | [diff] [blame] | 71 | except getopt.error, msg: |
| 72 | usage(1, msg) |
| 73 | |
Barry Warsaw | 04c7886 | 1998-09-28 16:28:04 +0000 | [diff] [blame] | 74 | if len(args) == 0: |
| 75 | initialcolor = 'grey50' |
| 76 | elif len(args) == 1: |
| 77 | initialcolor = args[0] |
| 78 | else: |
Barry Warsaw | f7c1e5a | 1998-01-31 23:39:28 +0000 | [diff] [blame] | 79 | usage(1) |
| 80 | |
| 81 | for opt, arg in opts: |
| 82 | if opt in ('-h', '--help'): |
| 83 | usage(0) |
Barry Warsaw | 04c7886 | 1998-09-28 16:28:04 +0000 | [diff] [blame] | 84 | elif opt in ('-d', '--database'): |
| 85 | RGB_TXT.insert(0, arg) |
Barry Warsaw | f7c1e5a | 1998-01-31 23:39:28 +0000 | [diff] [blame] | 86 | |
| 87 | # create the windows and go |
| 88 | for f in RGB_TXT: |
| 89 | try: |
| 90 | colordb = ColorDB.get_colordb(f) |
Barry Warsaw | 14e2caf | 1998-10-06 15:21:04 +0000 | [diff] [blame^] | 91 | if colordb: |
| 92 | break |
Barry Warsaw | f7c1e5a | 1998-01-31 23:39:28 +0000 | [diff] [blame] | 93 | except IOError: |
| 94 | pass |
| 95 | else: |
Barry Warsaw | 14e2caf | 1998-10-06 15:21:04 +0000 | [diff] [blame^] | 96 | usage(1, 'No color database file found, see the -d option.') |
Barry Warsaw | f7c1e5a | 1998-01-31 23:39:28 +0000 | [diff] [blame] | 97 | |
Barry Warsaw | eab81a9 | 1998-02-11 18:56:13 +0000 | [diff] [blame] | 98 | # get triplet for initial color |
| 99 | try: |
| 100 | red, green, blue = colordb.find_byname(initialcolor) |
| 101 | except ColorDB.BadColor: |
| 102 | # must be a #rrggbb style color |
| 103 | try: |
| 104 | red, green, blue = ColorDB.rrggbb_to_triplet(initialcolor) |
| 105 | except ColorDB.BadColor: |
Barry Warsaw | 04c7886 | 1998-09-28 16:28:04 +0000 | [diff] [blame] | 106 | print 'Bad initial color, using default: %s' % initialcolor |
| 107 | initialcolor = 'grey50' |
| 108 | try: |
| 109 | red, green, blue = ColorDB.rrggbb_to_triplet(initialcolor) |
| 110 | except ColorDB.BadColor: |
| 111 | usage(1, 'Cannot find an initial color to use') |
Barry Warsaw | eab81a9 | 1998-02-11 18:56:13 +0000 | [diff] [blame] | 112 | |
Barry Warsaw | 63c9e98 | 1998-09-28 23:41:53 +0000 | [diff] [blame] | 113 | # create all output widgets |
Barry Warsaw | 4ab5d85 | 1998-10-01 16:47:06 +0000 | [diff] [blame] | 114 | s = Switchboard(colordb) |
| 115 | |
| 116 | # create the application window decorations |
| 117 | app = PyncheWidget(__version__, s) |
| 118 | parent = app.parent() |
| 119 | |
Barry Warsaw | 63c9e98 | 1998-09-28 23:41:53 +0000 | [diff] [blame] | 120 | s.add_view(StripViewer(s, parent)) |
Barry Warsaw | 4ab5d85 | 1998-10-01 16:47:06 +0000 | [diff] [blame] | 121 | s.add_view(ChipViewer(s, parent)) |
| 122 | s.add_view(TypeinViewer(s, parent)) |
Barry Warsaw | 63c9e98 | 1998-09-28 23:41:53 +0000 | [diff] [blame] | 123 | s.update_views(red, green, blue) |
| 124 | |
Barry Warsaw | f7c1e5a | 1998-01-31 23:39:28 +0000 | [diff] [blame] | 125 | try: |
Barry Warsaw | 63c9e98 | 1998-09-28 23:41:53 +0000 | [diff] [blame] | 126 | app.start() |
Barry Warsaw | f7c1e5a | 1998-01-31 23:39:28 +0000 | [diff] [blame] | 127 | except KeyboardInterrupt: |
| 128 | pass |
| 129 | |
| 130 | |
| 131 | |
| 132 | if __name__ == '__main__': |
| 133 | main() |