I called a ProgressDialog without the parent to let users know something is going on.
However when the dialog destroyed, the main frame goes to the bottom (behind of all the other running frames). So I did ‘Raise()’ for the frame but it causes flickering.
I want the frame keeps its position after the dialog’s destruction. I tried yielding or sub-threading but nothing figure it out.
Any ideas?
import wx
from time import sleep
class MyProgressDialog(wx.ProgressDialog):
def __init__(self, test_frame:wx.Frame):
wx.ProgressDialog.__init__(self, 'ProgDlg', 'Working..')
self.test_frame = test_frame
self.Pulse('Working..')
self.Bind(wx.EVT_WINDOW_DESTROY, self.OnDestroy)
def OnDestroy(self, event):
# Without 'Raise()', the main frame goes to the bottom when this dialog is destroyed.
self.test_frame.Raise()
class TestFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, title='TEST', style=wx.DEFAULT_FRAME_STYLE^wx.RESIZE_BORDER^wx.MAXIMIZE_BOX)
pn = wx.Panel(self)
bt = wx.Button(pn, label='Start 5 sec work')
sz_vert = wx.BoxSizer(wx.HORIZONTAL)
sz_vert.AddMany((
((-1, -1), 1),
(bt, 0, wx.ALIGN_CENTER_VERTICAL),
((-1, -1), 1)
))
sz_main = wx.BoxSizer(wx.HORIZONTAL)
sz_main.Add(sz_vert, 1, wx.EXPAND|wx.ALL, 100)
pn.SetSizerAndFit(sz_main)
self.SetSize(self.GetBestSize())
bt.Bind(wx.EVT_BUTTON, self.OnButton)
def OnButton(self, event):
with MyProgressDialog(self):
# I can't add 'wx.Yield()' here.
# I need to solve the problem within 'MyProgressDialog' class.
sleep(5)
if __name__ == '__main__':
app = wx.App()
TestFrame().Show()
app.MainLoop()
Indeed, it won’t occur if a parent has set. But than the main frame is freezing.
In my situation, I can’t do Yield() nor Pulse() from the main thread. (Please see the inside of with MyProgressDialog(self).
How can I make it yield from a sub-thread?
import wx
from time import sleep
class MyProgressDialog(wx.ProgressDialog):
def __init__(self, test_frame:wx.Frame):
wx.ProgressDialog.__init__(self, 'ProgDlg', 'Working..')
self.test_frame = test_frame
self.Pulse('Working..')
self.Bind(wx.EVT_WINDOW_DESTROY, self.OnDestroy)
def OnDestroy(self, event):
# Without 'Raise()', the main frame goes to the bottom when this dialog is destroyed.
self.test_frame.Raise()
class TestFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, title='TEST', style=wx.DEFAULT_FRAME_STYLE^wx.RESIZE_BORDER^wx.MAXIMIZE_BOX)
pn = wx.Panel(self)
bt = wx.Button(pn, label='Start 5 sec work')
sz_vert = wx.BoxSizer(wx.HORIZONTAL)
sz_vert.AddMany((
((-1, -1), 1),
(bt, 0, wx.ALIGN_CENTER_VERTICAL),
((-1, -1), 1)
))
sz_main = wx.BoxSizer(wx.HORIZONTAL)
sz_main.Add(sz_vert, 1, wx.EXPAND|wx.ALL, 100)
pn.SetSizerAndFit(sz_main)
self.SetSize(self.GetBestSize())
bt.Bind(wx.EVT_BUTTON, self.OnButton)
def OnButton(self, event):
with MyProgressDialog(self):
# I can't add 'wx.Yield()' here.
# I need to solve the problem within 'MyProgressDialog' class.
# Many
sleep(1)
# many
sleep(1)
# many
sleep(1)
# many
sleep(1)
# lines here
if __name__ == '__main__':
app = wx.App()
TestFrame().Show()
app.MainLoop()