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()
On Jan 18, 2009, at 1:20 PM, David MacMahon wrote:> 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.You can try setting the target for a particular widget to an FXDebugTarget instance. It should then print to the console all of the messages that that widget receives, e.g. button = FXButton.new(...) debug_target = FXDebugTarget.new button.target = debug_target Hope this helps, Lyle
On Jan 19, 2009, at 7:45 , Lyle Johnson wrote:> You can try setting the target for a particular widget to an > FXDebugTarget instance. It should then print to the console all of > the messages that that widget receives, e.g. > > button = FXButton.new(...) > debug_target = FXDebugTarget.new > button.target = debug_targetThanks, Lyle, I found FXDebugTarget after I had sent my message. That helps somewhat, but it seems like it tells me all the events sent by a widget rather than all the events received by a widget. It seems like FXDebugTarget does not forward the event to any other widget (i.e. the "real" target). I think it would be more useful if FXDebugTarget''s constructor accepted a target (optionally, defaulting to nil). It would print the info as it does now and then pass the event on to the given target (if it''s not nil). This would make it possible to insert and remove an FXDebugTarget at will while still allowing the application to function normally... # Insert FXDebugTarget to see events sent by button button.target = FXDebugTarget.new(button.target) # Remove FXDebugTarget from button button.target = button.target.target The remove operation assumes that FXDebugTarget has an attribute named "target" that returns the original target. This could be a problem if button''s target is a regular widget rather than an FXDebugTarget since that will set button''s target to the other widget''s target, effectively bypassing button''s original target. To avoid this, perhaps FXDebugTarget''s "target" attribute should be called something else (e.g. "original_target"). Then the removal would give an error button''s target does not respond to "original_target"... # Safer removal of FXDebugTarget from button button.target = button.target.original_target With this proxying in place, I could walk the widget tree and add FXDebugtargets to all the wdigets. Then I''d see all the events! Thanks for FXRuby, Dave