Skip to content

Commit

Permalink
fix(menu): not assume the return value of the action in ActionItem
Browse files Browse the repository at this point in the history
…is a `Menu` if it is not an `application`
  • Loading branch information
sassanh committed Apr 19, 2024
1 parent d8b16c3 commit 9a85194
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 122 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.10.7

- fix(menu): not assume the return value of the action in `ActionItem` is a `Menu`
if it is not an `application`

## Version 0.10.6

- feat: info action for the `NotificationWidget`
Expand Down
218 changes: 109 additions & 109 deletions poetry.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "ubo-gui"
version = "0.10.6"
version = "0.10.7"
description = "GUI sdk for Ubo Pod"
authors = ["Sassan Haradji <[email protected]>"]
license = "Apache-2.0"
Expand All @@ -26,8 +26,8 @@ optional = true

[tool.poetry.group.dev.dependencies]
poethepoet = "^0.24.4"
pyright = "^1.1.355"
ruff = "^0.3.4"
pyright = "^1.1.359"
ruff = "^0.4.1"

[tool.poetry.extras]
dev = ['headless-kivy-pi']
Expand Down
2 changes: 2 additions & 0 deletions ubo_gui/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
SECONDARY_COLOR = '#363F4B'
TEXT_COLOR = '#FFFFFF'

INFO_COLOR = '#2196F3'
DANGER_COLOR = '#FF3F51'
WARNING_COLOR = '#FFC107'
SUCCESS_COLOR = '#03F7AE'

Builder.load_string(
Expand Down
11 changes: 5 additions & 6 deletions ubo_gui/menu/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,8 @@ def select_action_item(self: MenuWidget, item: ActionItem) -> None:
if not result:
return
if isinstance(result, type) and issubclass(result, PageWidget):
application_instance = result(name=uuid.uuid4().hex)
self.open_application(application_instance)
else:
self.open_application(result())
elif isinstance(result, Menu):
self.open_menu(result)

def select_application_item(self: MenuWidget, item: ApplicationItem) -> None:
Expand All @@ -243,8 +242,7 @@ def handle_application_change(application: type[PageWidget]) -> None:
)
if application_instance:
self.close_application(application_instance)
application_instance = application(name=uuid.uuid4().hex)
self.open_application(application_instance)
self.open_application(application())

subscription = process_subscribable_value(
item.application,
Expand Down Expand Up @@ -440,6 +438,7 @@ def open_application(self: MenuWidget, application: PageWidget) -> None:
headless_widget = HeadlessWidget.get_instance(self)
if headless_widget:
headless_widget.activate_high_fps_mode()
application.name = uuid.uuid4().hex
self.push(
application,
transition=self._swap_transition,
Expand Down Expand Up @@ -551,7 +550,7 @@ def pop(
self.clean_application(popped.application)
target = self.top
transition_ = self._slide_transition
if isinstance(target, PageWidget) or self.current_application:
if isinstance(target, StackApplicationItem) or self.current_application:
transition_ = self._swap_transition
self._switch_to(
self.current_screen,
Expand Down
16 changes: 12 additions & 4 deletions ubo_gui/notification/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
StringProperty,
)

from ubo_gui.constants import DANGER_COLOR
from ubo_gui.constants import DANGER_COLOR, INFO_COLOR
from ubo_gui.menu.types import ActionItem
from ubo_gui.page import PAGE_MAX_ITEMS, PageWidget

Expand Down Expand Up @@ -45,12 +45,16 @@ def get_info_action(self: NotificationWidget) -> ActionItem | None:
"""Return the info action if `info` is available."""
if not self.has_extra_information:
return None

def dispatch_info() -> None:
self.dispatch('on_info')

return ActionItem(
icon='󰋼',
action=lambda: self.dispatch('on_info'),
action=dispatch_info,
label='',
is_short=True,
background_color=DANGER_COLOR,
background_color=INFO_COLOR,
)

info_action: ActionItem = AliasProperty(
Expand All @@ -65,9 +69,13 @@ def __init__(
**kwargs: object,
) -> None:
"""Create a new `NotificationWidget` object."""

def dispatch_dismiss() -> None:
self.dispatch('on_dismiss')

self.dismiss_action = ActionItem(
icon='󰆴',
action=lambda: self.dispatch('on_dismiss') and None,
action=dispatch_dismiss,
label='',
is_short=True,
background_color=DANGER_COLOR,
Expand Down

0 comments on commit 9a85194

Please sign in to comment.