From: Morton Goldberg Date: 2006-09-06T04:00:45+09:00 Subject: Re: How to properly bind context menus to canvas in Ruby/Tk? On Sep 5, 2006, at 2:00 PM, Josef Wolf wrote: > On Tue, Sep 05, 2006 at 08:43:01PM +0900, Morton Goldberg wrote: > > Thanks for the reply, Morton! > >> I tried running your code on my system which is OS X 10.4.7 running >> Ruby 1.8.2, and I don't see what you report. What I see is following: >> >> * Right-clicking away from the the rectangle, the canvas' contextual >> menu pops-up. >> * Right-clicking on the rectangle. >> ** The rectangle's contextual menu pops-up. >> ** When the rectangle's menu is dismissed, the canvas' >> contextual menu pops-up. > > How do you "dismiss" the menu? Whatever I do, I never get the > second menu. By left clicking -- either on or off the menu. Which menu don't you get, the canvas' or the rect's? >> With a small tweak, I was able to keep the canvas' contextual menu >> from popping up when the the rectangle is right-clicked. So what I >> have now running on my system works as you expected. > > Your handled_by_rect flag seems to do the trick. But this would be a > global flag in my case since the menus are created from different > classes. :-( I would like to avoid such a global flag. WeLL, I try to avoid globals, too, but sometimes a global is the simplest solution. On the other hand you could create a class, say CanvasFlag, to manage the flag -- creating a class will solve most Ruby design problems ;) > The Tk::Bind manpage mentions that processing of matching callbacks > can > be controlled by "return" or calling "Tk->break" inside the callback. > That is, the rectangle's callback should call Tk->break. But none of > the involved classes seem to have a break method. And returning > false/true/nil/1/0 don't have any effect, too. Any ideas? I believe the Ruby/Tk equivalent is Tk.callback_break, but I don't think it will help here where we're dealing with an interaction between a bind and an itembind. Regards, Morton