Skip to content

Commit

Permalink
refactor: make on_title callback use weakref to avoid memory leaks
Browse files Browse the repository at this point in the history
refactor: use headless-kivy-pi 0.6.0
  • Loading branch information
sassanh committed Mar 25, 2024
1 parent 2c522ab commit d64cfab
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 82 deletions.
46 changes: 26 additions & 20 deletions .github/workflows/integration_delivery.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ jobs:
- uses: actions/checkout@v4
name: Checkout

- name: Save Cached Poetry
id: cached-poetry
uses: actions/cache@v4
with:
path: |
~/.cache
~/.local
key: poetry-${{ hashFiles('poetry.lock') }}

- uses: actions/setup-python@v5
name: Setup Python
with:
Expand All @@ -30,15 +39,6 @@ jobs:
- name: Install dependencies
run: poetry install --extras=dev --with dev

- name: Save Cached Poetry
id: cached-poetry
uses: actions/cache/save@v4
with:
path: |
~/.cache
~/.local
key: poetry-0

type-check:
name: Type Check
needs:
Expand All @@ -61,7 +61,7 @@ jobs:
path: |
~/.cache
~/.local
key: poetry-0
key: poetry-${{ hashFiles('poetry.lock') }}

- name: Create stub files
run: poetry run pyright --createstub kivy
Expand Down Expand Up @@ -91,7 +91,7 @@ jobs:
path: |
~/.cache
~/.local
key: poetry-0
key: poetry-${{ hashFiles('poetry.lock') }}

- name: Lint
run: poetry run poe lint
Expand All @@ -102,7 +102,8 @@ jobs:
- dependencies
runs-on: ubuntu-latest
outputs:
ubo_app_version: ${{ steps.extract_version.outputs.ubo_app_version }}
version: ${{ steps.extract_version.outputs.version }}
name: ${{ steps.extract_version.outputs.name }}
steps:
- uses: actions/checkout@v4
name: Checkout
Expand All @@ -122,15 +123,16 @@ jobs:
path: |
~/.cache
~/.local
key: poetry-0
key: poetry-${{ hashFiles('poetry.lock') }}

- name: Build
run: poetry build

- name: Extract Version
id: extract_version
run: |
echo "ubo_app_version=$(poetry run python scripts/print_version.py)" >> "$GITHUB_OUTPUT"
echo "version=$(poetry version --short)" >> "$GITHUB_OUTPUT"
echo "name=$(poetry version | cut -d' ' -f1)" >> "$GITHUB_OUTPUT"
- name: Upload wheel
uses: actions/upload-artifact@v4
Expand All @@ -156,8 +158,8 @@ jobs:
- build
runs-on: ubuntu-latest
environment:
name: PyPI
url: https://pypi.org/p/ubo-app
name: release
url: https://pypi.org/p/${{ needs.build.outputs.name }}
permissions:
id-token: write
steps:
Expand All @@ -176,6 +178,7 @@ jobs:
with:
packages-dir: dist
verbose: true
skip-existing: true

release:
name: Release
Expand All @@ -184,6 +187,9 @@ jobs:
- lint
- build
- pypi-publish
environment:
name: release
url: https://pypi.org/p/${{ needs.build.outputs.name }}
runs-on: ubuntu-latest
permissions:
contents: write
Expand All @@ -202,12 +208,12 @@ jobs:
path: artifacts

- name: Release
uses: softprops/action-gh-release@v1
uses: softprops/action-gh-release@v2
with:
files: artifacts/*
tag_name: ${{ needs.build.outputs.ubo_app_version }}
tag_name: v${{ needs.build.outputs.version }}
body: |
Release of version ${{ needs.build.outputs.ubo_app_version }}
PyPI package: https://pypi.org/project/ubo-app/${{ needs.build.outputs.ubo_app_version }}
Release of version ${{ needs.build.outputs.version }}
PyPI package: https://pypi.org/project/${{ needs.build.outputs.name }}/${{ needs.build.outputs.version }}
prerelease: false
draft: false
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.9.6

- refactor: use headless-kivy-pi 0.6.0
- refactor: make `on_title` callback use weakref to avoid memory leaks

## Version 0.9.5

- chore: use git-lfs to track material font
Expand Down
56 changes: 28 additions & 28 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 5 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
[tool.poetry]
name = "ubo-gui"
version = "0.9.5"
version = "0.9.6"
description = "GUI sdk for Ubo Pod"
authors = ["Sassan Haradji <[email protected]>"]
license = "Apache-2.0"
readme = "README.md"
packages = [{ include = "ubo_gui" }]
include = ['ubo_gui/assets/fonts/*']


[[tool.poetry.source]]
name = "PyPI"
priority = "primary"


[tool.poetry.dependencies]
python = "^3.11"
headless-kivy-pi = [
{ version = "^0.5.3", markers = "extra=='default'", extras = [
{ version = "^0.6.0", markers = "extra=='default'", extras = [
'default',
] },
{ version = "^0.5.3", markers = "extra=='dev'", extras = [
{ version = "^0.6.0", markers = "extra=='dev'", extras = [
'dev',
] },
]
Expand All @@ -30,8 +24,9 @@ python-immutable = "^1.0.2"
optional = true

[tool.poetry.group.dev.dependencies]
poethepoet = "^0.24.4"
pyright = "^1.1.349"
ruff = "^0.2.1"
ruff = "^0.2.2"

[tool.poetry.extras]
dev = ['headless-kivy-pi']
Expand Down
27 changes: 15 additions & 12 deletions ubo_gui/app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,23 +70,26 @@ def central(self: UboApp) -> Widget | None:
"""The central section of the app."""
return None

def title_callback(self: UboApp, _: RootWidget, title: str) -> None:
"""Update the header label when the title changes."""
if not self:
return
header_layout: BoxLayout = self.root.ids.header_layout
if title is not None:
self.header_label.text = title
header_layout.height = dp(30)
else:
self.header_label.text = ''
header_layout.height = 0

@cached_property
def header(self: UboApp) -> Widget | None:
"""The header section of the app."""
header_label = Label(text=self.root.title or '')

def title_callback(_: RootWidget, title: str) -> None:
header_layout: BoxLayout = self.root.ids.header_layout
if title is not None:
header_label.text = title
header_layout.height = dp(30)
else:
header_label.text = ''
header_layout.height = 0
self.header_label = Label(text=self.root.title or '')

self.root.bind(title=title_callback)
self.root.bind(title=self.title_callback)

return header_label
return self.header_label

@cached_property
def footer(self: UboApp) -> Widget | None:
Expand Down
8 changes: 6 additions & 2 deletions ubo_gui/menu/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,9 @@ def go_back(self: MenuWidget) -> None:
"""Go back to the previous menu."""
if self.current_application and self.current_application.go_back():
return
HeadlessWidget.activate_high_fps_mode()
headless_widget = HeadlessWidget.get_instance(self)
if headless_widget:
headless_widget.activate_high_fps_mode()
self.pop()

def render_items(self: MenuWidget, *_: object) -> None:
Expand Down Expand Up @@ -412,7 +414,9 @@ def set_current_screen(self: MenuWidget, screen: Screen) -> bool:

def open_application(self: MenuWidget, application: PageWidget) -> None:
"""Open an application."""
HeadlessWidget.activate_high_fps_mode()
headless_widget = HeadlessWidget.get_instance(self)
if headless_widget:
headless_widget.activate_high_fps_mode()
self.push(
application,
transition=self._swap_transition,
Expand Down
Loading

0 comments on commit d64cfab

Please sign in to comment.