I read the api document online: http://wxruby.rubyforge.org/doc/evthandler.html but still don''t know how to use it. EvtHandler#connect connect(Integer id, Integer lastId, EventType eventType, ObjectEventFunction function, Object userData = nil, EvtHandler eventSink = nil) the online doc''s example is write in C++: frame->Connect( ID_EXIT, EVT_COMMAND_MENU_SELECTED, CommandEventHandler(MyFrame::OnQuit) ); is it like this?: frame.connect(Wx::ID_EXIT, Wx::EVT_COMMAND_MENU_SELECTED,frame.on_exit); I need to attach event, but not in initialtion function. thanks! cy
Alex Fenton
2007-Apr-13 08:34 UTC
[Wxruby-users] who can give me an EvtHandler#connect example?
yang cao wrote:> I read the api document online: http://wxruby.rubyforge.org/doc/evthandler.html > but still don''t know how to use it. > > EvtHandler#connect >wxRuby doesn''t currently support the #connect method for hooking up events. There''s an open feature request for it: https://rubyforge.org/tracker/index.php?func=detail&aid=609&group_id=35&atid=221 However, I don''t think it''s a problem for you as you can already do what you want; see below.> is it like this?: > frame.connect(Wx::ID_EXIT, Wx::EVT_COMMAND_MENU_SELECTED,frame.on_exit); >No, this won''t work. In ruby, frame.on_exit calls the method, rather than being a reference to the method to be called later (as in Python or C++)> I need to attach event, but not in initialtion function. >You can do this by using the ordinary way evt_menu(Wx::ID_EXIT) { ... } in wxRuby these can be used anywhere, not just in the initialize method. All of the evt_xxxx methods in ruby are implemented in C++ using EvtHandler#connect. For example, I tried adding an event handler in the on_about method in the minimal sample, and it works correctly. alex
yang cao
2007-Apr-13 18:19 UTC
[Wxruby-users] who can give me an EvtHandler#connect example?
2007/4/13, Alex Fenton <alex at pressure.to>:> yang cao wrote: > > I read the api document online: http://wxruby.rubyforge.org/doc/evthandler.html > > but still don''t know how to use it. > > > > EvtHandler#connect > > > wxRuby doesn''t currently support the #connect method for hooking up > events. There''s an open feature request for it: > https://rubyforge.org/tracker/index.php?func=detail&aid=609&group_id=35&atid=221 > > However, I don''t think it''s a problem for you as you can already do what > you want; see below. > > is it like this?: > > frame.connect(Wx::ID_EXIT, Wx::EVT_COMMAND_MENU_SELECTED,frame.on_exit); > > > No, this won''t work. In ruby, frame.on_exit calls the method, rather > than being a reference to the method to be called later (as in Python orye~, i see :)> C++) > > > I need to attach event, but not in initialtion function. > > > > You can do this by using the ordinary way > > evt_menu(Wx::ID_EXIT) { ... } > > in wxRuby these can be used anywhere, not just in the initialize method. > All of the evt_xxxx methods in ruby are implemented in C++ using > EvtHandler#connect. > > For example, I tried adding an event handler in the on_about method in > the minimal sample, and it works correctly.how can evt_key_down methods pop up the key_down event? like in a textctrl, user typed a ''c''. i want the event handler process it like this: from the ancestor to the descendant, not the opposite, is there any way to do this? thanks! cy> > alex > > > _______________________________________________ > wxruby-users mailing list > wxruby-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/wxruby-users >
Seemingly Similar Threads
- Wizards
- Major Breakthrough?
- [1061] trunk/wxruby2/swig/classes/EvtHandler.i: Remove a lot of no longer needed includes from EvtHandler.i
- [1075] trunk/wxruby2/lib/wx/classes/evthandler.rb: Send IconizeEvent to EvtHandlers
- [ wxruby-Bugs-12610 ] Possible crash with EvtHandler.add_pending_evemt and custom event class