[wxruby-users] lose focus event?

Alex Fenton alex at pressure.to
Sun Jan 20 19:07:29 EST 2008


Hi David

David Morton wrote:
> I see that event firing, but it appears global, firing for everything  
> that loses focus.  I've tried to identify what object was responsible  
> via #get_event_object, #get_id, and  #id, but no luck so far.  How do  
> I associate it with the combo box?
>   
FocusEvents aren't CommandEvents, so they don't "bubble" upwards to 
parent widgets. So I think you need to call the evt_kill_focus method on 
each ComboBox instance. Have a look at the event handling tutorial in 
the main API docs for more info.

get_event_object should return the widget that triggered any event.

>       cbo = ComboBox.new(helloframe,
>                          :pos =>Point.new(10,10),
>                          :choices => ["foo","bar"],
>                          :value => "asdasd",
>                          :style => CB_SORT)
>       helloframe.show()
>       evt_set_focus() {|w|
>         # how do I tie this to cbo ?
>         }
>     end
try:
cbo.evt_set_focus { ... }

Note that there's a bug on OS X that means ComboBoxes aren't firing 
evt_kill_focus for some reason. But it should work fine on Windows or Linux.

hth
alex


More information about the wxruby-users mailing list