Skip to content

Commit 60a647e

Browse files
Copilotfsmosca
andcommitted
Debounce navigation buttons in review mode to prevent GUI freeze
When analysis is running and the user presses navigation buttons rapidly, stop the analysis immediately but defer restarting it until 300ms after the last button press. This avoids repeated blocking engine stop/start cycles that make the GUI unresponsive. Agent-Logs-Url: https://github.com/fsmosca/Python-Easy-Chess-GUI/sessions/71d680e7-f5da-483b-86f3-c7daf8a96f24 Co-authored-by: fsmosca <22366935+fsmosca@users.noreply.github.com>
1 parent 8541edb commit 60a647e

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

python_easy_chess_gui.py

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@
6969
BOX_TITLE = f'{APP_NAME} {APP_VERSION}'
7070
REVIEW_MAX_DISPLAY_GAMES = 10000
7171
REVIEW_ANALYSIS_MULTIPV_LINES = 3
72-
REVIEW_ANALYSIS_PV_MOVES = 7
72+
REVIEW_ANALYSIS_PV_MOVES = 7
73+
REVIEW_NAV_DEBOUNCE_SEC = 0.3
7374
REVIEW_MOVE_LIST_HEIGHT = 11
7475
REVIEW_ANALYSIS_BOX_HEIGHT = 4
7576

@@ -829,8 +830,9 @@ def reset_review_state(self):
829830
self.review_analysis_lines = [''] * REVIEW_ANALYSIS_MULTIPV_LINES
830831
self.review_analysis_enabled = False
831832
self.review_analysis_status = 'Analysis stopped'
832-
self.review_analysis_search = None
833-
self.review_analysis_engine = None
833+
self.review_analysis_search = None
834+
self.review_analysis_engine = None
835+
self.review_nav_last_time = 0
834836

835837
def update_game(self, mc: int, user_move: str, time_left: int, user_comment: str):
836838
"""Saves moves in the game.
@@ -3107,9 +3109,17 @@ def start_review_mode(self, window):
31073109
button, value = review_window.Read(timeout=50)
31083110
self.poll_review_analysis(review_window)
31093111

3110-
# Skip timeout events as analysis updates are processed by
3111-
# poll_review_analysis() called earlier in the loop.
3112-
if button == sg.TIMEOUT_KEY:
3112+
# Skip timeout events as analysis updates are processed by
3113+
# poll_review_analysis() called earlier in the loop.
3114+
if button == sg.TIMEOUT_KEY:
3115+
# Restart analysis after debounce delay following navigation.
3116+
if (self.review_nav_last_time
3117+
and self.review_analysis_enabled
3118+
and self.review_analysis_search is None
3119+
and time.time() - self.review_nav_last_time
3120+
>= REVIEW_NAV_DEBOUNCE_SEC):
3121+
self.review_nav_last_time = 0
3122+
self.start_review_analysis(review_window)
31133123
continue
31143124

31153125
if button is None:
@@ -3200,9 +3210,16 @@ def start_review_mode(self, window):
32003210
self.update_review_window(review_window)
32013211
continue
32023212

3203-
if position_changed:
3204-
self.update_review_window(review_window)
3205-
self.refresh_review_analysis(review_window)
3213+
if position_changed:
3214+
self.update_review_window(review_window)
3215+
if self.review_analysis_enabled:
3216+
self.stop_review_analysis()
3217+
self.review_nav_last_time = time.time()
3218+
self.review_analysis_lines = [''] * REVIEW_ANALYSIS_MULTIPV_LINES
3219+
self.review_analysis_status = 'Waiting...'
3220+
self.update_review_analysis_panel(review_window)
3221+
else:
3222+
self.refresh_review_analysis(review_window)
32063223

32073224
self.close_review_analysis()
32083225
review_window.Close()

0 commit comments

Comments
 (0)