-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
58 lines (46 loc) · 1.75 KB
/
main.py
File metadata and controls
58 lines (46 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import threading, time
import wx
from GradientFlowDialog import GradientFlowDialog
class MainFrame(wx.Frame):
def __init__(self, parent, ID, title):
"""
Initializes the MainFrame window and starts a worker thread to perform tasks.
This constructor sets up the main frame of the application, initializes a
GradientFlowDialog to display progress, and starts a separate thread to handle
time-consuming tasks.
Parameters:
parent (wx.Window): The parent window for this frame.
ID (int): The identifier for the frame.
title (str): The title of the frame.
Returns:
None
"""
wx.Frame.__init__(self, parent, ID, title)
self.gFr = GradientFlowDialog(message="Processing can take a few minutes. Please wait...")
self.gFr.Center()
# Start the worker thread
workThread = threading.Thread(target=self.doWork)
workThread.start()
self.gFr.ShowModal()
def doWork(self):
"""
Performs time-consuming tasks and updates the progress dialog.
This method runs in a separate thread, simulating a long-running process by
sleeping for a short duration in a loop. It updates the progress dialog with
the current progress and checks if the user has requested to cancel the operation.
Parameters:
None
Returns:
None
"""
for i in range(0, 100):
time.sleep(0.05)
if not self.gFr.keepCalculating:
break
wx.CallAfter(self.gFr.UpdateValue, i+1)
wx.CallAfter(self.gFr.Destroy)
wx.CallAfter(self.Destroy)
# Initialize the application
app = wx.App(False)
fr = MainFrame(None, -1, "Title")
app.MainLoop()