Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: make on_title callback use weakref to avoid memory leaks #29

Merged
merged 1 commit into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 24 additions & 19 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 Down Expand Up @@ -185,6 +187,9 @@ jobs:
- build
- pypi-publish
runs-on: ubuntu-latest
environment:
name: release
url: https://pypi.org/p/${{ needs.build.outputs.name }}
permissions:
contents: write
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
Expand All @@ -205,9 +210,9 @@ jobs:
uses: softprops/action-gh-release@v1
with:
files: artifacts/*
tag_name: ${{ needs.build.outputs.ubo_app_version }}
tag_name: ${{ 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
Loading