mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
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.
This commit is contained in:
parent
04da10c7a2
commit
ca07ba00ac
10 changed files with 266 additions and 130 deletions
|
@ -103,6 +103,56 @@ def initial_color(s, colordb):
|
|||
return r, g, b
|
||||
|
||||
|
||||
|
||||
def build(master=None, initialcolor=None, initfile=None, ignore=None):
|
||||
# create the windows and go
|
||||
for f in RGB_TXT:
|
||||
try:
|
||||
colordb = ColorDB.get_colordb(f)
|
||||
if colordb:
|
||||
break
|
||||
except IOError:
|
||||
pass
|
||||
else:
|
||||
usage(1, 'No color database file found, see the -d option.')
|
||||
|
||||
# create all output widgets
|
||||
s = Switchboard(colordb, not ignore and initfile)
|
||||
|
||||
# create the application window decorations
|
||||
app = PyncheWidget(__version__, s, master=master)
|
||||
w = app.window()
|
||||
|
||||
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
|
||||
# stored in the option database
|
||||
if initialcolor is None:
|
||||
optiondb = s.optiondb()
|
||||
red = optiondb.get('RED')
|
||||
green = optiondb.get('GREEN')
|
||||
blue = optiondb.get('BLUE')
|
||||
# but if there wasn't any stored in the database, use grey50
|
||||
if red is None or blue is None or green is None:
|
||||
red, green, blue = initial_color('grey50', colordb)
|
||||
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()
|
||||
|
||||
|
||||
|
||||
def main():
|
||||
try:
|
||||
|
@ -132,51 +182,7 @@ def main():
|
|||
elif opt in ('-i', '--initfile'):
|
||||
initfile = arg
|
||||
|
||||
# create the windows and go
|
||||
for f in RGB_TXT:
|
||||
try:
|
||||
colordb = ColorDB.get_colordb(f)
|
||||
if colordb:
|
||||
break
|
||||
except IOError:
|
||||
pass
|
||||
else:
|
||||
usage(1, 'No color database file found, see the -d option.')
|
||||
|
||||
# create all output widgets
|
||||
s = Switchboard(colordb, not ignore and initfile)
|
||||
|
||||
# create the application window decorations
|
||||
app = PyncheWidget(__version__, s)
|
||||
parent = app.parent()
|
||||
|
||||
s.add_view(StripViewer(s, parent))
|
||||
s.add_view(ChipViewer(s, parent))
|
||||
s.add_view(TypeinViewer(s, parent))
|
||||
|
||||
# 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
|
||||
# stored in the option database
|
||||
if initialcolor is None:
|
||||
optiondb = s.optiondb()
|
||||
red = optiondb.get('RED')
|
||||
green = optiondb.get('GREEN')
|
||||
blue = optiondb.get('BLUE')
|
||||
# but if there wasn't any stored in the database, use grey50
|
||||
if red is None or blue is None or green is None:
|
||||
red, green, blue = initial_color('grey50', colordb)
|
||||
else:
|
||||
red, green, blue = initial_color(initialcolor, colordb)
|
||||
s.update_views(red, green, blue)
|
||||
|
||||
try:
|
||||
app.start()
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
|
||||
# save the option database
|
||||
s.save_views(initfile)
|
||||
|
||||
run()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue