Page 1 of 1

stop events

Posted: Thu Feb 07, 2008 8:08 am
by ianar
Hello all,

Is there a way to stop all event processing during execution of a function?

Here's what's going on:
a) creating panels based on a config file
b) loading values from the config file into respective controls

Now, almost all my textctrl fields have wx.EVT_TXT set, so when the config loader goes widget.SetValue() it triggers the event. I need to stop this from happening.

I've tried using wx.EVT_CHAR, wx.EVT_KEY_UP, and wx.EVT_KEY_DOWN but then what I type doesn't get applied to the control!

I started writing a recursive function that would disable these events but then realized I would have no way of re-applying them.

I played around with SetExtraStyle(wx.WS_EX_BLOCK_EVENTS) but the windows and functions the controls the events are coming from are (generally) at the leaves of the hierarchy, while the loading function is in the trunk.
At least I think that's why it's not working (event handing is confusing) :?

Any ideas?


Posted: Thu Feb 07, 2008 8:25 am
by upCASE
I suppose you could try two things:
1. Use Freeze()
2. Dynamically connect the event handlers.

Using wxWindow::Freeze() will freeze the control so that no updates take place until Thaw() is called. There also is wxWindowUpdateLocker which basically does the same thing. I'm not really sure as I didn't try, but I guess the event handler would still be called, so maybe this is not the best solution.

You could dynamically connect the event handlers for EVT_TEXT. Have a look at wxEvtHandler::Connect(). So you wouldn't create a static event table mapping that would fire the event every time, but instead create your controls, load the text, etc. and then, when everything is finished, use Connect() to have the event handler applied. This may sound a bit complicated, but it should be the way to go.

Posted: Thu Feb 07, 2008 11:31 pm
by clyde729
For "dirty" hackers there is also

int wxApp::FilterEvent(wxEvent& event)

You can also try to externalize the EVT_TEXT to a wxEvtHandler derived class and call

void wxEvtHandler::SetEvtHandlerEnabled(bool enabled)


Posted: Thu Feb 07, 2008 11:39 pm
by doublemax
there is also wxTextCtrl::ChangeValue which does not generate an event.

Posted: Fri Feb 08, 2008 2:44 am
by ianar
Sorry about that, it was one of those 'late night' moments. I had forgotten I was already checking a checkbox to see if the app should process those events. I simply set the value of the checkbox to false during config load.

Thank you nonetheless for the help, I couldn't find much documentation on this on the net ... so if it happens for real I'll know where to look. :)