diff options
author | Barry Warsaw <barry@python.org> | 1998-02-11 17:11:34 (GMT) |
---|---|---|
committer | Barry Warsaw <barry@python.org> | 1998-02-11 17:11:34 (GMT) |
commit | 4a445c689cfe271d28c446aec44f1803cae24a66 (patch) | |
tree | 2f0f9194097c8158d25c2dd10a2709594c7707e5 /Tools/pynche/TypeinViewer.py | |
parent | 5d8f0edc33d51266d8c4eb452ed3df60c3235a7b (diff) | |
download | cpython-4a445c689cfe271d28c446aec44f1803cae24a66.zip cpython-4a445c689cfe271d28c446aec44f1803cae24a66.tar.gz cpython-4a445c689cfe271d28c446aec44f1803cae24a66.tar.bz2 |
#Layout looks good, as does validation, and delegate chaining
Diffstat (limited to 'Tools/pynche/TypeinViewer.py')
-rw-r--r-- | Tools/pynche/TypeinViewer.py | 73 |
1 files changed, 44 insertions, 29 deletions
diff --git a/Tools/pynche/TypeinViewer.py b/Tools/pynche/TypeinViewer.py index 64ff9f3..d0033b4 100644 --- a/Tools/pynche/TypeinViewer.py +++ b/Tools/pynche/TypeinViewer.py @@ -1,10 +1,11 @@ from Tkinter import * import Pmw +import string class TypeinWidget(Pmw.MegaWidget): def __init__(self, parent=None, **kw): - options = (('delegate', None, None), - ('color', (128, 128, 128), self.__set_color), + options = (('color', (128, 128, 128), self.__set_color), + ('delegate', None, None), ) self.defineoptions(kw, options) @@ -16,8 +17,11 @@ class TypeinWidget(Pmw.MegaWidget): 'x', (), None, Pmw.EntryField, interiorarg, label_text='Red', - labelpos=E, + label_width=5, + label_anchor=E, + labelpos=W, maxwidth=4, + entry_width=4, validate=self.__validate, modifiedcommand=self.__modified) self.__x.grid(row=0, column=0) @@ -26,8 +30,11 @@ class TypeinWidget(Pmw.MegaWidget): 'y', (), None, Pmw.EntryField, interiorarg, label_text='Green', - labelpos=E, + label_width=5, + label_anchor=E, + labelpos=W, maxwidth=4, + entry_width=4, validate=self.__validate, modifiedcommand=self.__modified) self.__y.grid(row=1, column=0) @@ -36,35 +43,42 @@ class TypeinWidget(Pmw.MegaWidget): 'z', (), None, Pmw.EntryField, interiorarg, label_text='Blue', - labelpos=E, + label_width=5, + label_anchor=E, + labelpos=W, maxwidth=4, + entry_width=4, validate=self.__validate, modifiedcommand=self.__modified) self.__z.grid(row=2, column=0) - # TBD: gross hack, fix later - self.__initializing = 1 # Check keywords and initialize options self.initialiseoptions(TypeinWidget) - # TBD: gross hack, fix later - self.__initializing = 0 - # public set color interface - def set_color(self, red, green, blue): - self.__x.configure(label_text=`red`) - self.__y.configure(label_text=`green`) - self.__z.configure(label_text=`blue`) - # dispatch to the delegate - delegate = self['delegate'] - if delegate: - delegate.set_color(red, green, blue) - + # + # PUBLIC INTERFACE + # + + def set_color(self, obj, rgbtuple): + # break infloop + red, green, blue = rgbtuple + self.__x.setentry(`red`) + self.__y.setentry(`green`) + self.__z.setentry(`blue`) + if obj == self: + return + + # + # PRIVATE INTERFACE + # + # called to validate the entry text - SAFE_EVAL = {'__builtins__': {}} def __str_to_int(self, text): try: - val = eval(text, self.SAFE_EVAL, {}) - return val + if text[:2] == '0x': + return string.atoi(text[2:], 16) + else: + return string.atoi(text) except: return None @@ -78,13 +92,14 @@ class TypeinWidget(Pmw.MegaWidget): # called whenever a text entry is modified def __modified(self): # these are guaranteed to be valid, right? - red = self.__str_to_int(self.__x['value']) - green = self.__str_to_int(self.__y['value']) - blue = self.__str_to_int(self.__z['value']) - self.set_color(red, green, blue) + vals = map(lambda x: x.get(), (self.__x, self.__y, self.__z)) + rgbs = map(self.__str_to_int, vals) + valids = map(self.__validate, vals) + delegate = self['delegate'] + if None not in rgbs and -1 not in valids and delegate: + delegate.set_color(self, rgbs) # called whenever the color option is changed def __set_color(self): - red, green, blue = self['color'] - if not self.__initializing: - self.set_color(red, green, blue) + rgbtuple = self['color'] + self.set_color(self, rgbtuple) |