Skip to content

Commit

Permalink
chore: update to the latest version of headless-kivy which drops fps …
Browse files Browse the repository at this point in the history
…control
  • Loading branch information
sassanh committed Oct 26, 2024
1 parent 7cfe508 commit c078194
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 37 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- chore: migrate from poetry to uv for the sake of improving performance and dealing with conflicting sub-dependencies
- feat: add spinner widget which doesn't trigger whole screen renders and uses new local renders of headless-kivy
- chore: update to the latest version of headless-kivy which drops fps control

## Version 0.13.3

Expand Down
10 changes: 0 additions & 10 deletions ubo_gui/menu/_transitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from functools import cached_property
from typing import Any, NotRequired, TypedDict

from headless_kivy import HeadlessWidget
from kivy.clock import mainthread
from kivy.uix.screenmanager import (
NoTransition,
Expand All @@ -17,7 +16,6 @@
SwapTransition,
TransitionBase,
)
from kivy.uix.widget import Widget


class SwitchParameters(TypedDict):
Expand Down Expand Up @@ -80,10 +78,6 @@ def _handle_transition_complete(
**switch_parameters,
)
else:
if isinstance(self, Widget):
headless_widget = HeadlessWidget.get_instance(self)
if headless_widget:
headless_widget.activate_low_fps_mode()
self._is_transition_in_progress = False

def _setup_transition(self: TransitionsMixin, transition: TransitionBase) -> None:
Expand Down Expand Up @@ -155,10 +149,6 @@ def _switch_to(
(screen, transition, direction, duration),
]
else:
if isinstance(self, Widget):
headless_widget = HeadlessWidget.get_instance(self)
if headless_widget:
headless_widget.activate_high_fps_mode()
self._is_transition_in_progress = transition is not self._no_transition
self._is_preparation_in_progress = True
self._perform_switch(
Expand Down
4 changes: 0 additions & 4 deletions ubo_gui/menu/menu_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import warnings
from typing import TYPE_CHECKING, cast, overload

from headless_kivy import HeadlessWidget
from kivy.clock import mainthread
from kivy.lang.builder import Builder
from kivy.properties import (
Expand Down Expand Up @@ -544,9 +543,6 @@ def set_current_screen(self: MenuWidget, screen: Screen) -> bool:
def open_application(self: MenuWidget, application: PageWidget) -> None:
"""Open an application."""
with self.stack_lock:
headless_widget = HeadlessWidget.get_instance(self)
if headless_widget:
headless_widget.activate_high_fps_mode()
application.name = uuid.uuid4().hex
application.padding_bottom = self.padding_bottom
application.padding_top = self.padding_top
Expand Down
35 changes: 12 additions & 23 deletions ubo_gui/spinner/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,36 @@

from __future__ import annotations

import math
import pathlib
from typing import Any, cast

from headless_kivy import HeadlessWidget
from kivy.clock import Clock
from kivy.graphics.context_instructions import Rotate
from kivy.lang.builder import Builder
from kivy.properties import NumericProperty
from kivy.uix.label import Label


class SpinnerWidget(HeadlessWidget):
class SpinnerWidget(HeadlessWidget, Label):
"""Spinner widget for loading indication."""

angle = NumericProperty(0)

def __init__(self: SpinnerWidget, **kwargs: object) -> None:
"""Initialize the SpinnerWidget class."""
super().__init__(**cast(Any, kwargs))
self.interval = Clock.schedule_interval(self.rotate_spinner, 1 / 40)
self.label = Label(
text='',
color=(1, 1, 1),
)
self.label.bind(texture_size=self.label.setter('size'))
self.bind(
size=lambda *_: self.label.setter('center')(
self.label,
(self.width / 2, self.height / 2),
),
)
self.add_widget(self.label)
self.interval = Clock.schedule_interval(self.rotate_spinner, 1 / 60)

def __del__(self: SpinnerWidget) -> None:
"""Remove the spinner widget."""
"""Cancel the interval when the widget is deleted."""
self.interval.cancel()

def rotate_spinner(self: SpinnerWidget, dt: float) -> None:
"""Rotate the spinner."""
self.angle = (self.angle + dt) % math.tau
with self.label.canvas.before:
Rotate(
angle=-dt * 400,
origin=self.label.center,
)
self.angle -= dt * 500
self.angle %= 360


Builder.load_file(
pathlib.Path(__file__).parent.joinpath('spinner_widget.kv').resolve().as_posix(),
)
16 changes: 16 additions & 0 deletions ubo_gui/spinner/spinner_widget.kv
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#:kivy 2.3.0

<SpinnerWidget>:
Label:
text: ''
size: print(root.size) or root.size

canvas.before:
PushMatrix

Rotate:
angle: root.angle
origin: self.center

canvas.after:
PopMatrix

0 comments on commit c078194

Please sign in to comment.