Commit 680ca08c authored by Barry Warsaw's avatar Barry Warsaw

Some fixes based on feedback from Hans Petter Langtangen.

build(): Fix the logic here for calculating fallbacks if the dbfile
isn't parseable.

main(): Fix the semantics for -d/--database; this should override any
database value found in the .pynche file.

Update some comments, and author contact info.

Bump to v1.4

Whitespace normalization.
parent 83dc2327
"""Pynche -- The PYthon Natural Color and Hue Editor. """Pynche -- The PYthon Natural Color and Hue Editor.
Contact: Barry Warsaw Contact: %(AUTHNAME)s
Email: bwarsaw@python.org Email: %(AUTHEMAIL)s
Version: %(__version__)s Version: %(__version__)s
Pynche is based largely on a similar color editor I wrote years ago for the Pynche is based largely on a similar color editor I wrote years ago for the
Sunview window system. That editor was called ICE: the Interactive Color SunView window system. That editor was called ICE: the Interactive Color
Editor. I'd always wanted to port the editor to X but didn't feel like Editor. I'd always wanted to port the editor to X but didn't feel like
hacking X and C code to do it. Fast forward many years, to where Python + hacking X and C code to do it. Fast forward many years, to where Python +
Tkinter provides such a nice programming environment, with enough power, that Tkinter provides such a nice programming environment, with enough power, that
I finally buckled down and implemented it. I changed the name because these I finally buckled down and implemented it. I changed the name because these
days, too many other systems have the acronym `ICE'. days, too many other systems have the acronym `ICE'.
This program currently requires Python 1.5 with Tkinter. It has only been This program currently requires Python 2.2 with Tkinter.
tested on Solaris 2.6. Feedback is greatly appreciated. Send email to
bwarsaw@python.org
Usage: %(PROGRAM)s [-d file] [-i file] [-X] [-v] [-h] [initialcolor] Usage: %(PROGRAM)s [-d file] [-i file] [-X] [-v] [-h] [initialcolor]
...@@ -38,7 +36,7 @@ Where: ...@@ -38,7 +36,7 @@ Where:
--version --version
-v -v
print the version number print the version number and exit
--help --help
-h -h
...@@ -48,7 +46,7 @@ Where: ...@@ -48,7 +46,7 @@ Where:
initial color, as a color name or #RRGGBB format initial color, as a color name or #RRGGBB format
""" """
__version__ = '1.3' __version__ = '1.4'
import sys import sys
import os import os
...@@ -64,6 +62,8 @@ from TypeinViewer import TypeinViewer ...@@ -64,6 +62,8 @@ from TypeinViewer import TypeinViewer
PROGRAM = sys.argv[0] PROGRAM = sys.argv[0]
AUTHNAME = 'Barry Warsaw'
AUTHEMAIL = 'barry@python.org'
# Default locations of rgb.txt or other textual color database # Default locations of rgb.txt or other textual color database
RGB_TXT = [ RGB_TXT = [
...@@ -120,25 +120,26 @@ def initial_color(s, colordb): ...@@ -120,25 +120,26 @@ def initial_color(s, colordb):
def build(master=None, initialcolor=None, initfile=None, ignore=None): def build(master=None, initialcolor=None, initfile=None, ignore=None,
dbfile=None):
# create all output widgets # create all output widgets
s = Switchboard(not ignore and initfile) s = Switchboard(not ignore and initfile)
# defer to the command line chosen color database, falling back to the one
# load the color database # in the .pynche file.
colordb = None if dbfile is None:
try:
dbfile = s.optiondb()['DBFILE'] dbfile = s.optiondb()['DBFILE']
colordb = ColorDB.get_colordb(dbfile) # find a parseable color database
except (KeyError, IOError): colordb = None
# scoot through the files listed above to try to find a usable color files = RGB_TXT[:]
# database file while colordb is None:
for f in RGB_TXT: try:
try: colordb = ColorDB.get_colordb(dbfile)
colordb = ColorDB.get_colordb(f) except (KeyError, IOError):
if colordb: pass
break if colordb is None:
except IOError: if not files:
pass break
dbfile = files.pop(0)
if not colordb: if not colordb:
usage(1, 'No color database file found, see the -d option.') usage(1, 'No color database file found, see the -d option.')
s.set_colordb(colordb) s.set_colordb(colordb)
...@@ -153,7 +154,7 @@ def build(master=None, initialcolor=None, initfile=None, ignore=None): ...@@ -153,7 +154,7 @@ def build(master=None, initialcolor=None, initfile=None, ignore=None):
s.add_view(TypeinViewer(s, w)) s.add_view(TypeinViewer(s, w))
# get the initial color as components and set the color on all views. if # get the initial color as components and set the color on all views. if
# there was no initial color given on the command line, use the one that's # there was no initial color given on the command line, use the one that's
# stored in the option database # stored in the option database
if initialcolor is None: if initialcolor is None:
optiondb = s.optiondb() optiondb = s.optiondb()
...@@ -171,50 +172,52 @@ def build(master=None, initialcolor=None, initfile=None, ignore=None): ...@@ -171,50 +172,52 @@ def build(master=None, initialcolor=None, initfile=None, ignore=None):
def run(app, s): def run(app, s):
try: try:
app.start() app.start()
except KeyboardInterrupt: except KeyboardInterrupt:
pass pass
def main(): def main():
try: try:
opts, args = getopt.getopt( opts, args = getopt.getopt(
sys.argv[1:], sys.argv[1:],
'hd:i:Xv', 'hd:i:Xv',
['database=', 'initfile=', 'ignore', 'help', 'version']) ['database=', 'initfile=', 'ignore', 'help', 'version'])
except getopt.error, msg: except getopt.error, msg:
usage(1, msg) usage(1, msg)
if len(args) == 0: if len(args) == 0:
initialcolor = None initialcolor = None
elif len(args) == 1: elif len(args) == 1:
initialcolor = args[0] initialcolor = args[0]
else: else:
usage(1) usage(1)
ignore = 0 ignore = False
dbfile = None
initfile = os.path.expanduser('~/.pynche') initfile = os.path.expanduser('~/.pynche')
for opt, arg in opts: for opt, arg in opts:
if opt in ('-h', '--help'): if opt in ('-h', '--help'):
usage(0) usage(0)
elif opt in ('-v', '--version'): elif opt in ('-v', '--version'):
print '''\ print """\
Pynche -- The PYthon Natural Color and Hue Editor. Pynche -- The PYthon Natural Color and Hue Editor.
Contact: Barry Warsaw Contact: %(AUTHNAME)s
Email: bwarsaw@python.org Email: %(AUTHEMAIL)s
Version: %s''' % __version__ Version: %(__version__)s""" % globals()
sys.exit(0) sys.exit(0)
elif opt in ('-d', '--database'): elif opt in ('-d', '--database'):
RGB_TXT.insert(0, arg) dbfile = arg
elif opt in ('-X', '--ignore'): elif opt in ('-X', '--ignore'):
ignore = 1 ignore = True
elif opt in ('-i', '--initfile'): elif opt in ('-i', '--initfile'):
initfile = arg initfile = arg
app, sb = build(initialcolor=initialcolor, app, sb = build(initialcolor=initialcolor,
initfile=initfile, initfile=initfile,
ignore=ignore) ignore=ignore,
dbfile=dbfile)
run(app, sb) run(app, sb)
sb.save_views() sb.save_views()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment