Mercurial > cpython-lru_cache-weakref
annotate Tools/pynche/Main.py @ 79675:c0a2294de787 2.7
Issue #16199: Backport 2to3 typo fix from 3.2.
| author | Chris Jerdonek <chris.jerdonek@gmail.com> |
|---|---|
| date | Thu, 11 Oct 2012 16:15:46 -0700 |
| parents | 646f0f11c519 |
| children | 6b18a095c2e7 |
| rev | line source |
|---|---|
| 9499 | 1 """Pynche -- The PYthon Natural Color and Hue Editor. |
| 2 | |
|
25876
5f7a334c0925
Some fixes based on feedback from Hans Petter Langtangen.
Barry Warsaw <barry@python.org>
parents:
19447
diff
changeset
|
3 Contact: %(AUTHNAME)s |
|
5f7a334c0925
Some fixes based on feedback from Hans Petter Langtangen.
Barry Warsaw <barry@python.org>
parents:
19447
diff
changeset
|
4 Email: %(AUTHEMAIL)s |
| 9499 | 5 Version: %(__version__)s |
| 7167 | 6 |
| 7 Pynche is based largely on a similar color editor I wrote years ago for the | |
|
25876
5f7a334c0925
Some fixes based on feedback from Hans Petter Langtangen.
Barry Warsaw <barry@python.org>
parents:
19447
diff
changeset
|
8 SunView window system. That editor was called ICE: the Interactive Color |
| 7167 | 9 Editor. I'd always wanted to port the editor to X but didn't feel like |
| 10 hacking X and C code to do it. Fast forward many years, to where Python + | |
| 9154 | 11 Tkinter provides such a nice programming environment, with enough power, that |
| 12 I finally buckled down and implemented it. I changed the name because these | |
| 13 days, too many other systems have the acronym `ICE'. | |
| 7167 | 14 |
|
25876
5f7a334c0925
Some fixes based on feedback from Hans Petter Langtangen.
Barry Warsaw <barry@python.org>
parents:
19447
diff
changeset
|
15 This program currently requires Python 2.2 with Tkinter. |
|
7184
6f78195bf8f6
Moved toplevel widget to PyncheWidget.py
Barry Warsaw <barry@python.org>
parents:
7167
diff
changeset
|
16 |
| 9499 | 17 Usage: %(PROGRAM)s [-d file] [-i file] [-X] [-v] [-h] [initialcolor] |
| 7167 | 18 |
| 19 Where: | |
| 9154 | 20 --database file |
| 21 -d file | |
| 22 Alternate location of a color database file | |
|
7241
b5985542bae1
Better conversion of command line given initial color
Barry Warsaw <barry@python.org>
parents:
7184
diff
changeset
|
23 |
|
9414
c03ffff387f8
Saving/Restoring state into ~/.pynche file
Barry Warsaw <barry@python.org>
parents:
9272
diff
changeset
|
24 --initfile file |
|
c03ffff387f8
Saving/Restoring state into ~/.pynche file
Barry Warsaw <barry@python.org>
parents:
9272
diff
changeset
|
25 -i file |
|
c03ffff387f8
Saving/Restoring state into ~/.pynche file
Barry Warsaw <barry@python.org>
parents:
9272
diff
changeset
|
26 Alternate location of the initialization file. This file contains a |
|
c03ffff387f8
Saving/Restoring state into ~/.pynche file
Barry Warsaw <barry@python.org>
parents:
9272
diff
changeset
|
27 persistent database of the current Pynche options and color. This |
|
c03ffff387f8
Saving/Restoring state into ~/.pynche file
Barry Warsaw <barry@python.org>
parents:
9272
diff
changeset
|
28 means that Pynche restores its option settings and current color when |
|
c03ffff387f8
Saving/Restoring state into ~/.pynche file
Barry Warsaw <barry@python.org>
parents:
9272
diff
changeset
|
29 it restarts, using this file (unless the -X option is used). The |
|
c03ffff387f8
Saving/Restoring state into ~/.pynche file
Barry Warsaw <barry@python.org>
parents:
9272
diff
changeset
|
30 default is ~/.pynche |
|
c03ffff387f8
Saving/Restoring state into ~/.pynche file
Barry Warsaw <barry@python.org>
parents:
9272
diff
changeset
|
31 |
|
c03ffff387f8
Saving/Restoring state into ~/.pynche file
Barry Warsaw <barry@python.org>
parents:
9272
diff
changeset
|
32 --ignore |
|
c03ffff387f8
Saving/Restoring state into ~/.pynche file
Barry Warsaw <barry@python.org>
parents:
9272
diff
changeset
|
33 -X |
|
c03ffff387f8
Saving/Restoring state into ~/.pynche file
Barry Warsaw <barry@python.org>
parents:
9272
diff
changeset
|
34 Ignore the initialization file when starting up. Pynche will still |
|
c03ffff387f8
Saving/Restoring state into ~/.pynche file
Barry Warsaw <barry@python.org>
parents:
9272
diff
changeset
|
35 write the current option settings to this file when it quits. |
|
c03ffff387f8
Saving/Restoring state into ~/.pynche file
Barry Warsaw <barry@python.org>
parents:
9272
diff
changeset
|
36 |
| 9499 | 37 --version |
| 38 -v | |
|
25876
5f7a334c0925
Some fixes based on feedback from Hans Petter Langtangen.
Barry Warsaw <barry@python.org>
parents:
19447
diff
changeset
|
39 print the version number and exit |
| 9499 | 40 |
| 7167 | 41 --help |
| 42 -h | |
| 43 print this message | |
| 44 | |
| 9154 | 45 initialcolor |
| 46 initial color, as a color name or #RRGGBB format | |
| 7167 | 47 """ |
| 48 | |
|
30293
646f0f11c519
Fix for SF bug #780996, crash when no .pynche file exists and -d
Barry Warsaw <barry@python.org>
parents:
25876
diff
changeset
|
49 __version__ = '1.4.1' |
| 7167 | 50 |
|
7184
6f78195bf8f6
Moved toplevel widget to PyncheWidget.py
Barry Warsaw <barry@python.org>
parents:
7167
diff
changeset
|
51 import sys |
|
9262
9d2c12f240e6
Added the rgb.txt file from X11R6.4, including the license
Barry Warsaw <barry@python.org>
parents:
9260
diff
changeset
|
52 import os |
|
7184
6f78195bf8f6
Moved toplevel widget to PyncheWidget.py
Barry Warsaw <barry@python.org>
parents:
7167
diff
changeset
|
53 import getopt |
|
6f78195bf8f6
Moved toplevel widget to PyncheWidget.py
Barry Warsaw <barry@python.org>
parents:
7167
diff
changeset
|
54 import ColorDB |
| 18459 | 55 |
|
7184
6f78195bf8f6
Moved toplevel widget to PyncheWidget.py
Barry Warsaw <barry@python.org>
parents:
7167
diff
changeset
|
56 from PyncheWidget import PyncheWidget |
| 9154 | 57 from Switchboard import Switchboard |
| 9167 | 58 from StripViewer import StripViewer |
| 9198 | 59 from ChipViewer import ChipViewer |
| 60 from TypeinViewer import TypeinViewer | |
|
7184
6f78195bf8f6
Moved toplevel widget to PyncheWidget.py
Barry Warsaw <barry@python.org>
parents:
7167
diff
changeset
|
61 |
|
6f78195bf8f6
Moved toplevel widget to PyncheWidget.py
Barry Warsaw <barry@python.org>
parents:
7167
diff
changeset
|
62 |
|
6f78195bf8f6
Moved toplevel widget to PyncheWidget.py
Barry Warsaw <barry@python.org>
parents:
7167
diff
changeset
|
63 |
|
6f78195bf8f6
Moved toplevel widget to PyncheWidget.py
Barry Warsaw <barry@python.org>
parents:
7167
diff
changeset
|
64 PROGRAM = sys.argv[0] |
|
25876
5f7a334c0925
Some fixes based on feedback from Hans Petter Langtangen.
Barry Warsaw <barry@python.org>
parents:
19447
diff
changeset
|
65 AUTHNAME = 'Barry Warsaw' |
|
5f7a334c0925
Some fixes based on feedback from Hans Petter Langtangen.
Barry Warsaw <barry@python.org>
parents:
19447
diff
changeset
|
66 AUTHEMAIL = 'barry@python.org' |
|
7184
6f78195bf8f6
Moved toplevel widget to PyncheWidget.py
Barry Warsaw <barry@python.org>
parents:
7167
diff
changeset
|
67 |
|
6f78195bf8f6
Moved toplevel widget to PyncheWidget.py
Barry Warsaw <barry@python.org>
parents:
7167
diff
changeset
|
68 # Default locations of rgb.txt or other textual color database |
|
6f78195bf8f6
Moved toplevel widget to PyncheWidget.py
Barry Warsaw <barry@python.org>
parents:
7167
diff
changeset
|
69 RGB_TXT = [ |
|
6f78195bf8f6
Moved toplevel widget to PyncheWidget.py
Barry Warsaw <barry@python.org>
parents:
7167
diff
changeset
|
70 # Solaris OpenWindows |
|
6f78195bf8f6
Moved toplevel widget to PyncheWidget.py
Barry Warsaw <barry@python.org>
parents:
7167
diff
changeset
|
71 '/usr/openwin/lib/rgb.txt', |
|
10722
f335fa1d6e71
Added /usr/lib/X11/rgb.txt in front of X/rgb.txt for Linuxers
Barry Warsaw <barry@python.org>
parents:
9637
diff
changeset
|
72 # Linux |
|
f335fa1d6e71
Added /usr/lib/X11/rgb.txt in front of X/rgb.txt for Linuxers
Barry Warsaw <barry@python.org>
parents:
9637
diff
changeset
|
73 '/usr/lib/X11/rgb.txt', |
|
9262
9d2c12f240e6
Added the rgb.txt file from X11R6.4, including the license
Barry Warsaw <barry@python.org>
parents:
9260
diff
changeset
|
74 # The X11R6.4 rgb.txt file |
|
9414
c03ffff387f8
Saving/Restoring state into ~/.pynche file
Barry Warsaw <barry@python.org>
parents:
9272
diff
changeset
|
75 os.path.join(sys.path[0], 'X/rgb.txt'), |
|
7184
6f78195bf8f6
Moved toplevel widget to PyncheWidget.py
Barry Warsaw <barry@python.org>
parents:
7167
diff
changeset
|
76 # add more here |
|
6f78195bf8f6
Moved toplevel widget to PyncheWidget.py
Barry Warsaw <barry@python.org>
parents:
7167
diff
changeset
|
77 ] |
|
6f78195bf8f6
Moved toplevel widget to PyncheWidget.py
Barry Warsaw <barry@python.org>
parents:
7167
diff
changeset
|
78 |
|
6f78195bf8f6
Moved toplevel widget to PyncheWidget.py
Barry Warsaw <barry@python.org>
parents:
7167
diff
changeset
|
79 |
|
6f78195bf8f6
Moved toplevel widget to PyncheWidget.py
Barry Warsaw <barry@python.org>
parents:
7167
diff
changeset
|
80 |
| 18459 | 81 # Do this because PyncheWidget.py wants to get at the interpolated docstring |
| 82 # too, for its Help menu. | |
|
9580
9a8ecd759e13
docstring(): Function for returning __doc__ % globals()
Barry Warsaw <barry@python.org>
parents:
9499
diff
changeset
|
83 def docstring(): |
| 18459 | 84 return __doc__ % globals() |
|
9580
9a8ecd759e13
docstring(): Function for returning __doc__ % globals()
Barry Warsaw <barry@python.org>
parents:
9499
diff
changeset
|
85 |
|
9a8ecd759e13
docstring(): Function for returning __doc__ % globals()
Barry Warsaw <barry@python.org>
parents:
9499
diff
changeset
|
86 |
| 18459 | 87 def usage(code, msg=''): |
|
9580
9a8ecd759e13
docstring(): Function for returning __doc__ % globals()
Barry Warsaw <barry@python.org>
parents:
9499
diff
changeset
|
88 print docstring() |
|
7184
6f78195bf8f6
Moved toplevel widget to PyncheWidget.py
Barry Warsaw <barry@python.org>
parents:
7167
diff
changeset
|
89 if msg: |
| 9499 | 90 print msg |
| 18459 | 91 sys.exit(code) |
|
7184
6f78195bf8f6
Moved toplevel widget to PyncheWidget.py
Barry Warsaw <barry@python.org>
parents:
7167
diff
changeset
|
92 |
|
6f78195bf8f6
Moved toplevel widget to PyncheWidget.py
Barry Warsaw <barry@python.org>
parents:
7167
diff
changeset
|
93 |
|
6f78195bf8f6
Moved toplevel widget to PyncheWidget.py
Barry Warsaw <barry@python.org>
parents:
7167
diff
changeset
|
94 |
|
9260
a73cd7f99b95
Better initial color choosing
Barry Warsaw <barry@python.org>
parents:
9250
diff
changeset
|
95 def initial_color(s, colordb): |
|
a73cd7f99b95
Better initial color choosing
Barry Warsaw <barry@python.org>
parents:
9250
diff
changeset
|
96 # function called on every color |
|
a73cd7f99b95
Better initial color choosing
Barry Warsaw <barry@python.org>
parents:
9250
diff
changeset
|
97 def scan_color(s, colordb=colordb): |
|
a73cd7f99b95
Better initial color choosing
Barry Warsaw <barry@python.org>
parents:
9250
diff
changeset
|
98 try: |
|
a73cd7f99b95
Better initial color choosing
Barry Warsaw <barry@python.org>
parents:
9250
diff
changeset
|
99 r, g, b = colordb.find_byname(s) |
|
a73cd7f99b95
Better initial color choosing
Barry Warsaw <barry@python.org>
parents:
9250
diff
changeset
|
100 except ColorDB.BadColor: |
|
a73cd7f99b95
Better initial color choosing
Barry Warsaw <barry@python.org>
parents:
9250
diff
changeset
|
101 try: |
|
a73cd7f99b95
Better initial color choosing
Barry Warsaw <barry@python.org>
parents:
9250
diff
changeset
|
102 r, g, b = ColorDB.rrggbb_to_triplet(s) |
|
a73cd7f99b95
Better initial color choosing
Barry Warsaw <barry@python.org>
parents:
9250
diff
changeset
|
103 except ColorDB.BadColor: |
|
a73cd7f99b95
Better initial color choosing
Barry Warsaw <barry@python.org>
parents:
9250
diff
changeset
|
104 return None, None, None |
|
a73cd7f99b95
Better initial color choosing
Barry Warsaw <barry@python.org>
parents:
9250
diff
changeset
|
105 return r, g, b |
|
a73cd7f99b95
Better initial color choosing
Barry Warsaw <barry@python.org>
parents:
9250
diff
changeset
|
106 # |
|
a73cd7f99b95
Better initial color choosing
Barry Warsaw <barry@python.org>
parents:
9250
diff
changeset
|
107 # First try the passed in color |
|
a73cd7f99b95
Better initial color choosing
Barry Warsaw <barry@python.org>
parents:
9250
diff
changeset
|
108 r, g, b = scan_color(s) |
|
a73cd7f99b95
Better initial color choosing
Barry Warsaw <barry@python.org>
parents:
9250
diff
changeset
|
109 if r is None: |
|
a73cd7f99b95
Better initial color choosing
Barry Warsaw <barry@python.org>
parents:
9250
diff
changeset
|
110 # try the same color with '#' prepended, since some shells require |
|
a73cd7f99b95
Better initial color choosing
Barry Warsaw <barry@python.org>
parents:
9250
diff
changeset
|
111 # this to be escaped, which is a pain |
|
a73cd7f99b95
Better initial color choosing
Barry Warsaw <barry@python.org>
parents:
9250
diff
changeset
|
112 r, g, b = scan_color('#' + s) |
|
a73cd7f99b95
Better initial color choosing
Barry Warsaw <barry@python.org>
parents:
9250
diff
changeset
|
113 if r is None: |
|
a73cd7f99b95
Better initial color choosing
Barry Warsaw <barry@python.org>
parents:
9250
diff
changeset
|
114 print 'Bad initial color, using gray50:', s |
|
a73cd7f99b95
Better initial color choosing
Barry Warsaw <barry@python.org>
parents:
9250
diff
changeset
|
115 r, g, b = scan_color('gray50') |
|
a73cd7f99b95
Better initial color choosing
Barry Warsaw <barry@python.org>
parents:
9250
diff
changeset
|
116 if r is None: |
|
a73cd7f99b95
Better initial color choosing
Barry Warsaw <barry@python.org>
parents:
9250
diff
changeset
|
117 usage(1, 'Cannot find an initial color to use') |
|
a73cd7f99b95
Better initial color choosing
Barry Warsaw <barry@python.org>
parents:
9250
diff
changeset
|
118 # does not return |
|
a73cd7f99b95
Better initial color choosing
Barry Warsaw <barry@python.org>
parents:
9250
diff
changeset
|
119 return r, g, b |
|
a73cd7f99b95
Better initial color choosing
Barry Warsaw <barry@python.org>
parents:
9250
diff
changeset
|
120 |
|
a73cd7f99b95
Better initial color choosing
Barry Warsaw <barry@python.org>
parents:
9250
diff
changeset
|
121 |
|
a73cd7f99b95
Better initial color choosing
Barry Warsaw <barry@python.org>
parents:
9250
diff
changeset
|
122 |
|
25876
5f7a334c0925
Some fixes based on feedback from Hans Petter Langtangen.
Barry Warsaw <barry@python.org>
parents:
19447
diff
changeset
|
123 def build(master=None, initialcolor=None, initfile=None, ignore=None, |
|
5f7a334c0925
Some fixes based on feedback from Hans Petter Langtangen.
Barry Warsaw <barry@python.org>
parents:
19447
diff
changeset
|
124 dbfile=None): |
|
10744
4c9de6fd267b
Lots of changes to support loading alternative color name database.
Barry Warsaw <barry@python.org>
parents:
10722
diff
changeset
|
125 # create all output widgets |
|
4c9de6fd267b
Lots of changes to support loading alternative color name database.
Barry Warsaw <barry@python.org>
parents:
10722
diff
changeset
|
126 s = Switchboard(not ignore and initfile) |
|
25876
5f7a334c0925
Some fixes based on feedback from Hans Petter Langtangen.
Barry Warsaw <barry@python.org>
parents:
19447
diff
changeset
|
127 # defer to the command line chosen color database, falling back to the one |
|
5f7a334c0925
Some fixes based on feedback from Hans Petter Langtangen.
Barry Warsaw <barry@python.org>
parents:
19447
diff
changeset
|
128 # in the .pynche file. |
|
5f7a334c0925
Some fixes based on feedback from Hans Petter Langtangen.
Barry Warsaw <barry@python.org>
parents:
19447
diff
changeset
|
129 if dbfile is None: |
|
30293
646f0f11c519
Fix for SF bug #780996, crash when no .pynche file exists and -d
Barry Warsaw <barry@python.org>
parents:
25876
diff
changeset
|
130 dbfile = s.optiondb().get('DBFILE') |
|
25876
5f7a334c0925
Some fixes based on feedback from Hans Petter Langtangen.
Barry Warsaw <barry@python.org>
parents:
19447
diff
changeset
|
131 # find a parseable color database |
|
5f7a334c0925
Some fixes based on feedback from Hans Petter Langtangen.
Barry Warsaw <barry@python.org>
parents:
19447
diff
changeset
|
132 colordb = None |
|
5f7a334c0925
Some fixes based on feedback from Hans Petter Langtangen.
Barry Warsaw <barry@python.org>
parents:
19447
diff
changeset
|
133 files = RGB_TXT[:] |
|
30293
646f0f11c519
Fix for SF bug #780996, crash when no .pynche file exists and -d
Barry Warsaw <barry@python.org>
parents:
25876
diff
changeset
|
134 if dbfile is None: |
|
646f0f11c519
Fix for SF bug #780996, crash when no .pynche file exists and -d
Barry Warsaw <barry@python.org>
parents:
25876
diff
changeset
|
135 dbfile = files.pop() |
|
25876
5f7a334c0925
Some fixes based on feedback from Hans Petter Langtangen.
Barry Warsaw <barry@python.org>
parents:
19447
diff
changeset
|
136 while colordb is None: |
|
5f7a334c0925
Some fixes based on feedback from Hans Petter Langtangen.
Barry Warsaw <barry@python.org>
parents:
19447
diff
changeset
|
137 try: |
|
5f7a334c0925
Some fixes based on feedback from Hans Petter Langtangen.
Barry Warsaw <barry@python.org>
parents:
19447
diff
changeset
|
138 colordb = ColorDB.get_colordb(dbfile) |
|
5f7a334c0925
Some fixes based on feedback from Hans Petter Langtangen.
Barry Warsaw <barry@python.org>
parents:
19447
diff
changeset
|
139 except (KeyError, IOError): |
|
5f7a334c0925
Some fixes based on feedback from Hans Petter Langtangen.
Barry Warsaw <barry@python.org>
parents:
19447
diff
changeset
|
140 pass |
|
5f7a334c0925
Some fixes based on feedback from Hans Petter Langtangen.
Barry Warsaw <barry@python.org>
parents:
19447
diff
changeset
|
141 if colordb is None: |
|
5f7a334c0925
Some fixes based on feedback from Hans Petter Langtangen.
Barry Warsaw <barry@python.org>
parents:
19447
diff
changeset
|
142 if not files: |
|
5f7a334c0925
Some fixes based on feedback from Hans Petter Langtangen.
Barry Warsaw <barry@python.org>
parents:
19447
diff
changeset
|
143 break |
|
5f7a334c0925
Some fixes based on feedback from Hans Petter Langtangen.
Barry Warsaw <barry@python.org>
parents:
19447
diff
changeset
|
144 dbfile = files.pop(0) |
|
10744
4c9de6fd267b
Lots of changes to support loading alternative color name database.
Barry Warsaw <barry@python.org>
parents:
10722
diff
changeset
|
145 if not colordb: |
|
9427
7567ef40de77
Many changes to support a second mode of operation. Pynche can now be
Barry Warsaw <barry@python.org>
parents:
9414
diff
changeset
|
146 usage(1, 'No color database file found, see the -d option.') |
|
10744
4c9de6fd267b
Lots of changes to support loading alternative color name database.
Barry Warsaw <barry@python.org>
parents:
10722
diff
changeset
|
147 s.set_colordb(colordb) |
|
9427
7567ef40de77
Many changes to support a second mode of operation. Pynche can now be
Barry Warsaw <barry@python.org>
parents:
9414
diff
changeset
|
148 |
|
7567ef40de77
Many changes to support a second mode of operation. Pynche can now be
Barry Warsaw <barry@python.org>
parents:
9414
diff
changeset
|
149 # create the application window decorations |
|
7567ef40de77
Many changes to support a second mode of operation. Pynche can now be
Barry Warsaw <barry@python.org>
parents:
9414
diff
changeset
|
150 app = PyncheWidget(__version__, s, master=master) |
|
7567ef40de77
Many changes to support a second mode of operation. Pynche can now be
Barry Warsaw <barry@python.org>
parents:
9414
diff
changeset
|
151 w = app.window() |
|
7567ef40de77
Many changes to support a second mode of operation. Pynche can now be
Barry Warsaw <barry@python.org>
parents:
9414
diff
changeset
|
152 |
| 10758 | 153 # these built-in viewers live inside the main Pynche window |
|
9427
7567ef40de77
Many changes to support a second mode of operation. Pynche can now be
Barry Warsaw <barry@python.org>
parents:
9414
diff
changeset
|
154 s.add_view(StripViewer(s, w)) |
|
7567ef40de77
Many changes to support a second mode of operation. Pynche can now be
Barry Warsaw <barry@python.org>
parents:
9414
diff
changeset
|
155 s.add_view(ChipViewer(s, w)) |
|
7567ef40de77
Many changes to support a second mode of operation. Pynche can now be
Barry Warsaw <barry@python.org>
parents:
9414
diff
changeset
|
156 s.add_view(TypeinViewer(s, w)) |
|
7567ef40de77
Many changes to support a second mode of operation. Pynche can now be
Barry Warsaw <barry@python.org>
parents:
9414
diff
changeset
|
157 |
|
7567ef40de77
Many changes to support a second mode of operation. Pynche can now be
Barry Warsaw <barry@python.org>
parents:
9414
diff
changeset
|
158 # get the initial color as components and set the color on all views. if |
|
25876
5f7a334c0925
Some fixes based on feedback from Hans Petter Langtangen.
Barry Warsaw <barry@python.org>
parents:
19447
diff
changeset
|
159 # there was no initial color given on the command line, use the one that's |
|
9427
7567ef40de77
Many changes to support a second mode of operation. Pynche can now be
Barry Warsaw <barry@python.org>
parents:
9414
diff
changeset
|
160 # stored in the option database |
|
7567ef40de77
Many changes to support a second mode of operation. Pynche can now be
Barry Warsaw <barry@python.org>
parents:
9414
diff
changeset
|
161 if initialcolor is None: |
|
7567ef40de77
Many changes to support a second mode of operation. Pynche can now be
Barry Warsaw <barry@python.org>
parents:
9414
diff
changeset
|
162 optiondb = s.optiondb() |
|
7567ef40de77
Many changes to support a second mode of operation. Pynche can now be
Barry Warsaw <barry@python.org>
parents:
9414
diff
changeset
|
163 red = optiondb.get('RED') |
|
7567ef40de77
Many changes to support a second mode of operation. Pynche can now be
Barry Warsaw <barry@python.org>
parents:
9414
diff
changeset
|
164 green = optiondb.get('GREEN') |
|
7567ef40de77
Many changes to support a second mode of operation. Pynche can now be
Barry Warsaw <barry@python.org>
parents:
9414
diff
changeset
|
165 blue = optiondb.get('BLUE') |
|
7567ef40de77
Many changes to support a second mode of operation. Pynche can now be
Barry Warsaw <barry@python.org>
parents:
9414
diff
changeset
|
166 # but if there wasn't any stored in the database, use grey50 |
|
7567ef40de77
Many changes to support a second mode of operation. Pynche can now be
Barry Warsaw <barry@python.org>
parents:
9414
diff
changeset
|
167 if red is None or blue is None or green is None: |
|
7567ef40de77
Many changes to support a second mode of operation. Pynche can now be
Barry Warsaw <barry@python.org>
parents:
9414
diff
changeset
|
168 red, green, blue = initial_color('grey50', colordb) |
|
7567ef40de77
Many changes to support a second mode of operation. Pynche can now be
Barry Warsaw <barry@python.org>
parents:
9414
diff
changeset
|
169 else: |
|
7567ef40de77
Many changes to support a second mode of operation. Pynche can now be
Barry Warsaw <barry@python.org>
parents:
9414
diff
changeset
|
170 red, green, blue = initial_color(initialcolor, colordb) |
|
7567ef40de77
Many changes to support a second mode of operation. Pynche can now be
Barry Warsaw <barry@python.org>
parents:
9414
diff
changeset
|
171 s.update_views(red, green, blue) |
|
7567ef40de77
Many changes to support a second mode of operation. Pynche can now be
Barry Warsaw <barry@python.org>
parents:
9414
diff
changeset
|
172 return app, s |
|
7567ef40de77
Many changes to support a second mode of operation. Pynche can now be
Barry Warsaw <barry@python.org>
parents:
9414
diff
changeset
|
173 |
|
7567ef40de77
Many changes to support a second mode of operation. Pynche can now be
Barry Warsaw <barry@python.org>
parents:
9414
diff
changeset
|
174 |
|
7567ef40de77
Many changes to support a second mode of operation. Pynche can now be
Barry Warsaw <barry@python.org>
parents:
9414
diff
changeset
|
175 def run(app, s): |
|
7567ef40de77
Many changes to support a second mode of operation. Pynche can now be
Barry Warsaw <barry@python.org>
parents:
9414
diff
changeset
|
176 try: |
|
25876
5f7a334c0925
Some fixes based on feedback from Hans Petter Langtangen.
Barry Warsaw <barry@python.org>
parents:
19447
diff
changeset
|
177 app.start() |
|
9427
7567ef40de77
Many changes to support a second mode of operation. Pynche can now be
Barry Warsaw <barry@python.org>
parents:
9414
diff
changeset
|
178 except KeyboardInterrupt: |
|
25876
5f7a334c0925
Some fixes based on feedback from Hans Petter Langtangen.
Barry Warsaw <barry@python.org>
parents:
19447
diff
changeset
|
179 pass |
|
9427
7567ef40de77
Many changes to support a second mode of operation. Pynche can now be
Barry Warsaw <barry@python.org>
parents:
9414
diff
changeset
|
180 |
|
7567ef40de77
Many changes to support a second mode of operation. Pynche can now be
Barry Warsaw <barry@python.org>
parents:
9414
diff
changeset
|
181 |
|
7567ef40de77
Many changes to support a second mode of operation. Pynche can now be
Barry Warsaw <barry@python.org>
parents:
9414
diff
changeset
|
182 |
|
7184
6f78195bf8f6
Moved toplevel widget to PyncheWidget.py
Barry Warsaw <barry@python.org>
parents:
7167
diff
changeset
|
183 def main(): |
|
6f78195bf8f6
Moved toplevel widget to PyncheWidget.py
Barry Warsaw <barry@python.org>
parents:
7167
diff
changeset
|
184 try: |
|
25876
5f7a334c0925
Some fixes based on feedback from Hans Petter Langtangen.
Barry Warsaw <barry@python.org>
parents:
19447
diff
changeset
|
185 opts, args = getopt.getopt( |
| 9154 | 186 sys.argv[1:], |
| 9499 | 187 'hd:i:Xv', |
| 188 ['database=', 'initfile=', 'ignore', 'help', 'version']) | |
|
7184
6f78195bf8f6
Moved toplevel widget to PyncheWidget.py
Barry Warsaw <barry@python.org>
parents:
7167
diff
changeset
|
189 except getopt.error, msg: |
|
25876
5f7a334c0925
Some fixes based on feedback from Hans Petter Langtangen.
Barry Warsaw <barry@python.org>
parents:
19447
diff
changeset
|
190 usage(1, msg) |
|
7184
6f78195bf8f6
Moved toplevel widget to PyncheWidget.py
Barry Warsaw <barry@python.org>
parents:
7167
diff
changeset
|
191 |
| 9154 | 192 if len(args) == 0: |
|
9414
c03ffff387f8
Saving/Restoring state into ~/.pynche file
Barry Warsaw <barry@python.org>
parents:
9272
diff
changeset
|
193 initialcolor = None |
| 9154 | 194 elif len(args) == 1: |
| 195 initialcolor = args[0] | |
| 196 else: | |
|
25876
5f7a334c0925
Some fixes based on feedback from Hans Petter Langtangen.
Barry Warsaw <barry@python.org>
parents:
19447
diff
changeset
|
197 usage(1) |
|
7184
6f78195bf8f6
Moved toplevel widget to PyncheWidget.py
Barry Warsaw <barry@python.org>
parents:
7167
diff
changeset
|
198 |
|
25876
5f7a334c0925
Some fixes based on feedback from Hans Petter Langtangen.
Barry Warsaw <barry@python.org>
parents:
19447
diff
changeset
|
199 ignore = False |
|
5f7a334c0925
Some fixes based on feedback from Hans Petter Langtangen.
Barry Warsaw <barry@python.org>
parents:
19447
diff
changeset
|
200 dbfile = None |
|
9414
c03ffff387f8
Saving/Restoring state into ~/.pynche file
Barry Warsaw <barry@python.org>
parents:
9272
diff
changeset
|
201 initfile = os.path.expanduser('~/.pynche') |
|
7184
6f78195bf8f6
Moved toplevel widget to PyncheWidget.py
Barry Warsaw <barry@python.org>
parents:
7167
diff
changeset
|
202 for opt, arg in opts: |
|
25876
5f7a334c0925
Some fixes based on feedback from Hans Petter Langtangen.
Barry Warsaw <barry@python.org>
parents:
19447
diff
changeset
|
203 if opt in ('-h', '--help'): |
|
5f7a334c0925
Some fixes based on feedback from Hans Petter Langtangen.
Barry Warsaw <barry@python.org>
parents:
19447
diff
changeset
|
204 usage(0) |
| 9499 | 205 elif opt in ('-v', '--version'): |
|
25876
5f7a334c0925
Some fixes based on feedback from Hans Petter Langtangen.
Barry Warsaw <barry@python.org>
parents:
19447
diff
changeset
|
206 print """\ |
| 9499 | 207 Pynche -- The PYthon Natural Color and Hue Editor. |
|
25876
5f7a334c0925
Some fixes based on feedback from Hans Petter Langtangen.
Barry Warsaw <barry@python.org>
parents:
19447
diff
changeset
|
208 Contact: %(AUTHNAME)s |
|
5f7a334c0925
Some fixes based on feedback from Hans Petter Langtangen.
Barry Warsaw <barry@python.org>
parents:
19447
diff
changeset
|
209 Email: %(AUTHEMAIL)s |
|
5f7a334c0925
Some fixes based on feedback from Hans Petter Langtangen.
Barry Warsaw <barry@python.org>
parents:
19447
diff
changeset
|
210 Version: %(__version__)s""" % globals() |
| 9499 | 211 sys.exit(0) |
|
25876
5f7a334c0925
Some fixes based on feedback from Hans Petter Langtangen.
Barry Warsaw <barry@python.org>
parents:
19447
diff
changeset
|
212 elif opt in ('-d', '--database'): |
|
5f7a334c0925
Some fixes based on feedback from Hans Petter Langtangen.
Barry Warsaw <barry@python.org>
parents:
19447
diff
changeset
|
213 dbfile = arg |
|
9414
c03ffff387f8
Saving/Restoring state into ~/.pynche file
Barry Warsaw <barry@python.org>
parents:
9272
diff
changeset
|
214 elif opt in ('-X', '--ignore'): |
|
25876
5f7a334c0925
Some fixes based on feedback from Hans Petter Langtangen.
Barry Warsaw <barry@python.org>
parents:
19447
diff
changeset
|
215 ignore = True |
|
9414
c03ffff387f8
Saving/Restoring state into ~/.pynche file
Barry Warsaw <barry@python.org>
parents:
9272
diff
changeset
|
216 elif opt in ('-i', '--initfile'): |
|
c03ffff387f8
Saving/Restoring state into ~/.pynche file
Barry Warsaw <barry@python.org>
parents:
9272
diff
changeset
|
217 initfile = arg |
|
7184
6f78195bf8f6
Moved toplevel widget to PyncheWidget.py
Barry Warsaw <barry@python.org>
parents:
7167
diff
changeset
|
218 |
|
9433
9ea5c42dcbed
Fixed running of standalone via command line. Also, only do save from
Barry Warsaw <barry@python.org>
parents:
9427
diff
changeset
|
219 app, sb = build(initialcolor=initialcolor, |
|
9ea5c42dcbed
Fixed running of standalone via command line. Also, only do save from
Barry Warsaw <barry@python.org>
parents:
9427
diff
changeset
|
220 initfile=initfile, |
|
25876
5f7a334c0925
Some fixes based on feedback from Hans Petter Langtangen.
Barry Warsaw <barry@python.org>
parents:
19447
diff
changeset
|
221 ignore=ignore, |
|
5f7a334c0925
Some fixes based on feedback from Hans Petter Langtangen.
Barry Warsaw <barry@python.org>
parents:
19447
diff
changeset
|
222 dbfile=dbfile) |
|
9433
9ea5c42dcbed
Fixed running of standalone via command line. Also, only do save from
Barry Warsaw <barry@python.org>
parents:
9427
diff
changeset
|
223 run(app, sb) |
|
9ea5c42dcbed
Fixed running of standalone via command line. Also, only do save from
Barry Warsaw <barry@python.org>
parents:
9427
diff
changeset
|
224 sb.save_views() |
|
7184
6f78195bf8f6
Moved toplevel widget to PyncheWidget.py
Barry Warsaw <barry@python.org>
parents:
7167
diff
changeset
|
225 |
| 18459 | 226 |
|
7184
6f78195bf8f6
Moved toplevel widget to PyncheWidget.py
Barry Warsaw <barry@python.org>
parents:
7167
diff
changeset
|
227 |
|
6f78195bf8f6
Moved toplevel widget to PyncheWidget.py
Barry Warsaw <barry@python.org>
parents:
7167
diff
changeset
|
228 if __name__ == '__main__': |
|
6f78195bf8f6
Moved toplevel widget to PyncheWidget.py
Barry Warsaw <barry@python.org>
parents:
7167
diff
changeset
|
229 main() |
