Adding a handler proc after the fact to GladeXML

Hi,

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

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

I’d like to do this:
@glade = GladeXML.new(path_or_data, root, domain,localedir, flag)

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

Or even

my_handler = {|handler| method(handler)}

@glade = GladeXML.new(path_or_data, root, domain,localedir, flag)

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

Will any of these options work?


Cheers,

Matt.

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

Ian McIntosh wrote:

Hi,

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©
}
new_object = new_class_ref.new(*instance_parameters)
@widgets[new_object.object_id] = new_object
return new_object
end

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:
http://bazaar.launchpad.net/~ian-mcintosh/luz/trunk/annotate/head%3A/utils/glade_window.rb

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

Thanks!

Matt

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.


Cheers,

Matt.

“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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs