Hi,
I am trying out this example adapted from the wxpython book, but the
mouse motion event does not seem to be captured right. What am I doing
wrong?
Thanks
warrior
# code below
require 'wx'
class MyFrame < Wx::Frame
def initialize
super(nil, -1, "My Frame", :size => [300,300])
@my_panel = Wx::Panel.new(self, -1)
evt_motion(){ |event| on_move(event)}
Wx::StaticText.new(@my_panel, -1, :label => "Pos:", :pos => [10,
12])
@posCtrl = Wx::TextCtrl.new(@my_panel, -1, "",:pos => [40, 10])
show
end
def on_move(event)
@pos = event.get_position
@posCtrl.change_value("#{@pos}")
end
end
Wx::App.run{MyFrame.new}
on 31.03.2008 19:06
on 31.03.2008 22:29
Ajithkumar Warrier wrote: > I am trying out this example adapted from the wxpython book, but the > mouse motion event does not seem to be captured right. The mouse movement event is directed to the topmost window. So you either need to specify that mouse events are captured by the Frame, or call the event handler upon the panel which is topmost. If you think this is different to wxPython, could you post/point to the example you mention please? > # code below > require 'wx' > > class MyFrame < Wx::Frame > def initialize > super(nil, -1, "My Frame", :size => [300,300]) > @my_panel = Wx::Panel.new(self, -1) > evt_motion(){ |event| on_move(event)} > Either: @my_panel.evt_motion { | e | on_move(e) } or capture_mouse evt_motion :on_move > Wx::App.run{MyFrame.new} cheeers alex
on 31.03.2008 22:41
Thanks, your suggestion worked. I missed out on the fact that I had to bind the mouse motion to the panel and not to MyFrame. So, @my_panel.evt_motion worked exactly as needed.