Yes, I did understand that aspect of wx.CallAfter. Based on your
explanation in the earlier mails regarding control returning back to
main loop and also the your explanation on the way Skip() works, I did
figure out that CallAfter only calls After the current event handler
ends. My 'concern' wasn't due to a misunderstanding of when
wx.CallAfter executes its callable.
I may have been too brief in describing the concern; and the proposed
solution. Let me explain with these scenarios based on my
application.
---- Scenario A : Intermittent Unhandled exception
OnLeftUp event triggers event handler: Method A which does the
following:
* Prelim checks on what was clicked and required response
* Performs database updates
* resetCalPanels(): Destroys panels: one of which is the source of the
event.
* redrawCalPanels(): Redraws panels (requires database reads); putting
them on a GridBagSizer.
* some finalising code
Scenario A crashes intermittently with 'unhandled exception' because
resetCalPanels destroy the panel which is the source of the event,
prior to the completion of event processing
---- Scenario B : python Add to GridBagSizer exception
OnLeftUp event triggers event handler: Method A which does the
following:
* Prelim checks on what was clicked and required response
* Performs database updates
* wx.CallAfter(resetCalPanels()..: Destroys panels: one of which is
the source of the event.
* redrawCalPanels(): Redraws panels (requires database reads);
putting them on a GridBagSizer
* some finalising code
Scenario B is coded based on misunderstanding of when wx.CallAfter
executes. It will always crash when redrawCalPanels creates the
panels and adds them to the GridBagSizer because at this time,
resetCalPanels hasn't run yet; i.e. the positions in the GridBagSizer
are still occupied by the panels which have yet to be destroyed.
---- Scenario C : * my concern * event handler split across time
OnLeftUp event triggers event handler: Method A which does the
following:
Method A
* Prelim checks on what was clicked and required response
* Performs database updates
* wx.CallAfter(Method_B)
Method_B
* resetCalPanels(): Destroys panels: one of which is the source of the
event.
* redrawCalPanels(): Redraws panels (requires database reads);
putting them on a GridBagSizer
* some finalising code
This example will work without crashing. It is what I have changed my
code to doing at the moment. It shows my concern: the event handler is
now split in time across 2 methods calls. In most cases, this is fine,
but in some cases, it is possible that an intervening event from
another event source has altered the database or some other resource
in a way that interferes with the expected state of resources (db,
screen, etc) during the code execution in Method_B
---- Scenario D : * my proposed solution * ensure event handler is not
split across time
OnLeftUp event triggers event handler: Method A which does the
following:
Method A
* get required event parameters e.g. eventObject: the event source
* wx.CallAfter(Method_B, eventSource)
Method_B
* Prelim checks on what was clicked and required response
* Performs database updates
* resetCalPanels(): Destroys panels: one of which is the source of the
event.
* redrawCalPanels(): Redraws panels; putting them on a GridBagSizer
* some finalising code
This ensures that the code for the event handler is part of a single
continguous execution, without any coding gymnastics required in
preempting interference. Method_A is simply a dummy method to defer
event processing by 'one step' to preempt any problems caused by
destruction of resources required in the 'original' event handler.
Just some thoughts on this issue. Let me know if I am still offtrack.
Will be good to be ontrack finally 
Thanks again.
···
On Aug 13, 2:47 pm, Robin Dunn <ro...@alldunn.com> wrote:
Sam23 wrote:
> My concern: was that by calling wx.CallAfter in the middle of my event
> handling, I effectively split the event handling into 2 parts;
No, absolutely not. Calling wx.CallAfter only posts an event to the
app's pending event queue with the details about the callable and the
parameters, it does not actually call the callable object at that point
in time.