From 29a0d3db615ea70fe7c837f726aba353fcd0bbd4 Mon Sep 17 00:00:00 2001 From: Sassan Haradji Date: Fri, 12 Jul 2024 05:40:38 +0400 Subject: [PATCH] fix: avoid user selecting a second item while the screen is being transitioned --- CHANGELOG.md | 1 + ubo_gui/menu/__init__.py | 4 +++- ubo_gui/menu/transitions.py | 3 +++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d917528..843964d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Version 0.11.17 - feat: add `_visual_snapshot` to visualize the state of stack for debugging purposes +- fix: avoid user selecting a second item while the screen is being transitioned ## Version 0.11.16 diff --git a/ubo_gui/menu/__init__.py b/ubo_gui/menu/__init__.py index c87564a..d8e27ee 100644 --- a/ubo_gui/menu/__init__.py +++ b/ubo_gui/menu/__init__.py @@ -352,7 +352,9 @@ def select(self: MenuWidget, index: int) -> None: if not self.screen_manager.current_screen: warnings.warn('`current_screen` is `None`', RuntimeWarning, stacklevel=1) return - current_page = cast(PageWidget, self.screen_manager.current_screen) + if self._is_preparation_in_progress: + return + current_page = cast(PageWidget, self.current_screen) item = current_page.get_item(index) if item: self.select_item(item) diff --git a/ubo_gui/menu/transitions.py b/ubo_gui/menu/transitions.py index 4c55453..d765ccb 100644 --- a/ubo_gui/menu/transitions.py +++ b/ubo_gui/menu/transitions.py @@ -35,6 +35,7 @@ class TransitionsMixin: ] screen_manager: ScreenManager _is_transition_in_progress: bool = False + _is_preparation_in_progress: bool = False _transition_progress_lock: threading.Lock def __init__(self: TransitionsMixin, **kwargs: dict[str, Any]) -> None: @@ -130,6 +131,7 @@ def _perform_switch( duration=duration, **({} if direction is None else {'direction': direction}), ) + self._is_preparation_in_progress = False def _switch_to( self: TransitionsMixin, @@ -150,6 +152,7 @@ def _switch_to( if headless_widget: headless_widget.activate_high_fps_mode() self._is_transition_in_progress = transition is not self._no_transition + self._is_preparation_in_progress = True self._perform_switch( screen, transition=transition,