Skip to content

Commit

Permalink
refactor: handle text field of SpinnerWidget when it contains kiv…
Browse files Browse the repository at this point in the history
…y markup but yet reduces to `` when markup is removed
  • Loading branch information
sassanh committed Oct 30, 2024
1 parent 72dabdd commit 757be8b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Upcoming

- refactor: handle `text` field of `SpinnerWidget` when it contains kivy markup but yet reduces to `` when markup is removed

## Version 0.13.6

- fix: add `SpinnerWidget` to kivy factory
Expand Down
19 changes: 16 additions & 3 deletions ubo_gui/spinner/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import annotations

import pathlib
import re

from kivy.animation import Animation
from kivy.lang.builder import Builder
Expand All @@ -18,12 +19,24 @@ class SpinnerWidget(Label):
def on_kv_post(self: SpinnerWidget, base_widget: SpinnerWidget) -> None:
"""Start the spinner animation."""
_ = base_widget
rotation = Animation(angle=-360 * 100, duration=0.5 * 100) + Animation(
self.rotation_animation = Animation(
angle=-360 * 100,
duration=0.5 * 100,
) + Animation(
angle=0,
duration=0,
)
rotation.repeat = True
rotation.start(self)
self.rotation_animation.repeat = True
self.bind(text=self.handle_text_change)
self.handle_text_change(self, self.text)

def handle_text_change(self: SpinnerWidget, _: SpinnerWidget, text: str) -> None:
"""Decide whether to show the spinner or not."""
text = re.sub(r'\[(?P<tag>\w+)=.*?\](?P<text>.*?)\[/\1\]', r'\g<text>', text)
if text == '':
self.rotation_animation.start(self)
else:
self.rotation_animation.cancel(self)


Builder.load_file(
Expand Down

0 comments on commit 757be8b

Please sign in to comment.