Sideband/sbapp/kivymd/utils/fpsmonitor.py

49 lines
1.0 KiB
Python
Raw Normal View History

2022-07-07 16:16:10 -04:00
"""
Monitor module
==============
The Monitor module is a toolbar that shows the activity of your current
application :
* FPS
"""
from kivy.clock import Clock
from kivy.lang import Builder
2023-07-09 20:49:58 -04:00
from kivy.properties import NumericProperty, StringProperty, OptionProperty
2022-07-07 16:16:10 -04:00
from kivy.uix.label import Label
Builder.load_string(
"""
<FpsMonitor>:
size_hint_y: None
height: self.texture_size[1]
text: root._fsp_value
2023-07-09 20:49:58 -04:00
pos_hint: {root.anchor: 1}
2022-07-07 16:16:10 -04:00
canvas.before:
Color:
rgba: app.theme_cls.primary_dark
Rectangle:
pos: self.pos
size: self.size
"""
)
class FpsMonitor(Label):
updated_interval = NumericProperty(0.5)
"""FPS refresh rate."""
2023-07-09 20:49:58 -04:00
anchor = OptionProperty("top", options=["top", "bottom"])
"""Monitor position."""
2022-07-07 16:16:10 -04:00
_fsp_value = StringProperty()
def start(self):
Clock.schedule_interval(self.update_fps, self.updated_interval)
def update_fps(self, *args):
self._fsp_value = "FPS: %f" % Clock.get_fps()