11"""Pynche -- The PYthon Natural Color and Hue Editor.
22
3- Contact: Barry Warsaw
4- 3+ Contact: %(AUTHNAME)s
4+ Email: %(AUTHEMAIL)s
55Version: %(__version__)s
66
77Pynche is based largely on a similar color editor I wrote years ago for the
8- Sunview window system. That editor was called ICE: the Interactive Color
8+ SunView window system. That editor was called ICE: the Interactive Color
99Editor. I'd always wanted to port the editor to X but didn't feel like
1010hacking X and C code to do it. Fast forward many years, to where Python +
1111Tkinter provides such a nice programming environment, with enough power, that
1212I finally buckled down and implemented it. I changed the name because these
1313days, too many other systems have the acronym `ICE'.
1414
15- This program currently requires Python 1.5 with Tkinter. It has only been
16- tested on Solaris 2.6. Feedback is greatly appreciated. Send email to
17- 15+ This program currently requires Python 2.2 with Tkinter.
1816
1917Usage: %(PROGRAM)s [-d file] [-i file] [-X] [-v] [-h] [initialcolor]
2018
3836
3937 --version
4038 -v
41- print the version number
39+ print the version number and exit
4240
4341 --help
4442 -h
4846 initial color, as a color name or #RRGGBB format
4947"""
5048
51- __version__ = '1.3 '
49+ __version__ = '1.4 '
5250
5351import sys
5452import os
6462
6563
6664PROGRAM = sys .argv [0 ]
65+ AUTHNAME = 'Barry Warsaw'
66+ 6767
6868# Default locations of rgb.txt or other textual color database
6969RGB_TXT = [
@@ -120,25 +120,26 @@ def scan_color(s, colordb=colordb):
120120
121121
122122
123- def build (master = None , initialcolor = None , initfile = None , ignore = None ):
123+ def build (master = None , initialcolor = None , initfile = None , ignore = None ,
124+ dbfile = None ):
124125 # create all output widgets
125126 s = Switchboard (not ignore and initfile )
126-
127- # load the color database
128- colordb = None
129- try :
127+ # defer to the command line chosen color database, falling back to the one
128+ # in the .pynche file.
129+ if dbfile is None :
130130 dbfile = s .optiondb ()['DBFILE' ]
131- colordb = ColorDB .get_colordb (dbfile )
132- except (KeyError , IOError ):
133- # scoot through the files listed above to try to find a usable color
134- # database file
135- for f in RGB_TXT :
136- try :
137- colordb = ColorDB .get_colordb (f )
138- if colordb :
139- break
140- except IOError :
141- pass
131+ # find a parseable color database
132+ colordb = None
133+ files = RGB_TXT [:]
134+ while colordb is None :
135+ try :
136+ colordb = ColorDB .get_colordb (dbfile )
137+ except (KeyError , IOError ):
138+ pass
139+ if colordb is None :
140+ if not files :
141+ break
142+ dbfile = files .pop (0 )
142143 if not colordb :
143144 usage (1 , 'No color database file found, see the -d option.' )
144145 s .set_colordb (colordb )
@@ -153,7 +154,7 @@ def build(master=None, initialcolor=None, initfile=None, ignore=None):
153154 s .add_view (TypeinViewer (s , w ))
154155
155156 # get the initial color as components and set the color on all views. if
156- # there was no initial color given on the command line, use the one that's
157+ # there was no initial color given on the command line, use the one that's
157158 # stored in the option database
158159 if initialcolor is None :
159160 optiondb = s .optiondb ()
@@ -171,50 +172,52 @@ def build(master=None, initialcolor=None, initfile=None, ignore=None):
171172
172173def run (app , s ):
173174 try :
174- app .start ()
175+ app .start ()
175176 except KeyboardInterrupt :
176- pass
177+ pass
177178
178179
179180
180181def main ():
181182 try :
182- opts , args = getopt .getopt (
183+ opts , args = getopt .getopt (
183184 sys .argv [1 :],
184185 'hd:i:Xv' ,
185186 ['database=' , 'initfile=' , 'ignore' , 'help' , 'version' ])
186187 except getopt .error , msg :
187- usage (1 , msg )
188+ usage (1 , msg )
188189
189190 if len (args ) == 0 :
190191 initialcolor = None
191192 elif len (args ) == 1 :
192193 initialcolor = args [0 ]
193194 else :
194- usage (1 )
195+ usage (1 )
195196
196- ignore = 0
197+ ignore = False
198+ dbfile = None
197199 initfile = os .path .expanduser ('~/.pynche' )
198200 for opt , arg in opts :
199- if opt in ('-h' , '--help' ):
200- usage (0 )
201+ if opt in ('-h' , '--help' ):
202+ usage (0 )
201203 elif opt in ('-v' , '--version' ):
202- print ''' \
204+ print """ \
203205 Pynche -- The PYthon Natural Color and Hue Editor.
204- Contact: Barry Warsaw
205- 206- Version: %s''' % __version__
206+ Contact: %(AUTHNAME)s
207+ Email: %(AUTHEMAIL)s
208+ Version: %(__version__)s""" % globals ()
207209 sys .exit (0 )
208- elif opt in ('-d' , '--database' ):
209- RGB_TXT . insert ( 0 , arg )
210+ elif opt in ('-d' , '--database' ):
211+ dbfile = arg
210212 elif opt in ('-X' , '--ignore' ):
211- ignore = 1
213+ ignore = True
212214 elif opt in ('-i' , '--initfile' ):
213215 initfile = arg
214216
215217 app , sb = build (initialcolor = initialcolor ,
216218 initfile = initfile ,
217- ignore = ignore )
219+ ignore = ignore ,
220+ dbfile = dbfile )
218221 run (app , sb )
219222 sb .save_views ()
220223
0 commit comments