summaryrefslogtreecommitdiffstats
path: root/Tools/pynche/PyncheWidget.py
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>1998-02-11 17:19:54 (GMT)
committerBarry Warsaw <barry@python.org>1998-02-11 17:19:54 (GMT)
commita6f591ac6b9b0393f2e7a3db7f3868888b5139b4 (patch)
tree88466a72692d53954afae30e657104eb10bd6698 /Tools/pynche/PyncheWidget.py
parentf4562a7a0a75f8d82304fe44a60daac425e829d5 (diff)
downloadcpython-a6f591ac6b9b0393f2e7a3db7f3868888b5139b4.zip
cpython-a6f591ac6b9b0393f2e7a3db7f3868888b5139b4.tar.gz
cpython-a6f591ac6b9b0393f2e7a3db7f3868888b5139b4.tar.bz2
Interface changes, delegate chaining, type in widget addition
Diffstat (limited to 'Tools/pynche/PyncheWidget.py')
-rw-r--r--Tools/pynche/PyncheWidget.py50
1 files changed, 37 insertions, 13 deletions
diff --git a/Tools/pynche/PyncheWidget.py b/Tools/pynche/PyncheWidget.py
index d40a6ed..b6bd8f7 100644
--- a/Tools/pynche/PyncheWidget.py
+++ b/Tools/pynche/PyncheWidget.py
@@ -5,13 +5,16 @@ from Tkinter import *
import Pmw
import ColorDB
from ChipWidget import ChipWidget
+from TypeinWidget import TypeinWidget
class PyncheWidget(Pmw.MegaWidget):
def __init__(self, colordb, parent=None, **kw):
self.__colordb = colordb
- optionsdefs = (('color', 'grey50', self.__set_color),)
- self.defineoptions(kw, optionsdefs)
+ options = (('color', (128, 128, 128), self.__set_color),
+ ('delegate', None, None),
+ )
+ self.defineoptions(kw, options)
# initialize base class -- after defining options
Pmw.MegaWidget.__init__(self, parent)
@@ -32,20 +35,41 @@ class PyncheWidget(Pmw.MegaWidget):
self.__nearest.grid(row=0, column=1)
# create the options window
- options = Pmw.Group(parent, tag_text='Options')
- options.pack(expand=YES, fill=BOTH)
+ group = Pmw.Group(parent, tag_text='Options')
+ group.pack(expand=YES, fill=BOTH)
+ self.__typein = TypeinWidget(group.interior())
+ self.__typein.grid()
# Check keywords and initialize options
self.initialiseoptions(PyncheWidget)
+ self.__typein.configure(delegate=self)
- def __set_color(self):
- color = self['color']
- try:
- red, green, blue, rrggbb = self.__colordb.find_byname(color)
- except ColorDB.BadColor:
- red, green, blue = ColorDB.rrggbb_to_triplet(color)
-
- nearest = self.__colordb.nearest(red, green, blue)
- self.__selected.configure(color=color)
+ #
+ # PUBLIC INTERFACE
+ #
+
+
+ def set_color(self, obj, rgbtuple):
+ print 'setting color to:', rgbtuple
+ nearest = self.__colordb.nearest(rgbtuple)
+ red, green, blue, rrggbb = self.__colordb.find_byname(nearest)
+ # for an exact match, use the color name
+ if (red, green, blue) == rgbtuple:
+ self.__selected.configure(color=nearest)
+ # otherwise, use the #rrggbb name
+ else:
+ rrggbb = ColorDB.triplet_to_rrggbb(rgbtuple)
+ self.__selected.configure(color=rrggbb)
self.__nearest.configure(color=nearest)
+ self.__typein.configure(color=rgbtuple)
+ delegate = self['delegate']
+ if delegate:
+ delegate.set_color(self, rgbtuple)
+
+ #
+ # PRIVATE INTERFACE
+ #
+
+ def __set_color(self):
+ self.set_color(self, self['color'])