-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 I''m new to wxruby, and I haven''t found any answer with google: Is there a way to capture a lose focus event on controls, such as a combo box? All my experiments show events when changing the text, but not when leaving the box. I want to make a combobox that autocompletes if I press tab (or down arrow or something), but if I click out or hit enter it needs to prompt me to add a new value. I''m trying to duplicate a behaviour in an Access app - I''d really like to ditch Access! On a higher level explanation, in case there''s a better way to do it... I want it to search as I type, displaying possible matches, and let me complete with one of the matches, or if there is no match use the current search to create a new record. David Morton Maia Mailguard http://www.maiamailguard.com mortonda@dgrmm.net -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (Darwin) iD8DBQFHkipRUy30ODPkzl0RAi1bAKDNUbpfevGbpbkDQ8SqXXLZdDcrwQCfcE9G 3SLeVn92PcX8dgBXonwo0TA=ndvX -----END PGP SIGNATURE-----
Hello David, First off, welcome to the wxRuby community. Always nice to see new faces around, and more interest being sparked in wxRuby, especially since it is getting more stable with every release we make. To capture Focus Lost, you would need to use evt_kill_focus(), this detects when a control looses focus. It''s specifically for Windows, but since 99.9 percent of the classes we use in wxRuby, are derived from wxWindow, you should be able to utilize the evt_kill_focus() to detect when a control (Such as a combo box), has lost focus. Don''t think we have a full example of evt_kill_focus() and it''s counterpart evt_set_focus(), but it''s pretty simple, and you can find the docs for it here: http://wxruby.rubyforge.org/doc/focusevent.html If you have any more questions, feel free to ask, we''re more then happy to help out. L8ers, Mario Steele On 1/19/08, David Morton <mortonda at dgrmm.net> wrote:> > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > I''m new to wxruby, and I haven''t found any answer with google: Is > there a way to capture a lose focus event on controls, such as a combo > box? All my experiments show events when changing the text, but not > when leaving the box. > > I want to make a combobox that autocompletes if I press tab (or down > arrow or something), but if I click out or hit enter it needs to > prompt me to add a new value. I''m trying to duplicate a behaviour in > an Access app - I''d really like to ditch Access! > > > On a higher level explanation, in case there''s a better way to do it... > > I want it to search as I type, displaying possible matches, and let me > complete with one of the matches, or if there is no match use the > current search to create a new record. > > David Morton > Maia Mailguard http://www.maiamailguard.com > mortonda at dgrmm.net > > > > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.4.7 (Darwin) > > iD8DBQFHkipRUy30ODPkzl0RAi1bAKDNUbpfevGbpbkDQ8SqXXLZdDcrwQCfcE9G > 3SLeVn92PcX8dgBXonwo0TA> =ndvX > -----END PGP SIGNATURE----- > _______________________________________________ > wxruby-users mailing list > wxruby-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/wxruby-users >-- Mario Steele http://www.trilake.net http://www.ruby-im.net http://rubyforge.org/projects/wxruby/ http://rubyforge.org/projects/wxride/ http://rubyforge.org/projects/vwmc/ -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/wxruby-users/attachments/20080119/ac39483a/attachment-0001.html
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Jan 19, 2008, at 11:39 AM, Mario Steele wrote:> Hello David, > > First off, welcome to the wxRuby community. Always nice to see new > faces around, and more interest being sparked in wxRuby, especially > since it is getting more stable with every release we make. To > capture Focus Lost, you would need to use evt_kill_focus(), this > detects when a control looses focus. It''s specifically for Windows, > but since 99.9 percent of the classes we use in wxRuby, are derived > from wxWindow, you should be able to utilize the evt_kill_focus() to > detect when a control (Such as a combo box), has lost focus. > > Don''t think we have a full example of evt_kill_focus() and it''s > counterpart evt_set_focus(), but it''s pretty simple, and you can > find the docs for it here: http://wxruby.rubyforge.org/doc/focusevent.html > > If you have any more questions, feel free to ask, we''re more then > happy to help out. >Thanks for the generous welcome. I''m usually a unix person, and web based, but got roped into working on an Access project. (Hence why I''d rather do this in ruby) GUI stuff by hand is quite new to me. :) 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? require ''rubygems'' require "wx" include Wx class HelloWorld < App def on_init helloframe = Frame.new(nil, -1, "Hello World") button = Button.new(helloframe, :label => ''Close'', :pos => [200,200]) evt_button(button) {exit} 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 end HelloWorld.new.main_loop David Morton Maia Mailguard http://www.maiamailguard.com mortonda at dgrmm.net -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (Darwin) iD8DBQFHkms6Uy30ODPkzl0RAm6nAJ0QM8C4BJpIVduRleF1ci2F45cnsgCguqSU SD4j0BzY9WsCl+egTkwjxxU=qXox -----END PGP SIGNATURE-----
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1> > 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?I found and example in HTTP://wxruby.rubyforge.org/svn/trunk/wxruby2/samples/controls/ but it doesn''t work. Did you mean MS Windows when you said it was related to windows, or WX windows? class MyComboBox < ComboBox def initialize(*args) super(*args)#, style) evt_set_focus {|event| onFocusGot(event)} end def onFocusGot(event) log_message("MyComboBox::OnFocusGot") event.skip() end end David Morton Maia Mailguard http://www.maiamailguard.com mortonda at dgrmm.net -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (Darwin) iD8DBQFHkpIjUy30ODPkzl0RAj9MAKCRdrzr370rQyJ3TIkAzhe+WhLl8wCeK355 Xc40BF9/81vJO1zZ6m1NXFU=OGub -----END PGP SIGNATURE-----
evt_focus does capture all focus changes. The thing to do, is utilize EvtFocus.get_window, that will return the window that the focus is being called for. On 1/19/08, David Morton <mortonda at dgrmm.net> wrote:> > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > > > > 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? > > > I found and example in > HTTP://wxruby.rubyforge.org/svn/trunk/wxruby2/samples/controls/ > > but it doesn''t work. Did you mean MS Windows when you said it was > related to windows, or WX windows? > > class MyComboBox < ComboBox > def initialize(*args) > super(*args)#, style) > > evt_set_focus {|event| onFocusGot(event)} > end > > > def onFocusGot(event) > log_message("MyComboBox::OnFocusGot") > event.skip() > end > > end > > > > David Morton > Maia Mailguard http://www.maiamailguard.com > mortonda at dgrmm.net > > > > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.4.7 (Darwin) > > iD8DBQFHkpIjUy30ODPkzl0RAj9MAKCRdrzr370rQyJ3TIkAzhe+WhLl8wCeK355 > Xc40BF9/81vJO1zZ6m1NXFU> =OGub > -----END PGP SIGNATURE----- > _______________________________________________ > wxruby-users mailing list > wxruby-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/wxruby-users >-- Mario Steele http://www.trilake.net http://www.ruby-im.net http://rubyforge.org/projects/wxruby/ http://rubyforge.org/projects/wxride/ http://rubyforge.org/projects/vwmc/ -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/wxruby-users/attachments/20080119/a456e8fb/attachment-0001.html
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Jan 19, 2008, at 6:22 PM, Mario Steele wrote:> evt_focus does capture all focus changes. The thing to do, is > utilize EvtFocus.get_window, that will return the window that the > focus is being called for.test.rb:63:in `on_init'': undefined method ''get_window'' for #<Wx::FocusEvent:0x11d26a98> (NoMethodError) from test.rb:68:in `call'' from test.rb:68:in `main_loop'' from test.rb:68 class HelloWorld < App def on_init helloframe = Frame.new(nil, -1, "Hello World") button = Button.new(helloframe, :label => ''Close'', :pos => [200,200]) evt_button(button) {exit} cbo = MyComboBox.new(helloframe, :pos =>Point.new(10,10), :choices => ["foo","bar"], :value => "asdasd", :style => CB_SORT) helloframe.show() evt_set_focus() {|w| puts w.get_window # how do I tie this to cbo ? } end end HelloWorld.new.main_loop David Morton Maia Mailguard http://www.maiamailguard.com mortonda at dgrmm.net -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (Darwin) iD8DBQFHkphlUy30ODPkzl0RAmhIAJ4oTI9fQSCMlotalaYNvNa1EXvkTQCgkdVf CgiQBdFCoEdUE1ZU6bC1Deo=8NQI -----END PGP SIGNATURE-----
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 From what I can tell from various wxwidget sources, it seems that most controls do not send the event up to the control level, and I saw one post that was attempting to bind an event... is this the EvtHandler#connect method? On Jan 19, 2008, at 6:22 PM, Mario Steele wrote:> evt_focus does capture all focus changes. The thing to do, is > utilize EvtFocus.get_window, that will return the window that the > focus is being called for. > > On 1/19/08, David Morton <mortonda at dgrmm.net> wrote: -----BEGIN PGP > SIGNED MESSAGE----- > Hash: SHA1 > > > > > 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? > > > I found and example in HTTP://wxruby.rubyforge.org/svn/trunk/wxruby2/samples/controls/ > > but it doesn''t work. Did you mean MS Windows when you said it was > related to windows, or WX windows? > > class MyComboBox < ComboBox > def initialize(*args) > super(*args)#, style) > > evt_set_focus {|event| onFocusGot(event)} > end > > > def onFocusGot(event) > log_message("MyComboBox::OnFocusGot") > event.skip() > end > > end > > > > David Morton > Maia Mailguard http://www.maiamailguard.com > mortonda at dgrmm.net > > > > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.4.7 (Darwin) > > iD8DBQFHkpIjUy30ODPkzl0RAj9MAKCRdrzr370rQyJ3TIkAzhe+WhLl8wCeK355 > Xc40BF9/81vJO1zZ6m1NXFU> =OGub > -----END PGP SIGNATURE----- > _______________________________________________ > wxruby-users mailing list > wxruby-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/wxruby-users > > > > -- > Mario Steele > http://www.trilake.net > http://www.ruby-im.net > http://rubyforge.org/projects/wxruby/ > http://rubyforge.org/projects/wxride/ > http://rubyforge.org/projects/vwmc/ > _______________________________________________ > wxruby-users mailing list > wxruby-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/wxruby-usersDavid Morton Maia Mailguard http://www.maiamailguard.com mortonda at dgrmm.net -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (Darwin) iD8DBQFHkrQhUy30ODPkzl0RApl/AKDV5mFHh7YCGNKd8ji2TXKG+u3d+QCcDnG/ GLo2hIMbyp7bi7uqLlAIZD0=EAfD -----END PGP SIGNATURE-----
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 ? > } > endtry: 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
David Morton
2008-Jan-21 00:16 UTC
[wxruby-users] lose focus event? *Works in XP ; fails in OS X*
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Starting over on this thread. I found an example in the sample code controls/controls.rb around line 110-149: class MyComboBox < ComboBox def initialize(parent,id,value = EmptyString, pos = DEFAULT_POSITION, size = DEFAULT_SIZE, choices = [], style = 0) super(parent, id, value, pos, size, choices)#, style) evt_char {|event| onChar(event)} evt_key_down {|event| onKeyDown(event)} evt_key_up {|event| onKeyUp(event)} evt_set_focus {|event| onFocusGot(event)} end # [snip] def onFocusGot(event) log_message("MyComboBox::OnFocusGot") event.skip() end end I uncommented that log_message call in onFocusGot(). It works in WinXP, but it does not work in OS X. In XP, I get a popup with that message, but in OS X, nothing happens at all. Eventually the pp is going to be used in XP, but I''d like to develop on OS X. Any ideas? David Morton Maia Mailguard http://www.maiamailguard.com mortonda at dgrmm.net -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (Darwin) iD8DBQFHk+RHUy30ODPkzl0RAtXYAKDINuBBaAqfOEfJRUajNpPKedileACg06VR vxNQodbw6F0UErkeI5JuTKY=tMwM -----END PGP SIGNATURE-----
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Jan 20, 2008, at 6:07 PM, Alex Fenton wrote:> > 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.Hah, I just fired off a message about that. lol. Is this a wxwidgets thing, or a deeper OS X thing? David Morton Maia Mailguard http://www.maiamailguard.com mortonda at dgrmm.net -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (Darwin) iD8DBQFHk+S0Uy30ODPkzl0RAieJAJoCbnOf5jz4oDIstyj/1Hs119SLIACfeFhH QQGxQv8+NnQtC0eZAvOa/z0=auOH -----END PGP SIGNATURE-----
Alex Fenton
2008-Jan-21 00:32 UTC
[wxruby-users] lose focus event? *Works in XP ; fails in OS X*
David Morton wrote:> I uncommented that log_message call in onFocusGot(). It works in > WinXP, but it does not work in OS X. In XP, I get a popup with that > message, but in OS X, nothing happens at all. Eventually the pp is > going to be used in XP, but I''d like to develop on OS X. Any ideas? >http://rubyforge.org/tracker/index.php?func=detail&aid=5532&group_id=35&atid=218 It''s a bug I would very much like to fix as I want to do something similar to what you describe in my own app. But I suspect it''s a wxWidgets problem, and haven''t got around to writing a C++ test case to find out. As a workaround you could use evt_child_focus, which definitely does work on OS X. You cna use get_window to see what child received focus, and if you track what the last focus was, you could see when the CB lost focus. alex