Skip to content

Commit

Permalink
fix: avoid user selecting a second item while the screen is being tra…
Browse files Browse the repository at this point in the history
…nsitioned
  • Loading branch information
sassanh committed Jul 12, 2024
1 parent dc39d7c commit 312d052
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
22 changes: 11 additions & 11 deletions ubo_gui/menu/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -707,12 +709,9 @@ def _replace(
item: Menu | PageWidget,
) -> StackItem:
"""Replace the current menu or application."""
try:
item_index = self.stack.index(stack_item)
except ValueError:
if stack_item not in self.stack:
msg = '`stack_item` not found in stack'
raise ValueError(msg) from None
subscriptions = self.top.subscriptions.copy()
if isinstance(item, Menu):
new_item = StackMenuItem(
menu=item,
Expand All @@ -728,12 +727,13 @@ def _replace(
else:
msg = f'Unsupported type: {type(item)}'
raise TypeError(msg)
self.stack[item_index] = new_item
self.top.subscriptions = subscriptions
self._switch_to(
self.current_screen,
transition=self._no_transition,
)
new_item.subscriptions = stack_item.subscriptions
self.stack[self.stack.index(stack_item)] = new_item
if self.top is new_item:
self._switch_to(
self.current_screen,
transition=self._no_transition,
)
return new_item

@overload
Expand Down
3 changes: 3 additions & 0 deletions ubo_gui/menu/transitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 312d052

Please sign in to comment.