wx.Postevent is only processed at the end

Hello, I don’t have a runnable expample, so I try to show with pseudo code_

In a thread, I have a loop, which should update a dialog with progress bar.

Examplecode in thread:

while i < 10:
event = wx.CommandEvent ()
event.SetEventType (wx.wxEVT_COMMAND_BUTTON_CLICKED)
event.SetId (9999)
wx.PostEvent(self.m_pWndProgress, event) # this shall call OnUpdateProgress
print “post event”

is here something missing, so that the UI is getting the posted events?

#time.sleep(0.1)
++i

in Progress dialog
wx.EVT_BUTTON(self, 9999, self.OnUpdateProgress)

def OnUpdateProgress(self, event):
print ‘update’

output is:
post event
post event

post event
post event

update
update

update
update

so the update is not called before all PostEvents are delivered.

What do I have to to to get the OnUpdateProgress processed immediatly?

Sorry, solved, this was a bug in my program in another location…

glad you got it solved, but I can't help myself:

This looks like a much messier way to do this than you need. Rather than
try to emulate a button click, why not simply call OnUpdateProgress? --
something like:

wx.CallAfter(the_dialog.OnUpdateProgress, None)

-CHB

···

On Tue, May 30, 2017 at 5:48 AM, franz steinhaeusler < franz.steinhaeusler@gmail.com> wrote:

Sorry, solved, this was a bug in my program in another location...

--

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Hello Chris,

of course you are right, it’s only because I port/ported wxWidgets C++ Code. Here in wxPython, wx.CallAfter would be first choice (and less (and more clean code)) and I change it to that.