I am struggling again with ProgressDialog behaviour in wx 4.1.1 for an application which I am porting from 3.0.2.0. (windows 10)
I open a ProgressDialog & set it to “Pulse()” while I read a list of files from a network directory & then display them in my main application ListCtrl.
In wx 3.0.2.0 the code example below works fine (see also the animated GIF).
In wx 4.1.1 the dialog does not pulse until just before it closes.
I have other applications with 4.1.1 where the Pulse is working, so Im sure its my code but I cant see the difference in my usage.
Im guessing its because my code is executing the task (e.g. Sleep()) within the OnButtonClick function so the GUI is not given time to “update” the window.
However, I dont understand why it worked before & not now.
I have tried adding wx.Yield()
or wx.GetApp().Yield()
but this does not change the behaviour.
Can anyone see what I’m missing ??
As Simple Example is below which shows this behaviour:
import wx
import time
application = wx.App()
framework = wx.Frame(parent=None, title='MyFrame')
panel = wx.Panel(framework) # create a panel as a child of the frame
button = wx.Button(panel, label='Click Me', style=wx.BU_LEFT) # create a button as a child of the panel
sizer = wx.BoxSizer(wx.HORIZONTAL) # create a horizontal sizer
sizer.Add(button, 0, wx.ALL, 5) # add the button to the sizer with some padding
panel.SetSizer(sizer) # set the sizer for the panel
def on_button_click(event):
with wx.ProgressDialog("My Viewer", "Copying File...", maximum=1, parent=framework) as open_dlg:
open_dlg.Pulse()
time.sleep(5)
open_dlg.Update(1)
button.Bind(wx.EVT_BUTTON, on_button_click)
framework.Show()
application.MainLoop()