mutual updates in TextCtrls?

new to wxpython and gui programming generally. i'm thinking that this must come up often, so there may be an idiomatic solution, or a better way to do it.

i have a TextCtrl on each of two pages. I want user entry in either TextCtrl to be copied into the other TextCtrl. Symmetric replication if you like.

Apparently EVT_TEXT is triggered by programmatic updates as well as as user input. This implies that catching EVT_TEXT on each control would lead to a loop of mutual updates.

I can imagine that possible approaches might include:

1) magically render EVT_TEXT insensitive to programmatic updates (doesn't sound like newbie magic)
2) inspect some 'event stack' somewhere to see if you are the source of the current stack of events. if you are, copy the data; if you are not at the bottom of the stack, then you are target of another control's event, so do not copy the data (call Event.Skip(), i guess).
3) disable events until copying is done, using wx.Window.SetExtraStyle(wx.WX_BLOCK_EVENTS)? Then restore styles when done? Possible complications?

Is there a 'right' way to do this? Is there any way to do this?

Jim Peterson wrote:

new to wxpython and gui programming generally. i'm thinking that this must come up often, so there may be an idiomatic solution, or a better way to do it.

i have a TextCtrl on each of two pages. I want user entry in either TextCtrl to be copied into the other TextCtrl. Symmetric replication if you like.

Apparently EVT_TEXT is triggered by programmatic updates as well as as user input. This implies that catching EVT_TEXT on each control would lead to a loop of mutual updates.

I can imagine that possible approaches might include:

1) magically render EVT_TEXT insensitive to programmatic updates (doesn't sound like newbie magic)
2) inspect some 'event stack' somewhere to see if you are the source of the current stack of events. if you are, copy the data; if you are not at the bottom of the stack, then you are target of another control's event, so do not copy the data (call Event.Skip(), i guess).
3) disable events until copying is done, using wx.Window.SetExtraStyle(wx.WX_BLOCK_EVENTS)? Then restore styles when done? Possible complications?

Is there a 'right' way to do this? Is there any way to do this?

Most people will just set a flag before doing the thing that will cause an unwanted event and then check that flag at the begining of the event handler.

ยทยทยท

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