[wxruby-users] Mouse motion example - help

Alex Fenton alex at pressure.to
Mon Mar 31 16:28:25 EDT 2008


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::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}

cheeers
alex




More information about the wxruby-users mailing list