From: Ned Konz Date: 2001-09-30T03:17:37+09:00 Subject: [ruby-talk:21828] Re: ruby-gtk and entry validation On Friday 21 September 2001 04:25 pm, Neil Conway wrote: > Hi, > > On Thu, 2001-09-20 at 19:24, Ned Konz wrote: > > The Gtk FAQ has an example of validating a Gtk::Entry field using an > > insert_text handler: > > > > [snip C code] > > > > The problem is that I can't find any way in ruby-gtk to do this. There is > > signal_handler_unblock in Gtk::Object but not > > signal_handler_unblock_by_func(). > > Okay, the reason you can't find those functions is because they're not > implemented ;-) > > It's a bit difficult to implement them properly because of the way that > signal handlers are implemented in Ruby/GTK: as (anonymous) blocks. This > is convenient, but it means that the programmer can't refer back to the > signal handler by name. I'm still thinking about how to do this. For > now, here's a simple work-around: signal_connect returns the connection > ID of the newly created signal handler. Then you can use the Gtk::Object > methods signal_handler_block() and signal_handler_unblock(), which take > the connection ID. I haven't tested it but AFAICT it should work. > > In the upcoming Ruby-GNOME 0.26, the missing functions will at least > call rb_notimplement() and bail out; if anyone can think of a way to > implement these functions nicely, let me know. Well, in this instance, all that's needed is a way to execute a block from the inside of a signal handler without causing recursion; that is, to temporarily disable that signal handler. If you could make method that would take a block and execute it with the current signal handler disabled (and/or perhaps with a different handler in scope), that would be useful for this idiom. So an example of entry validation could look something like this (set up for Glade): def insert_text_handler(entry, *a) entry.signal_handler_block_while { entry.insert_text(a[0].gsub(/\D/, '')) } end An example of using a different handler: def insert_text_handler(entry, *a) entry.signal_handler_block_while(&other_handler) { entry.insert_text(a[0].gsub(/\D/, '')) } end -- Ned Konz currently: Stanwood, WA email: ned@bike-nomad.com homepage: http://bike-nomad.com