Adding a handler proc after the fact to GladeXML


I need to be able to set a handler after Is this possible?

Instead of this:
@glade =, root, domain,localedir,
flag) {|handler| method(handler)}

I’d like to do this:
@glade =, root, domain,localedir, flag)

@glade.handler_proc = {|handler| method(handler)}

Or even

my_handler = {|handler| method(handler)}

@glade =, root, domain,localedir, flag)

@glade.handler_proc = {|handler| method(handler)}

Will any of these options work?



“Why are the pretty ones always insane?” - Clancy Wiggum

Ian McIntosh wrote:


Saw your post to the ruby-gnome mailing list.

Why do you need to do that?

Well, I’m creating a remote gui client so I can deploy a rich network
application. It uses DRb so the client connects to the server and passes
up (via the front object) a gui management object. This gui management
object has functions allowing the server to create widgets (or other
objects) at the client end. Works fine for raw GTK, but Glade brings
some interesting challenges.

So, all the logic (including event handlers) are defined at the server
and I need a way of getting the handlers attached to the GladeXML object
as I haven’t figured out a way of passing a block during object creation
which, incidentally, looks like this:

def create_object(class_name, *instance_parameters)
new_class_ref = Object
class_name.split(‘::’).each { |c|
new_class_ref = new_class_ref.const_get(c)
new_object =*instance_parameters)
@widgets[new_object.object_id] = new_object
return new_object

I have created the GladeXML, and I have created an object containing
suitably named handlers (which lives on the server with a DRb proxy
object passed down to the client) but I’m currently trying to figure out
how to wire the two together. Maybe I should migrate to 1.9 which as
String#to_proc apparently, but I want 1.8 compatibility if possible.

This is what I use:
~ian-mcintosh/luz/trunk : contents of utils/glade_window.rb at revision 2167

I’ll take a look at this tomorrow - off to sleep for now!



In case anyone was interested, my solution was:

  • Create a class containing the event handlers on the server.
  • Create a wrapper class containing the GladeXML object on the client.
  • In the handler creation block, dynamically create local (i.e. in the
    wrapper class) instance methods with the same name as the glade signal
    and the remote handler function. Local functions call remote ones of
    the same name via DRbObject#missing_method.



“The idea that an arbitrary naive human should be able to properly use a
given tool without training or understanding is even more wrong for
computing than it is for other tools (e.g. automobiles, airplanes, guns,
power saws).” - Doug Gwyn