wx.Postevent is only processed at the end

111 views
Skip to first unread message

franz steinhaeusler

unread,
May 30, 2017, 7:24:23 AM5/30/17
to wxPython-users
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?

franz steinhaeusler

unread,
May 30, 2017, 8:48:03 AM5/30/17
to wxPython-users
Sorry, solved, this was a bug in my program in another location...

Chris Barker

unread,
May 31, 2017, 6:47:27 PM5/31/17
to wxpython-users
On Tue, May 30, 2017 at 5:48 AM, franz steinhaeusler <franz.ste...@gmail.com> wrote:
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


--

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....@noaa.gov

franz steinhaeusler

unread,
Jun 1, 2017, 4:36:23 AM6/1/17
to wxPython-users
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.
Reply all
Reply to author
Forward
0 new messages