@@ -113,49 +113,49 @@ def __init__(self, parent=None, **kw):
113113 canvasheight = chipheight + 43 # TBD: Kludge
114114
115115 # create the canvas and pack it
116- self .__canvas = Canvas (
116+ canvas = self .__canvas = Canvas (
117117 parent ,
118118 width = canvaswidth ,
119119 height = canvasheight ,
120120## borderwidth=2,
121121## relief=GROOVE
122122 )
123123
124- self .__canvas .pack ()
125- self .__canvas .bind ('<ButtonRelease-1>' ,
126- self .__select_chip )
127- self .__canvas .bind ('<B1-Motion>' ,
128- self .__select_chip )
124+ canvas .pack ()
125+ canvas .bind ('<ButtonRelease-1>' , self .__select_chip )
126+ canvas .bind ('<B1-Motion>' , self .__select_chip )
129127
130128 # Load a proc into the Tcl interpreter. This is used in the
131129 # set_color() method to speed up setting the chip colors.
132- self . __canvas .tk .eval (TCLPROC )
130+ canvas .tk .eval (TCLPROC )
133131
134132 # create the color strip
135133 chips = self .__chips = []
136134 x = 1
137135 y = 30
136+ tags = ('chip' ,)
138137 for c in range (self .__numchips ):
139138 color = 'grey'
140- rect = self . __canvas .create_rectangle (
139+ rect = canvas .create_rectangle (
141140 x , y , x + chipwidth , y + chipheight ,
142- fill = color , outline = color )
141+ fill = color , outline = color ,
142+ tags = tags )
143143
144144 x = x + chipwidth + 1 # for outline
145145 chips .append (color )
146146
147147 # create the string tag
148- self .__label = self . __canvas .create_text (
148+ self .__label = canvas .create_text (
149149 3 , y + chipheight + 8 ,
150150 text = self ['label' ],
151151 anchor = W )
152152
153153 # create the arrow and text item
154154 chipx = self .__arrow_x (0 )
155- self .__leftarrow = LeftArrow (self . __canvas , chipx )
155+ self .__leftarrow = LeftArrow (canvas , chipx )
156156
157157 chipx = self .__arrow_x (len (chips ) - 1 )
158- self .__rightarrow = RightArrow (self . __canvas , chipx )
158+ self .__rightarrow = RightArrow (canvas , chipx )
159159
160160 self .__generator = self ['generator' ]
161161 self .__axis = self ['axis' ]
@@ -174,21 +174,25 @@ def __arrow_x(self, chipnum):
174174 return (x1 + x0 ) / 2.0
175175
176176 def __select_chip (self , event = None ):
177- chip = self .__canvas .find_closest (event .x , event .y )[0 ]
178- if chip and self .__delegate :
179- color = self .__chips [chip - 1 ]
180- rgbtuple = ColorDB .rrggbb_to_triplet (color )
181- self .__delegate .set_color (self , rgbtuple )
182-
183- ## import profile
184- ## import pstats
185- ## import tempfile
186- ## statfile = tempfile.mktemp()
187- ## p = profile.Profile()
188- ## p.runcall(self.__delegate.set_color, self, rgbtuple)
189- ## p.dump_stats(statfile)
190- ## s = pstats.Stats(statfile)
191- ## s.strip_dirs().sort_stats('time').print_stats(10)
177+ if self .__delegate :
178+ x = event .x
179+ y = event .y
180+ canvas = self .__canvas
181+ chip = canvas .find_overlapping (x , y , x , y )
182+ if chip and (1 <= chip [0 ] <= self .__numchips ):
183+ color = self .__chips [chip [0 ]- 1 ]
184+ rgbtuple = ColorDB .rrggbb_to_triplet (color )
185+
186+ self .__delegate .set_color (self , rgbtuple )
187+ ## import profile
188+ ## import pstats
189+ ## import tempfile
190+ ## statfile = tempfile.mktemp()
191+ ## p = profile.Profile()
192+ ## p.runcall(self.__delegate.set_color, self, rgbtuple)
193+ ## p.dump_stats(statfile)
194+ ## s = pstats.Stats(statfile)
195+ ## s.strip_dirs().sort_stats('time').print_stats(10)
192196
193197 def __set_delegate (self ):
194198 self .__delegate = self ['delegate' ]
0 commit comments