From: Hidetoshi NAGAI Date: 2006-07-29T07:03:36+09:00 Subject: Re: Ruby::Tk on OS X event binding hint From: Morton Goldberg Subject: Re: Ruby::Tk on OS X event binding hint Date: Sat, 29 Jul 2006 04:58:52 +0900 Message-ID: > > It will not work on other toplevel widgets. > > The following may be better. > > ---------------------------------------- > > ev = TkVirtualEvent.new > > ev.add('Command-q') > > ev.add('Command-Shift-q') ### or ev.add('Command-q', 'Command-Shift- > > q') > > TkBindTag::ALL.bind(ev){exit} > > ---------------------------------------- > > Are you saying that, when my code runs, Command-q keystroke events > will trigger the callback only when the main window (Tk.root) is the > active window? Or is the problem that I've used two calls to bind > when I should have used just one? Or is it something else? I'm sorry if I misunderstanded your post. When your application has two or more windows, your binding will work on the root widget (or widgets on the root widget) only. Of course, you are right if that is what you want. The bindtags list of the widget on the other toplevel widget doesn't include the root widget. Please see Tcl/Tk's manual of `bindtags'. > > ev = TkVirtualEvent.new > > ev.add('Button-2', 'Control-Button-1') > > Tk.root.bind(ev){|e| info_mnu.popup(e.root_x, e.root_y)} > > Again I ask for further explanation: What problem arises with the > original code that you are fixing? (My code seems to be working with > no problems in my application, but that app has only one window.) In > this case it looks as if the two separate calls to bind are what > bother you. "Don't Repeat Yourself" to prevent bugs. ;-) If the part (and events for the callback) never change in the life cycle of your software, it has no problem. -- Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)