diff --git a/CHANGELOG.md b/CHANGELOG.md index 80f2842..4b0b87f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## Version 0.11.4 + +- refactor(NotificationWidget): remove all the logic and make it solely a view + ## Version 0.11.3 - feat(Menu): action items can now return not only the application class, but also diff --git a/pyproject.toml b/pyproject.toml index 520c3d2..935deaf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "ubo-gui" -version = "0.11.3" +version = "0.11.4" description = "GUI sdk for Ubo Pod" authors = ["Sassan Haradji "] license = "Apache-2.0" diff --git a/ubo_gui/notification/__init__.py b/ubo_gui/notification/__init__.py index b263040..6e72a69 100644 --- a/ubo_gui/notification/__init__.py +++ b/ubo_gui/notification/__init__.py @@ -3,89 +3,22 @@ from __future__ import annotations import pathlib -from typing import TYPE_CHECKING, Callable -from immutable import Immutable from kivy.lang.builder import Builder from kivy.metrics import dp -from kivy.properties import ( - AliasProperty, - BooleanProperty, - ColorProperty, - StringProperty, -) - -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 - -if TYPE_CHECKING: - from ubo_gui.menu.types import Item - +from kivy.properties import ColorProperty, StringProperty -class NotificationAction(Immutable): - """A notification action.""" - - title: str - callback: Callable +from ubo_gui.page import PageWidget class NotificationWidget(PageWidget): """renders a notification.""" - __events__ = ('on_dismiss', 'on_info') - notification_title: str = StringProperty() content: str = StringProperty() - has_extra_information: bool = BooleanProperty(defaultvalue=False) icon: str = StringProperty() color = ColorProperty() - 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=dispatch_info, - label='', - is_short=True, - background_color=INFO_COLOR, - ) - - info_action: ActionItem = AliasProperty( - getter=get_info_action, - bind=['has_extra_information'], - cache=True, - ) - - def __init__( - self: NotificationWidget, - *args: object, - **kwargs: object, - ) -> None: - """Create a new `NotificationWidget` object.""" - - def dispatch_dismiss() -> None: - self.dispatch('on_dismiss') - - self.dismiss_action = ActionItem( - icon='󰆴', - action=dispatch_dismiss, - label='', - is_short=True, - background_color=DANGER_COLOR, - ) - super().__init__( - *args, - items=[], - **kwargs, - ) - def go_down(self: NotificationWidget) -> None: """Scroll down the notification list.""" self.ids.slider.animated_value -= dp(50) @@ -94,20 +27,6 @@ def go_up(self: NotificationWidget) -> None: """Scroll up the notification list.""" self.ids.slider.animated_value += dp(50) - def get_item(self: NotificationWidget, index: int) -> Item | None: - """Get the page item at the given index.""" - if index == PAGE_MAX_ITEMS - 2: - return self.info_action - if index == PAGE_MAX_ITEMS - 1: - return self.dismiss_action - return None - - def on_dismiss(self: PageWidget) -> None: - """Signal when the notification is dismissed.""" - - def on_info(self: PageWidget) -> None: - """Signal when the info action is selected.""" - Builder.load_file( pathlib.Path(__file__) diff --git a/ubo_gui/notification/notification_widget.kv b/ubo_gui/notification/notification_widget.kv index f3a6d61..d42310a 100644 --- a/ubo_gui/notification/notification_widget.kv +++ b/ubo_gui/notification/notification_widget.kv @@ -13,11 +13,15 @@ spacing: dp(UBO_GUI_MENU_ITEM_GAP) ItemWidget: - item: root.info_action + item: root.items[0] size_hint: 1, None ItemWidget: - item: root.dismiss_action + item: root.items[1] + size_hint: 1, None + + ItemWidget: + item: root.items[2] size_hint: 1, None StencilView: @@ -72,7 +76,7 @@ AnchorLayout: size_hint: (None, 1) if scrollable_widget.height - container.height else (None, None) - width: dp(UBO_GUI_SHORT_WIDTH - 2) + width: dp(UBO_GUI_SHORT_WIDTH) AnimatedSlider: id: slider