Hi,
I’m trying to run a long running task. While the user waits for the long running task to be completed, a separate small frame with a gauge on it is displayed. As the long running task is executed, the gauge bar is updated.
But the problem is, although I display the mini frame and update the gauge on a separate thread, the mini frame and gauge is unresponsive. Instead, the main frame is responsive.
What I would like to achieve is: when the user presses the “Start” button, the mini frame should be displayed modal, the gauge should be updated, and the main frame should be unclickable.
Please help,
Thanks
Best Regards
import wx
import time
import threading
import wx.lib.agw.pygauge as PG
class MyForm(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY, "Main Frame",
style=wx.DEFAULT_FRAME_STYLE ^ wx.RESIZE_BORDER ^ wx.MAXIMIZE_BOX,
size=wx.Size(400, 200))
self.panel = wx.Panel(self)
self.button = wx.Button(self.panel, -1, "Start", size=(60, 30))
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.button, 0, wx.ALIGN_CENTER)
self.panel.SetSizer(sizer)
self.panel.Layout()
self.button.Bind(wx.EVT_BUTTON, self.EvtButton, self.button)
def EvtButton(self, event):
WorkerThread(self)
def print_10(self, prg_frame):
for i in range(10):
prg_frame.gauge.SetValue(i)
prg_frame.gauge.Refresh()
print(i)
time.sleep(1)
prg_frame.Destroy()
class ProgressFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY, "Progress Frame",
style=wx.DEFAULT_FRAME_STYLE ^ wx.RESIZE_BORDER ^ wx.MAXIMIZE_BOX,
size=wx.Size(300, 100))
self.progress_panel = wx.Panel(self)
self.gauge = PG.PyGauge(self.progress_panel, -1, size=(100,25),style=wx.GA_HORIZONTAL)
self.gauge.SetRange(10)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.gauge, 0, wx.ALIGN_CENTER)
self.progress_panel.SetSizer(sizer)
class WorkerThread(threading.Thread):
def __init__(self, the_frame):
threading.Thread.__init__(self)
self.frame = the_frame
self.start()
def run(self):
print("here")
self.prg_frame = ProgressFrame()
self.prg_frame.Show()
self.frame.print_10(self.prg_frame)
if __name__ == "__main__":
app = wx.App(False)
frame = MyForm()
frame.Show()
app.MainLoop()