diff options
author | Barry Warsaw <barry@python.org> | 1998-10-22 18:51:22 (GMT) |
---|---|---|
committer | Barry Warsaw <barry@python.org> | 1998-10-22 18:51:22 (GMT) |
commit | 2be858230a1253b773a7e0d004ac84fae785d8b9 (patch) | |
tree | 72f11361d9baeebf24f0afdf9e15d4c69407a94b /Tools | |
parent | f72d580d5e7759fd75ab18c238f851cadba248b3 (diff) | |
download | cpython-2be858230a1253b773a7e0d004ac84fae785d8b9.zip cpython-2be858230a1253b773a7e0d004ac84fae785d8b9.tar.gz cpython-2be858230a1253b773a7e0d004ac84fae785d8b9.tar.bz2 |
__init__(): Removed initialcolor keyword.
show(): added color keyword here so that the selected color can be
chosen on each invocation of askcolor().
Also fixed this class, and askcolor() so that the same Chooser
instance can be re-used instead of creating a new one on each
invocation of askcolor().
Added a module function save() which can be used to explicitly save
the option database in ~/.pynche. This does not happen automatically
when used as a modal.
Diffstat (limited to 'Tools')
-rw-r--r-- | Tools/pynche/pyColorChooser.py | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/Tools/pynche/pyColorChooser.py b/Tools/pynche/pyColorChooser.py index 94ba5d6..1eb0e5f 100644 --- a/Tools/pynche/pyColorChooser.py +++ b/Tools/pynche/pyColorChooser.py @@ -10,33 +10,41 @@ class Chooser: """Ask for a color""" def __init__(self, master = None, - initialcolor = None, databasefile = None, initfile = None, ignore = None, wantspec = None): self.__master = master - self.__initialcolor = initialcolor self.__databasefile = databasefile self.__initfile = initfile or os.path.expanduser('~/.pynche') self.__ignore = ignore self.__pw = None self.__wantspec = wantspec - def show(self): + def show(self, color=None): + if not self.__master: + from Tkinter import Tk + self.__master = Tk() if not self.__pw: self.__pw, self.__sb = \ Main.build(master = self.__master, - initialcolor = self.__initialcolor, initfile = self.__initfile, ignore = self.__ignore) + else: + self.__pw.deiconify() + # convert color + colordb = self.__sb.colordb() + if color: + r, g, b = Main.initial_color(color, colordb) + self.__sb.update_views(r, g, b) + # reset the canceled flag and run it + self.__sb.canceled(0) Main.run(self.__pw, self.__sb) rgbtuple = self.__sb.current_rgb() self.__pw.withdraw() # check to see if the cancel button was pushed if self.__sb.canceled_p(): return None, None - colordb = self.__sb.colordb() # try to return the color name from the database if there is an exact # match, otherwise use the "#rrggbb" spec. TBD: Forget about color # aliases for now, maybe later we should return these too. @@ -50,13 +58,25 @@ class Chooser: name = ColorDB.triplet_to_rrggbb(rgbtuple) return rgbtuple, name + def save(self): + if self.__sb: + self.__sb.save_views() # convenience stuff +_chooser = None + def askcolor(color = None, **options): """Ask for a color""" - return apply(Chooser, (), options).show() + global _chooser + if not _chooser: + _chooser = apply(Chooser, (), options) + return _chooser.show(color) +def save(): + global _chooser + if _chooser: + _chooser.save() # test stuff |