I have an FXMDIClient widget for which I would like to detect changes in
active window so that I can modify root-level keybindings and change the
menus available. I am having trouble capturing the SEL_CHANGED message in
the FXMDIClient or the SEL_ACTIVATED messages in the child widgets.
Here is my sample code, which crashes pretty hard when I try to switch
windows:
#!/usr/bin/ruby -w
require 'fox’
include Fox
def new_buffer(root,x)
mdi_child = FXMDIChild.new(root, “Test”, nil, nil, 0, (25 * x), (25 * x),
400, 300)
FXText.new(mdi_child, nil, 0)
mdi_child.create
end
def switch_buffer(sender, sel, data)
puts "sender: #{sender}\nsel: #{sel}\ndata: #{data}"
end
#create app
app = FXApp.new
mw = FXMainWindow.new(app, “mdi_test”, nil, nil, DECOR_ALL, 0, 0, 640, 480)
buffers = FXMDIClient.new(mw, LAYOUT_FILL_X|LAYOUT_FILL_Y)
app.create
mw.show
3.times{|x| new_buffer(buffers, x) }
buffers.connect(SEL_CHANGED, method(:switch_buffer))
app.run
The output:
m_libby@greyhound:~$ ruby mdi_error.rb
sender: #Fox::FXMDIClient:0x40ec61b4
sel: 2555904
data: #Fox::FXMDIChild:0x40ec53e0
mdi_error.rb:27:in position': undefined method
position’ for nil
(NoMethodError)
from mdi_error.rb:27:in `run’
from mdi_error.rb:27
m_libby@greyhound:~$
I’ve tried tinkering with the block version of connect, and putting in
return values from the switch_buffer method, but I still get errors either
way. Any ideas?
ruby 1.7.3
FOX 1.0.28
FXRuby 1.0.16
Thanks.
-michael