stop events

This forum can be used to talk about general design strategies, new ideas and questions in general related to wxWidgets. If you feel your questions doesn't fit anywhere, put it here.
Post Reply
ianar
Experienced Solver
Experienced Solver
Posts: 51
Joined: Tue Feb 07, 2006 5:50 pm
Location: Florida
Contact:

stop events

Post 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?

TIA
.
o--|==ianar
upCASE
Moderator
Moderator
Posts: 3176
Joined: Mon Aug 30, 2004 6:55 am
Location: Germany, Cologne

Post by upCASE »

Hi!
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.
OS: OpenSuSE, Ubuntu, Win XP Pro
wx: svn
Compiler: gcc 4.5.1, VC 2008, eVC 4

"If it was hard to write it should be hard to read..." - the unknown coder
"Try not! Do. Or do not. There is no try." - Yoda
clyde729
Super wx Problem Solver
Super wx Problem Solver
Posts: 426
Joined: Mon May 29, 2006 10:50 pm
Location: Jena, Germany

Post 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)

Cheers!
OS: Windows XP Home, Compiler: MingW, Version: wxWidgets 2.8.0, IDE: wx-Devcpp
User avatar
doublemax
Moderator
Moderator
Posts: 19159
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Post by doublemax »

there is also wxTextCtrl::ChangeValue which does not generate an event.
Use the source, Luke!
ianar
Experienced Solver
Experienced Solver
Posts: 51
Joined: Tue Feb 07, 2006 5:50 pm
Location: Florida
Contact:

Post 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. :)
.
o--|==ianar
Post Reply