Skip to content

Commit

Permalink
feat(core): notifications now can have an optional `extra_information…
Browse files Browse the repository at this point in the history
…` field which will cause the notification widget to render an info icon which opens a separate screen to render the extra information
  • Loading branch information
sassanh committed Apr 15, 2024
1 parent 6301683 commit ea2b47b
Show file tree
Hide file tree
Showing 16 changed files with 216 additions and 162 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Version 0.12.6

- feat(core): notifications now can have an optional `extra_information` field which
will cause the notification widget to render an info icon which opens a separate
screen to render the extra information

## Version 0.12.5

- fix(notification): avoid passing color components bigger than 255
Expand Down
184 changes: 92 additions & 92 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-app"
version = "0.12.5"
version = "0.12.6"
description = "Ubo main app, running on device initialization. A platform for running other apps."
authors = ["Sassan Haradji <[email protected]>"]
license = "Apache-2.0"
Expand All @@ -18,10 +18,10 @@ priority = "primary"
python = "^3.11"
psutil = "^5.9.8"
ubo-gui = [
{ version = "^0.10.5", markers = "extra=='default'", extras = [
{ version = "^0.10.6", markers = "extra=='default'", extras = [
"default",
] },
{ version = "^0.10.5", markers = "extra=='dev'", extras = [
{ version = "^0.10.6", markers = "extra=='dev'", extras = [
"dev",
] },
]
Expand Down
2 changes: 1 addition & 1 deletion tests/end_to_end/test_wireless_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async def test_wireless_flow(
) -> None:
"""Test the wireless flow."""
_ = needs_finish
from ubo_app.menu import MenuApp
from ubo_app.menu_app.menu import MenuApp
from ubo_app.store import dispatch, store
from ubo_app.store.services.camera import CameraStartViewfinderAction
from ubo_app.store.services.keypad import Key, KeypadKeyPressAction
Expand Down
3 changes: 2 additions & 1 deletion tests/fixtures/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

from _pytest.fixtures import SubRequest

from ubo_app.menu import MenuApp
from ubo_app.menu_app.menu import MenuApp

modules_snapshot = set(sys.modules)

Expand Down Expand Up @@ -99,6 +99,7 @@ async def app_context(request: SubRequest) -> AsyncGenerator[AppContext, None]:

os.environ['KIVY_NO_FILELOG'] = '1'
os.environ['KIVY_NO_CONSOLELOG'] = '1'
os.environ['KIVY_METRICS_DENSITY'] = '1'

setup()

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ async def test_app_runs_and_exits(
) -> None:
"""Test the application starts, runs and quits."""
_ = needs_finish
from ubo_app.menu import MenuApp
from ubo_app.menu_app.menu import MenuApp

app = MenuApp()

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async def test_all_services_register(
) -> None:
"""Test all services load."""
_ = needs_finish
from ubo_app.menu import MenuApp
from ubo_app.menu_app.menu import MenuApp

app = MenuApp()
app_context.set_app(app)
Expand Down
2 changes: 1 addition & 1 deletion ubo_app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def main() -> None:
headless_kivy_pi.config.setup_headless_kivy({'automatic_fps': True})

from ubo_app.load_services import load_services
from ubo_app.menu import MenuApp
from ubo_app.menu_app.menu import MenuApp

load_services()
app = MenuApp()
Expand Down
File renamed without changes.
72 changes: 72 additions & 0 deletions ubo_app/menu_app/home_page.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# ruff: noqa: D100, D101, D102, D103, D104, D107
from __future__ import annotations

from functools import cached_property
from typing import TYPE_CHECKING

from kivy.clock import Clock
from ubo_gui.gauge import GaugeWidget
from ubo_gui.page import PageWidget
from ubo_gui.volume import VolumeWidget

from ubo_app.store import autorun

if TYPE_CHECKING:
from collections.abc import Sequence

from ubo_gui.menu.types import Item


class HomePage(PageWidget):
def __init__(
self: HomePage,
items: Sequence[Item] | None = None,
*args: object,
**kwargs: object,
) -> None:
super().__init__(items, *args, **kwargs)

self.ids.central_column.add_widget(self.cpu_gauge)
self.ids.central_column.add_widget(self.ram_gauge)

self.volume_widget = VolumeWidget()
self.ids.right_column.add_widget(self.volume_widget)

autorun(lambda state: state.sound.playback_volume)(self._sync_output_volume)

def _sync_output_volume(self: HomePage, selector_result: float) -> None:
self.volume_widget.value = selector_result * 100

@cached_property
def cpu_gauge(self: HomePage) -> GaugeWidget:
import psutil

gauge = GaugeWidget(
value=psutil.cpu_percent(percpu=False),
fill_color='#24D636',
label='CPU',
)

def set_value(_: int) -> None:
gauge.value = psutil.cpu_percent(percpu=False)

Clock.schedule_interval(set_value, 1)

return gauge

@cached_property
def ram_gauge(self: HomePage) -> GaugeWidget:
import psutil

gauge = GaugeWidget(
value=psutil.virtual_memory().percent,
fill_color='#D68F24',
label='RAM',
)

def set_value(_: int) -> None:
gauge.value = psutil.virtual_memory().percent

Clock.schedule_interval(set_value, 1)

return gauge
File renamed without changes.
76 changes: 14 additions & 62 deletions ubo_app/menu_central.py → ubo_app/menu_app/menu_central.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@
from kivy.clock import Clock, mainthread
from kivy.lang.builder import Builder
from ubo_gui.app import UboApp
from ubo_gui.gauge import GaugeWidget
from ubo_gui.menu import MenuWidget
from ubo_gui.notification import NotificationWidget
from ubo_gui.page import PageWidget
from ubo_gui.volume import VolumeWidget

from ubo_app.menu_app.notification_info import NotificationInfo
from ubo_app.store import autorun, dispatch, subscribe_event
from ubo_app.store.main import SetMenuPathAction
from ubo_app.store.services.keypad import Key, KeypadKeyPressEvent
from ubo_app.store.services.notifications import (
Expand All @@ -24,68 +23,12 @@
NotificationsDisplayEvent,
)

from .store import autorun, dispatch, subscribe_event
from .home_page import HomePage

if TYPE_CHECKING:
from collections.abc import Sequence

from kivy.uix.widget import Widget
from ubo_gui.menu.types import Item, Menu


class HomePage(PageWidget):
def __init__(
self: HomePage,
items: Sequence[Item] | None = None,
*args: object,
**kwargs: object,
) -> None:
super().__init__(items, *args, **kwargs)

self.ids.central_column.add_widget(self.cpu_gauge)
self.ids.central_column.add_widget(self.ram_gauge)

self.volume_widget = VolumeWidget()
self.ids.right_column.add_widget(self.volume_widget)

autorun(lambda state: state.sound.playback_volume)(self._sync_output_volume)

def _sync_output_volume(self: HomePage, selector_result: float) -> None:
self.volume_widget.value = selector_result * 100

@cached_property
def cpu_gauge(self: HomePage) -> GaugeWidget:
import psutil

gauge = GaugeWidget(
value=psutil.cpu_percent(percpu=False),
fill_color='#24D636',
label='CPU',
)

def set_value(_: int) -> None:
gauge.value = psutil.cpu_percent(percpu=False)

Clock.schedule_interval(set_value, 1)

return gauge

@cached_property
def ram_gauge(self: HomePage) -> GaugeWidget:
import psutil

gauge = GaugeWidget(
value=psutil.virtual_memory().percent,
fill_color='#D68F24',
label='RAM',
)

def set_value(_: int) -> None:
gauge.value = psutil.virtual_memory().percent

Clock.schedule_interval(set_value, 1)

return gauge
from ubo_gui.menu.types import Menu
from ubo_gui.page import PageWidget


class MenuWidgetWithHomePage(MenuWidget):
Expand Down Expand Up @@ -173,7 +116,9 @@ def display_notification(
content=notification.content,
icon=notification.icon,
color=notification.color,
has_extra_information=notification.extra_information is not None,
)
info_application = NotificationInfo(text=notification.extra_information)

application.bind(
on_dismiss=lambda _: (
Expand All @@ -184,6 +129,10 @@ def display_notification(
),
)

application.bind(
on_info=lambda _: self.menu_widget.open_application(info_application),
)

self.menu_widget.open_application(application)

if notification.display_type is NotificationDisplayType.FLASH:
Expand All @@ -196,3 +145,6 @@ def display_notification(
Builder.load_file(
pathlib.Path(__file__).parent.joinpath('home_page.kv').resolve().as_posix(),
)
Builder.load_file(
pathlib.Path(__file__).parent.joinpath('notification_info.kv').resolve().as_posix(),
)
File renamed without changes.
13 changes: 13 additions & 0 deletions ubo_app/menu_app/notification_info.kv
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#:kivy 2.2.1

<NotificationInfo>:
BoxLayout:
orientation: 'horizontal'
padding: dp(5)

Label:
text: root.text
text_size: self.size
halign: 'left'
valign: 'top'
size_hint: 1, 1
9 changes: 9 additions & 0 deletions ubo_app/menu_app/notification_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# ruff: noqa: D100, D101, D102, D103, D104, D107
from __future__ import annotations

from kivy.properties import StringProperty
from ubo_gui.page import PageWidget


class NotificationInfo(PageWidget):
text: str = StringProperty()
1 change: 1 addition & 0 deletions ubo_app/store/services/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class Notification(Immutable):
id: str = field(default_factory=lambda: uuid4().hex)
title: str
content: str
extra_information: str | None = None
importance: Importance = Importance.LOW
chime: Chime = Chime.DONE
timestamp: datetime = field(default_factory=lambda: datetime.now(tz=UTC))
Expand Down

0 comments on commit ea2b47b

Please sign in to comment.