Extending Events

Hans Harmon hans_harmon at yahoo.com
Fri Aug 4 05:49:53 PDT 2006


Lee,

No problem.
I just noticed a few things wrong with the example code, but they are minor.

first change ScriptData from a struct to:

class ScriptData : public wxObject
{
    scriptValue ctrl;
    scriptValue evt;
    scriptValue func;
};

And second, I used the "." instead of "->" when accessing its members.

That's what I get for throwing an exmple together too fast, too early in the morning.

Hans.


Lee McColl-Sylvester <lee.mccoll at lyons-group.co.uk> wrote:        v\:* {behavior:url(#default#VML);} o\:* {behavior:url(#default#VML);} w\:* {behavior:url(#default#VML);} .shape {behavior:url(#default#VML);}           Hi Hans,
   
  Thanks for that.  I have the wxWidgets book, but it in no way hints to the fact you can include user data in the connect function.  Had I known that, I would have solved this ages ago.  Guess I should learn to look in the manual from time to time.  ;-)
   
  Thank you.  You’ve saved me hours of hair pulling.
   
  Regards,
  Lee
   
   
   
   
      
---------------------------------
  
  From: Hans Harmon [mailto:hans_harmon at yahoo.com] 
 Sent: 04 August 2006 13:30
 To: wx-users at lists.wxwidgets.org
 Subject: RE: Extending Events
  
   
  Lee,
 
 This is not complete, but should provide enough of a start to get things working.
 
 /////////////////////////////
 // Begin code
 
 struct ScriptData
 {
     scriptValue ctrl;
     scriptValue evt;
     scriptValue func;
 };
 
 
 class MyEvtHandler : EvtHandler()
 {
     // Have script use something like this.
     void MyClass ::EventBind( scriptValue ctrl, scriptValue evt, scriptValue func )
     {
         // Create some data to store, remember to delete this later.
         ScriptData * newScriptData = new ScriptData();
 
         newScriptData.ctrl = ctrl;
         newScriptData.evt  = evt;
         newScriptData.fun  = func;
 
         // Select the type of event. To be used by the type of event
         //...
 
         // Get the event type and id information
         wxEventType event_type = evt.event_type;
         int event_id = evt.id;
         
         // The this->OnEvent will need to be cast to the right type of event handler, see wx/event.h for a list of these macros.
         this->Connect ( event_id, event_type, wxMenuEventHandler ( this->OnEvent ), newScriptData, this );
     }
 
     OnEvent ( wxEvent &event )
     {
         ScriptData * scriptEventData;
 
         scriptEventData = event.GetEventObject();
 
         // Process the event using the ctrl, evt, and func values stored.
     }
 };
 
 // End Code
 /////////////////////
 
 Also note that wxEventType is just an int.  And look in event.h for a list of macros for the event function conversion.  I just used wxMenuEventHandler since your previous example showed a table that grabs all of the menu events.
 
 Hans
 
 
 Lee McColl-Sylvester <lee.mccoll at lyons-group.co.uk> wrote:
    Hi Hans,
  
     
  
    Can you at least give a tiny example how I would pass data to an event type before calling the EvtHandler::Connect function?
  
     
  
    Thanks,
  
    Lee
  
     
  
     
  
     
  
      
---------------------------------
  
    From: Hans Harmon [mailto:hans_harmon at yahoo.com] 
 Sent: 04 August 2006 12:47
 To: wx-users at lists.wxwidgets.org
 Subject: Re: Extending Events
  
  
     
  
    I would recommend looking at EvtHandler::Connect as this has solved some of my needs for dynamic events, without needing the macro table.  You should be able to use the UserData pointer to pass whatever else you need for the event callback to work properly.  Unfortunately I do not have any examples (that I can post), especially doing this with a scripting language.
 
 Hans
 
 Lee McColl-Sylvester <lee.mccoll at lyons-group.co.uk> wrote:
  
    Hi List,
 
 
 
 I'm intending on using wxWidgets to provide GUI support for a scripting
 language, but I'm having trouble working out how best to support events.
 I know that wxPython extends the event objects, but how do they then get
 the widgets to send the events with the extended data?
 
 
 
 For example, normally one would register an event and supply a function
 pointer using the event table macros, but this won't be possible in my
 cercumstance. I'm gonna need to register the event dynamically, passing
 not only a function call but also various parameters that the function
 will need to be able to proxy the event back to the scripting language.
 
 
 
 Does anyone on this list have experience with this? Do you know of any
 examples I can look at?
 
 
 
 Regards,
 
 Lee
 
 
 
 
 
 
 
 ---------------------------------------------------------------------
 To unsubscribe, e-mail: wx-users-unsubscribe at lists.wxwidgets.org
 For additional commands, e-mail: wx-users-help at lists.wxwidgets.org
  
     
  
     __________________________________________________
 Do You Yahoo!?
 Tired of spam? Yahoo! Mail has the best spam protection around 
 http://mail.yahoo.com 
  
   
    
    
---------------------------------
  
  Talk is cheap. Use Yahoo! Messenger to make PC-to-Phone calls. Great rates starting at 1¢/min.
  
  

 		
---------------------------------
Do you Yahoo!?
 Get on board. You're invited to try the new Yahoo! Mail Beta.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.wxwidgets.org/pipermail/wx-users/attachments/20060804/68da5eda/attachment.htm


More information about the wx-users mailing list