From: Hidetoshi NAGAI Date: 2005-05-24T17:56:34+09:00 Subject: Re: Tk read-only text box From: nornagon Subject: Re: Tk read-only text box Date: Tue, 24 May 2005 15:40:25 +0900 Message-ID: <14d61533050523234070e4f92a@mail.gmail.com> > > For example, > > --------------------------------------------------- > > require 'tk' > > t = TkText.new.pack > > t.bindtags_unshift(b = TkBindTag.new) > > b.bind('Key', proc{ Tk.callback_break }) > > > > t.insert(:end, "This is a test message.\n"); > > > > Tk.after(10000){t.insert(:end, "This is another test message.\n")} > > > > Tk.mainloop > > --------------------------------------------------- > > Interesting. Could you tell me how that works, exactly? Like, what's > bindtags_unshift do? What's a BindTag, even? Each widget has a bindtag list to determine bindings which should be appleid. The default value of the list is [, , , 'all']. When an event occurs on the widget, one or none of the procedures binded to each bindtag is called. Of course, the event sequence of the binding has to matche the event. Usually, the calling process is done in order of the bindtag list. Tk.callback_break can break the sequence and complete the operation for the event. You can get/set the bindtag list by bindtags/bindtags= method. And can add a new bindtag to the head of the list by bindtags_unshift method (remove the head by bindtags_shift method). If you remove from a bindtag list of a widget, the widget lose all bindings of the widget class. If add again, the widget gets the bindings of the widget class again. Well, in the example case, a new bindtag is inserted at head of the bindtag list of the text widget. The bindtag has a binding for all "Key" events. And the binding is "Tk.callback_break", that is, "finish the operation for the event". The operataion "insert a key-pressed character" is one of the bindings for a kind of "Key" event. And it is binded on , that is, "TkText". However, on the example, all kind of "Key" events are blocked on the new bindtag and aren't checked on "TkText" tag. So, keyboard events cannot change the text widget. # The reason of why don't remove "TkText" tag is to be able to accept # mouse events. -- Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)