working condition
This commit is contained in:
parent
417e54da96
commit
511e0b0379
517 changed files with 29187 additions and 32696 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -1,67 +0,0 @@
|
|||
"""
|
||||
asynckivy
|
||||
=========
|
||||
|
||||
Copyright (c) 2019 Nattōsai Mitō
|
||||
|
||||
GitHub -
|
||||
https://github.com/gottadiveintopython
|
||||
GitHub Gist -
|
||||
https://gist.github.com/gottadiveintopython/5f4a775849f9277081c396de65dc57c1
|
||||
|
||||
"""
|
||||
|
||||
__all__ = ("start", "sleep", "event")
|
||||
|
||||
import types
|
||||
from collections import namedtuple
|
||||
from functools import partial
|
||||
|
||||
from kivy.clock import Clock
|
||||
|
||||
CallbackParameter = namedtuple("CallbackParameter", ("args", "kwargs"))
|
||||
|
||||
|
||||
def start(coro):
|
||||
def step(*args, **kwargs):
|
||||
try:
|
||||
coro.send(CallbackParameter(args, kwargs))(step)
|
||||
except StopIteration:
|
||||
pass
|
||||
|
||||
try:
|
||||
coro.send(None)(step)
|
||||
except StopIteration:
|
||||
pass
|
||||
|
||||
|
||||
@types.coroutine
|
||||
def sleep(duration):
|
||||
# The partial() here looks meaningless. But this is needed in order
|
||||
# to avoid weak reference.
|
||||
param = yield lambda step_coro: Clock.schedule_once(
|
||||
partial(step_coro), duration
|
||||
)
|
||||
return param.args[0]
|
||||
|
||||
|
||||
class event:
|
||||
def __init__(self, ed, name):
|
||||
self.bind_id = None
|
||||
self.ed = ed
|
||||
self.name = name
|
||||
|
||||
def bind(self, step_coro):
|
||||
self.bind_id = bind_id = self.ed.fbind(self.name, self.callback)
|
||||
assert bind_id > 0 # check if binding succeeded
|
||||
self.step_coro = step_coro
|
||||
|
||||
def callback(self, *args, **kwargs):
|
||||
self.parameter = CallbackParameter(args, kwargs)
|
||||
ed = self.ed
|
||||
ed.unbind_uid(self.name, self.bind_id)
|
||||
self.step_coro()
|
||||
|
||||
def __await__(self):
|
||||
yield self.bind
|
||||
return self.parameter
|
|
@ -21,10 +21,11 @@ Builder.load_string(
|
|||
height: self.texture_size[1]
|
||||
text: root._fsp_value
|
||||
pos_hint: {root.anchor: 1}
|
||||
color: app.theme_cls.surfaceColor
|
||||
|
||||
canvas.before:
|
||||
Color:
|
||||
rgba: app.theme_cls.primary_dark
|
||||
rgba: app.theme_cls.onBackgroundColor
|
||||
Rectangle:
|
||||
pos: self.pos
|
||||
size: self.size
|
||||
|
@ -33,16 +34,36 @@ Builder.load_string(
|
|||
|
||||
|
||||
class FpsMonitor(Label):
|
||||
"""
|
||||
Fps monitor class.
|
||||
|
||||
For more information, see in the
|
||||
:class:`~kivy.uix.label.Label` class documentation.
|
||||
"""
|
||||
|
||||
updated_interval = NumericProperty(0.5)
|
||||
"""FPS refresh rate."""
|
||||
"""
|
||||
FPS refresh rate.
|
||||
|
||||
:attr:`updated_interval` is an :class:`~kivy.properties.NumericProperty`
|
||||
and defaults to `0.5`.
|
||||
"""
|
||||
|
||||
anchor = OptionProperty("top", options=["top", "bottom"])
|
||||
"""Monitor position."""
|
||||
"""
|
||||
Monitor position.
|
||||
Available option are: 'top', 'bottom'.
|
||||
|
||||
:attr:`anchor` is an :class:`~kivy.properties.OptionProperty`
|
||||
and defaults to `'top'`.
|
||||
"""
|
||||
|
||||
_fsp_value = StringProperty()
|
||||
|
||||
def start(self):
|
||||
def start(self) -> None:
|
||||
"""Monitor starting."""
|
||||
|
||||
Clock.schedule_interval(self.update_fps, self.updated_interval)
|
||||
|
||||
def update_fps(self, *args):
|
||||
def update_fps(self, *args) -> None:
|
||||
self._fsp_value = "FPS: %f" % Clock.get_fps()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue