diff options
author | Barry Warsaw <barry@python.org> | 1998-10-22 03:25:59 (GMT) |
---|---|---|
committer | Barry Warsaw <barry@python.org> | 1998-10-22 03:25:59 (GMT) |
commit | ca07ba00acdd020e0c179277ed829a8ce1664245 (patch) | |
tree | 03ddbed7626ca441d4c90d599b2028773f8e298c /Tools/pynche/Main.py | |
parent | 04da10c7a2fa0bd060e8052a9fe3d47623324b94 (diff) | |
download | cpython-ca07ba00acdd020e0c179277ed829a8ce1664245.zip cpython-ca07ba00acdd020e0c179277ed829a8ce1664245.tar.gz cpython-ca07ba00acdd020e0c179277ed829a8ce1664245.tar.bz2 |
Many changes to support a second mode of operation. Pynche can now be
run either as a standalone application (by running pynche or
pynche.pyw), or as a modal dialog inside another application. This
can be done by importing pyColorChooser and running askcolor(). The
API for this is the same as the tkColorChooser.askcolor() API, namely:
When `Okay' is hit, askcolor() returns ((r, g, b), "name"). When
`Cancel' is hit, askcolor() returns (None, None).
Note the following differences:
1. pyColorChooser.askcolor() takes an optional keyword `master'
which if set tells Pynche to run as a modal dialog. `master'
is a Tkinter parent window. Without the `master' keyword
Pynche runs standalone.
2. in pyColorChooser.askcolor() will return a Tk/X11 color name as
"name" if there is an exact match, otherwise it will return a
color spec, e.g. "#rrggbb". tkColorChooser can't return a
color name.
There are also some UI differences when running standalone vs. modal.
When modal, there is no "File" menu, but instead there are "Okay" and
"Cancel" buttons.
The implementation of all this is a bit of a hack, but it seems to
work moderately well. I'm not guaranteeing the pyColorChooser.Chooser
class has the same semantics as the tkColorChooser.Chooser class.
Diffstat (limited to 'Tools/pynche/Main.py')
-rw-r--r-- | Tools/pynche/Main.py | 76 |
1 files changed, 41 insertions, 35 deletions
diff --git a/Tools/pynche/Main.py b/Tools/pynche/Main.py index bb5329e..f266a8d 100644 --- a/Tools/pynche/Main.py +++ b/Tools/pynche/Main.py @@ -104,34 +104,7 @@ def initial_color(s, colordb): -def main(): - try: - opts, args = getopt.getopt( - sys.argv[1:], - 'hd:i:X', - ['database=', 'initfile=', 'ignore', 'help']) - except getopt.error, msg: - usage(1, msg) - - if len(args) == 0: - initialcolor = None - elif len(args) == 1: - initialcolor = args[0] - else: - usage(1) - - ignore = 0 - initfile = os.path.expanduser('~/.pynche') - for opt, arg in opts: - if opt in ('-h', '--help'): - usage(0) - elif opt in ('-d', '--database'): - RGB_TXT.insert(0, arg) - elif opt in ('-X', '--ignore'): - ignore = 1 - elif opt in ('-i', '--initfile'): - initfile = arg - +def build(master=None, initialcolor=None, initfile=None, ignore=None): # create the windows and go for f in RGB_TXT: try: @@ -147,12 +120,12 @@ def main(): s = Switchboard(colordb, not ignore and initfile) # create the application window decorations - app = PyncheWidget(__version__, s) - parent = app.parent() + app = PyncheWidget(__version__, s, master=master) + w = app.window() - s.add_view(StripViewer(s, parent)) - s.add_view(ChipViewer(s, parent)) - s.add_view(TypeinViewer(s, parent)) + s.add_view(StripViewer(s, w)) + s.add_view(ChipViewer(s, w)) + s.add_view(TypeinViewer(s, w)) # 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 @@ -168,15 +141,48 @@ def main(): else: red, green, blue = initial_color(initialcolor, colordb) s.update_views(red, green, blue) + return app, s + +def run(app, s): try: app.start() except KeyboardInterrupt: pass - # save the option database - s.save_views(initfile) + s.save_views() + + + +def main(): + try: + opts, args = getopt.getopt( + sys.argv[1:], + 'hd:i:X', + ['database=', 'initfile=', 'ignore', 'help']) + except getopt.error, msg: + usage(1, msg) + + if len(args) == 0: + initialcolor = None + elif len(args) == 1: + initialcolor = args[0] + else: + usage(1) + + ignore = 0 + initfile = os.path.expanduser('~/.pynche') + for opt, arg in opts: + if opt in ('-h', '--help'): + usage(0) + elif opt in ('-d', '--database'): + RGB_TXT.insert(0, arg) + elif opt in ('-X', '--ignore'): + ignore = 1 + elif opt in ('-i', '--initfile'): + initfile = arg + run() if __name__ == '__main__': |