Skip to content

Commit

Permalink
fix(menu): avoid closing all applications when a single application i…
Browse files Browse the repository at this point in the history
…s closed
  • Loading branch information
sassanh committed Apr 14, 2024
1 parent f4d921e commit 29fe8ef
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Version 0.10.4

- fix(menu): avoid closing all applications when a single application is closed

## Version 0.10.3

- feat(menu): add placeholder for the menu when it's empty
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "ubo-gui"
version = "0.10.3"
version = "0.10.4"
description = "GUI sdk for Ubo Pod"
authors = ["Sassan Haradji <[email protected]>"]
license = "Apache-2.0"
Expand Down
21 changes: 14 additions & 7 deletions ubo_gui/menu/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,20 +447,30 @@ def open_application(self: MenuWidget, application: PageWidget) -> None:
direction='left',
)
application.bind(on_close=self.close_application)
application.bind(on_leave=self.leave_application)

def clean_application(self: MenuWidget, application: PageWidget) -> None:
"""Clean up the application bounds."""
application.unbind(on_close=self.close_application)
application.unbind(on_leave=self.leave_application)

def close_application(self: MenuWidget, application: PageWidget) -> None:
"""Close an application after its `on_close` event is fired."""
self.clean_application(application)
while any(
isinstance(item, StackApplicationItem) and item.application is application
for item in self.stack
):
self.go_back()

def leave_application(self: MenuWidget, application: PageWidget) -> None:
"""Close an application after its `on_close` event is fired."""
if any(
isinstance(item, StackApplicationItem) and item.application is application
for item in self.stack
):
return
application.dispatch('on_close')

@property
def top(self: MenuWidget) -> StackItem:
"""Return the top item of the stack."""
Expand Down Expand Up @@ -537,14 +547,11 @@ def pop(
*self.stack, popped = self.stack
if not keep_subscriptions and isinstance(popped, StackMenuItem):
popped.clear_subscriptions()
elif isinstance(popped, StackApplicationItem):
self.clean_application(popped.application)
target = self.top
transition_ = self._slide_transition
if isinstance(target, PageWidget):
transition_ = self._swap_transition
if self.current_application:
self.clean_application(self.current_application)
elif self.current_application:
self.clean_application(self.current_application)
if isinstance(target, PageWidget) or self.current_application:
transition_ = self._swap_transition
self._switch_to(
self.current_screen,
Expand Down
5 changes: 0 additions & 5 deletions ubo_gui/page/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,3 @@ def get_item(self: PageWidget, index: int) -> Item | None:

def on_close(self: PageWidget) -> None:
"""Signal when the page is closed."""

def on_leave(self: PageWidget, *args: object) -> None:
"""Override `on_leave` to dispatch `on_close` event."""
self.dispatch('on_close')
return super().on_leave(*args)

0 comments on commit 29fe8ef

Please sign in to comment.