Skip to content

Commit

Permalink
refactor(MenuWidget): dispatch on_close event on the PageWidget i…
Browse files Browse the repository at this point in the history
…nstance when it is closed, to close a `PageWidget` instance, one should call `close_application`
  • Loading branch information
sassanh committed May 7, 2024
1 parent ac8f541 commit 2ec1f20
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 23 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## Version 0.11.6

- refactor(MenuWidget): dispatch `on_close` event on the `PageWidget` instance when
it is closed, to close a `PageWidget` instance, one should call `close_application`

## Version 0.11.5

- fix(MenuWidget): avoid opening an `ActionItem`'s `action` return value twice if
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.11.5"
version = "0.11.6"
description = "GUI sdk for Ubo Pod"
authors = ["Sassan Haradji <sassanh@gmail.com>"]
license = "Apache-2.0"
Expand Down
26 changes: 4 additions & 22 deletions ubo_gui/menu/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,15 +535,6 @@ def open_application(self: MenuWidget, application: PageWidget) -> None:
duration=0.2,
direction='left',
)
application.bind(
on_close=self.close_application,
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."""
Expand All @@ -567,7 +558,7 @@ def close_application(self: MenuWidget, application: PageWidget) -> None:

for item in to_be_removed:
item.clear_subscriptions()
self.clean_application(item.application)
item.application.dispatch('on_close')

self.stack = [item for item in self.stack if item not in to_be_removed]

Expand All @@ -577,15 +568,6 @@ def close_application(self: MenuWidget, application: PageWidget) -> None:
):
self.pop()

def leave_application(self: MenuWidget, application: PageWidget) -> None:
"""Close an application after its `on_leave` 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 @@ -660,10 +642,10 @@ def pop(
if self.depth == 1:
return
*self.stack, popped = self.stack
if not keep_subscriptions and isinstance(popped, StackMenuItem):
if not keep_subscriptions:
popped.clear_subscriptions()
elif isinstance(popped, StackApplicationItem):
self.clean_application(popped.application)
if isinstance(popped, StackApplicationItem):
popped.application.dispatch('on_close')
target = self.top
transition_ = self._slide_transition
if isinstance(target, StackApplicationItem) or self.current_application:
Expand Down

0 comments on commit 2ec1f20

Please sign in to comment.