1. wxEuphoria - set_event_handler
- Posted by sixs <sixs at ida.net> Apr 25, 2005
- 430 views
Hi. I'm having some trouble with clicking on a wxlistbox and I am confused about the event handler. I am thinking that within set event handler that the "this" is the wxFrame name, "id" is thename of the listbox, the "event" is ?, " rid" is the name of the procedure. I can get the buttons to work. Thanks for any help Jim set_event_handler ( object this, object id, object event, integer rid ) Category: Events <cid:part1.08050608.07080507 at ida.net> Set up an event handler. * *this* is the object that receives the event. Often, it will be the top level frame that receives the event, as in the case of a menu item. When setting an event for a wxMenuItem <cid:part2.03040306.02070104 at ida.net> under Linux, *this* must be a sequence where the first element is the wxFrame <cid:part3.09020900.05020408 at ida.net> to which the wxMenuItem <cid:part2.03040306.02070104 at ida.net> belongs, and the second element is the wxMenu <cid:part5.08080504.05030404 at ida.net> to which the wxMenuItem <cid:part2.03040306.02070104 at ida.net> belongs. Under Windows, set_event_hander() will also accept *this* as a sequence. * *id* is the id of the item generating the event, such a a menu item. * *event* is an event constant, and * *rid* is the routine id of your event handler.
2. Re: wxEuphoria - set_event_handler
- Posted by Mario Steele <eumario at trilake.net> Apr 25, 2005
- 459 views
Hey Jim, sixs wrote: > > Hi. I'm having some trouble with clicking on a wxlistbox and I am > confused about the event handler. I am thinking that within set event > handler that the "this" is the wxFrame name, "id" is thename of the > listbox, the "event" is ?, " rid" is the name of the procedure. I can > get the buttons to work. > Thanks for any help > Jim Okay, I know this can be a bit confusing at first, but it's actually quite simple. With wxEuphoria, most controls, can have a ID assigned to it, but the thing to note about wxEuphoria, is that it's an Object Oriented library. In the set_event_handler() routine, this refers to the instance of the control you created, for example: constant MyFrame = create(wxWindow,{0,-1,"Hello World",-1,-1,-1,-1}) set_event_handler(MyFrame,-1,wxEVT_PAINT,routine_id("myPaintRoutine")) Notice, that the 'this' is being passed as MyFrame. the 'id' is -1. The 'event' is wxEVT_PAINT, and the 'rid' is "routine_id("myPaintRoutine")" Another way this can work, is through this method: set_event_handler(MyFrame,get_id(MyFrame),wxEVT_PAINT,routine_id("myPaintRoutine")) Most generally, the ID that you pass in a set_event_handler() can be a -1, so that the wxEuphoria library can grab the 'id' associated with the instance given. Hope this helps. Mario Steele http://enchantedblade.trilake.net Attaining World Dominiation, one byte at a time...
3. Re: wxEuphoria - set_event_handler
- Posted by Matt Lewis <matthewwalkerlewis at gmail.com> Apr 25, 2005
- 432 views
Mario Steele wrote: > > Hey Jim, > sixs wrote: > > > > Hi. I'm having some trouble with clicking on a wxlistbox and I am > > confused about the event handler. I am thinking that within set event > > handler that the "this" is the wxFrame name, "id" is thename of the > > listbox, the "event" is ?, " rid" is the name of the procedure. I can > > get the buttons to work. > > Thanks for any help > > Jim > > Okay, I know this can be a bit confusing at first, but it's actually quite > simple. With wxEuphoria, most controls, can have a ID assigned to it, but > the thing to note about wxEuphoria, is that it's an Object Oriented library. > > In the set_event_handler() routine, this refers to the instance of the > control you created, for example: > > constant MyFrame = create(wxWindow,{0,-1,"Hello World",-1,-1,-1,-1}) > > set_event_handler(MyFrame,-1,wxEVT_PAINT,routine_id("myPaintRoutine")) > > Notice, that the 'this' is being passed as MyFrame. the 'id' is -1. > The 'event' is wxEVT_PAINT, and the 'rid' is "routine_id("myPaintRoutine")" I can see that I need to sharpen the docs with regard to ids. :) Actually, when you create a control with an id of -1, it's really telling wxWidgets to automatically assign an id. Usually, this is what you want to do. There are some conveniently pre-assigned ids, such as wxID_OPEN, wxID_EXIT, etc. In the docs, look at Controls->IDs for some more info. Note that wxMenuItems won't automatically generate an id, so you either need to use one of the pre-assigned, or make a new one using new_id(). When you set an event handler, however, -1 means something else. When an event is triggered, wxWidgets notifies the objects 'responsible' for the event. Any normal control has wxEventHandler in its ancestry. Usually, if the control itself (e.g., the wxButton) doesn't handle the event, then the event is passed to the control's parent. The parent needs to know who is doing the event (could be lots of buttons), so the id of the source of the event is passed. This is especially important for menus, since they don't have their own event handlers--the wxFrame parent has to handle their events. So for your buttons, you could set up the handler in any of several ways:
set_event_handler( MyFrame, buttonID, wxEVT_COMMAND_BUTTON_CLICKED, routine_id("on_click")) set_event_handler( MyFrame, -1, wxEVT_COMMAND_BUTTON_CLICKED, routine_id("on_click")) set_event_handler( MyButton, buttonID, wxEVT_COMMAND_BUTTON_CLICKED, routine_id("on_click")) set_event_handler( MyButton, -1, wxEVT_COMMAND_BUTTON_CLICKED, routine_id("on_click"))
Matt Lewis