[fxruby-users] Monitoring events/messages

David MacMahon
Sun, 18 Jan 2009 19:20:49 -0000

I am trying to learn FXRuby (and Fox).  I already know Ruby pretty
well.  One thing that would help my understanding of FXRuby (and Fox)
is to be able to monitor (i.e. spy) on events that are sent to a
particular widget, class of widgets, or every widget.  I tried to
accomplish this both by redefining the FXObject#handle  as well as
creating my own subclass with its own #handle method.  Neither way
did what I was hoping it would do.

Below is my modified hello.rb script.  Can anyone tell me how to do
what I''m trying to do?  Can it be done at all in FXRuby?

Thanks,
Dave

#!/usr/bin/env ruby

require ''fox16''

include Fox

class FXObject
   alias :old_handle :handle
   def handle(sender, selector, data)
     p [self, sender, selector, data]
     old_handle(sender, selector, data)
   end
end

class MyApp < FXApp
   def handle(sender, selector, data)
     p ["MyApp", sender, selector, data]
     super(sender, selector, data)
   end
end

application = MyApp.new("Hello", "FoxTest")
main = FXMainWindow.new(application, "Hello", nil, nil, DECOR_ALL)
FXButton.new(main, "&Hello, World!", nil, application,
FXApp::ID_QUIT)
application.create()
main.show(PLACEMENT_SCREEN)
application.run()