how to simulate an event

hi all.
  
In general, as we simulate an event?
I would like to simulate the event on the enter button without that
has been pressed.
How do I do?

Fabio Spadaro
www.fabiospadaro.com

Fabio Spadaro wrote:

hi all.
  
In general, as we simulate an event?
I would like to simulate the event on the enter button without that
has been pressed.
How do I do?

Fabio Spadaro
www.fabiospadaro.com

See Unit Testing with wxPython - wxPyWiki

If you don't use the event object in your handler, you can fake an event by doing something like this:

self.callMyEventHandler("")

If you want the button to show itself depressing and releasing, you'll have to look at the archives. I don't recall if anyone mentioned a way to do that or not.

···

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org

Fabio Spadaro wrote:

hi all.
  
In general, as we simulate an event?
I would like to simulate the event on the enter button without that
has been pressed.
How do I do?

It depends on what you want it for. If you just want to cause your event handlers to be called but don't care about the actual state of the widget then you can either just call your event handler directly or you can construct and send the event that would have been generated by wx. For example:

  evt = wx.CommandEvent(wx.EVT_BUTTON.typeId)
  evt.SetEventObject(theButton)
  evt.SetId(theButton.GetId())
  theButton.GetEventHandler().ProcessEvent(evt)

On the other hand if you want the native widget to fully respond as if the user actually clicked the mouse buttons on the UI button and then to generate the EVT_BUTTON event "naturally" then you are out of luck. wxWidgets does not provide such functionality because the platforms are so different, and even versions of the same platform will differ from each other in some ways. There is a project underway that will help with things like this, but it is not ready yet. If you really need this level of event simulation then you'll need to use native platform specific code.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!