Created
February 4, 2016 17:29
-
-
Save tito/0e07f3dde14d9c1c6bd4 to your computer and use it in GitHub Desktop.
ProgressSpinner using fontello
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Font-based ProgressSpinner | |
========================== | |
''' | |
from kivy.lang import Builder | |
from kivy.properties import NumericProperty, BooleanProperty, StringProperty | |
from kivy.clock import Clock | |
from kivy.uix.widget import Widget | |
Builder.load_string(""" | |
<ProgressSpinner>: | |
canvas.before: | |
PushMatrix | |
Rotate: | |
origin: self.center | |
axis: 0, 0, 1 | |
angle: self.rotation | |
canvas.after: | |
PopMatrix | |
Label: | |
font_name: "images/fontello.ttf" | |
pos: root.pos | |
size: root.size | |
text: root.symbol | |
font_size: sp(24) | |
""") | |
class ProgressSpinner(Widget): | |
rotation = NumericProperty() | |
auto_start = BooleanProperty(True) | |
symbol = StringProperty(u"\ue80a") | |
def on_opacity(self, instance, value): | |
if not value: | |
self.stop_spinning() | |
elif self.auto_start: | |
self.start_spinning() | |
def on_parent(self, instance, value): | |
if value is None: | |
self.stop_spinning() | |
elif self.auto_start: | |
self.start_spinning() | |
def start_spinning(self): | |
Clock.unschedule(self._rotate) | |
Clock.schedule_interval(self._rotate, 1 / 30.) | |
def stop_spinning(self): | |
Clock.unschedule(self._rotate) | |
def _rotate(self, dt): | |
self.rotation += dt * -180. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment