|
10 | 10 | power, that I finally buckled down and implemented it. I changed the name |
11 | 11 | because these days, too many other systems have the acronym `ICE'. |
12 | 12 |
|
13 | | -Usage: %(PROGRAM) [-h] |
| 13 | +This program currently requires Python 1.5 with Tkinter. It also requires at |
| 14 | +least Pmw 0.6.1. It has only been tested on Solaris 2.6. Feedback is greatly |
| 15 | +appreciated. Send email to [email protected] |
| 16 | +
|
| 17 | +Usage: %(PROGRAM)s [-h] |
14 | 18 |
|
15 | 19 | Where: |
16 | 20 | --help |
|
21 | 25 |
|
22 | 26 | __version__ = '1.0' |
23 | 27 |
|
| 28 | +import sys |
| 29 | +import getopt |
| 30 | +import Pmw |
| 31 | +import ColorDB |
| 32 | +from Tkinter import * |
| 33 | +from PyncheWidget import PyncheWidget |
| 34 | + |
| 35 | + |
| 36 | + |
| 37 | +PROGRAM = sys.argv[0] |
| 38 | + |
| 39 | +# Milliseconds between interrupt checks |
| 40 | +KEEPALIVE_TIMER = 500 |
| 41 | + |
| 42 | +RGBCOLOR = 1 |
| 43 | +HSICOLOR = 2 |
| 44 | +NAMEDCOLOR = 3 |
| 45 | + |
| 46 | +# Default locations of rgb.txt or other textual color database |
| 47 | +RGB_TXT = [ |
| 48 | + # Solaris OpenWindows |
| 49 | + '/usr/openwin/lib/rgb.txt', |
| 50 | + # add more here |
| 51 | + ] |
| 52 | + |
| 53 | + |
| 54 | + |
| 55 | +def usage(status, msg=''): |
| 56 | + if msg: |
| 57 | + print msg |
| 58 | + print __doc__ % globals() |
| 59 | + sys.exit(status) |
| 60 | + |
| 61 | + |
| 62 | + |
| 63 | +app = None |
| 64 | + |
| 65 | +def keepalive(): |
| 66 | + # Exercise the Python interpreter regularly so keybard interrupts get |
| 67 | + # through. |
| 68 | + app.tk.createtimerhandler(KEEPALIVE_TIMER, keepalive) |
| 69 | + |
| 70 | + |
| 71 | +def 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 | + |
| 113 | +if __name__ == '__main__': |
| 114 | + main() |
0 commit comments