@@ -57,6 +57,11 @@ def start_detection(self):
57
57
# Detect blinks in the filtered signal
58
58
self .detect_blinks (filtered_eog )
59
59
60
+ def quit_detection (self ):
61
+ # Quit the detection loop
62
+ print ("Quitting peak detection..." )
63
+ self .running = False
64
+
60
65
def stop_detection (self ):
61
66
# Stop the detection loop
62
67
print ("Stopping peak detection..." )
@@ -102,10 +107,10 @@ def update_button_color(self):
102
107
time .sleep (0.1 )
103
108
self .blink_button .config (bg = "SystemButtonFace" )
104
109
105
- def stop_action (detector ):
110
+ def quit_action (detector ):
106
111
# Action for the Quit button
107
112
print ("Quit button pressed. Exiting program." )
108
- detector .stop_detection ()
113
+ detector .quit_detection ()
109
114
exit ()
110
115
111
116
def keystroke_action ():
@@ -119,6 +124,25 @@ def start_action(detector):
119
124
detection_thread = threading .Thread (target = detector .start_detection , daemon = True )
120
125
detection_thread .start ()
121
126
127
+ def stop_action (detector ):
128
+ # Action for the Start button
129
+ print ("Stop button pressed. Stopping the program." )
130
+ detection_thread = threading .Thread (target = detector .stop_detection , daemon = True )
131
+ detection_thread .stop ()
132
+
133
+ def toggle_action (detector , start_button ):
134
+ # Toggle between Start and Stop
135
+ if start_button .cget ("text" ) == "Start" :
136
+ print ("Start button pressed. Starting the program." )
137
+ start_button .config (text = "Stop" )
138
+ detector .running = True
139
+ detection_thread = threading .Thread (target = detector .start_detection , daemon = True )
140
+ detection_thread .start ()
141
+ else :
142
+ print ("Stop button pressed. Stopping the program." )
143
+ start_button .config (text = "Start" )
144
+ detector .stop_detection ()
145
+
122
146
def create_popup ():
123
147
# Create the main GUI window
124
148
popup = tk .Tk ()
@@ -134,20 +158,20 @@ def create_popup():
134
158
blink_button = tk .Button (horizontal_frame , text = "Blink Detected" , width = 12 )
135
159
blink_button .pack (side = tk .LEFT , padx = 10 )
136
160
137
- # Add Start button
161
+ # Add Start/Stop button
138
162
start_button = tk .Button (horizontal_frame , text = "Start" , width = 8 )
139
163
start_button .pack (side = tk .LEFT , padx = 10 )
140
164
141
165
# Add Quit button
142
- stop_button = tk .Button (horizontal_frame , text = "Quit" , width = 8 )
143
- stop_button .pack (side = tk .LEFT , padx = 10 )
166
+ quit_button = tk .Button (horizontal_frame , text = "Quit" , width = 8 )
167
+ quit_button .pack (side = tk .LEFT , padx = 10 )
144
168
145
169
# Initialize the EOG peak detector
146
170
detector = EOGPeakDetector (blink_button , keystroke_action )
147
171
148
- # Link Start and Stop buttons to their respective actions
149
- start_button .config (command = lambda : start_action (detector ))
150
- stop_button .config (command = lambda : stop_action (detector ))
172
+ # Link Start/Stop button and Quit button to their respective actions
173
+ start_button .config (command = lambda : toggle_action (detector , start_button ))
174
+ quit_button .config (command = lambda : quit_action (detector ))
151
175
152
176
popup .mainloop ()
153
177
0 commit comments