test-kivy-app/kivy_venv/lib/python3.11/site-packages/kivymd/utils/fpsmonitor.py

70 lines
1.5 KiB
Python
Raw Normal View History

2024-09-15 12:12:16 +00: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
from kivy.properties import NumericProperty, StringProperty, OptionProperty
from kivy.uix.label import Label
Builder.load_string(
"""
<FpsMonitor>:
size_hint_y: None
height: self.texture_size[1]
text: root._fsp_value
pos_hint: {root.anchor: 1}
2024-09-15 17:57:02 +00:00
color: app.theme_cls.surfaceColor
2024-09-15 12:12:16 +00:00
canvas.before:
Color:
2024-09-15 17:57:02 +00:00
rgba: app.theme_cls.onBackgroundColor
2024-09-15 12:12:16 +00:00
Rectangle:
pos: self.pos
size: self.size
"""
)
class FpsMonitor(Label):
2024-09-15 17:57:02 +00:00
"""
Fps monitor class.
For more information, see in the
:class:`~kivy.uix.label.Label` class documentation.
"""
2024-09-15 12:12:16 +00:00
updated_interval = NumericProperty(0.5)
2024-09-15 17:57:02 +00:00
"""
FPS refresh rate.
:attr:`updated_interval` is an :class:`~kivy.properties.NumericProperty`
and defaults to `0.5`.
"""
2024-09-15 12:12:16 +00:00
anchor = OptionProperty("top", options=["top", "bottom"])
2024-09-15 17:57:02 +00:00
"""
Monitor position.
Available option are: 'top', 'bottom'.
:attr:`anchor` is an :class:`~kivy.properties.OptionProperty`
and defaults to `'top'`.
"""
2024-09-15 12:12:16 +00:00
_fsp_value = StringProperty()
2024-09-15 17:57:02 +00:00
def start(self) -> None:
"""Monitor starting."""
2024-09-15 12:12:16 +00:00
Clock.schedule_interval(self.update_fps, self.updated_interval)
2024-09-15 17:57:02 +00:00
def update_fps(self, *args) -> None:
2024-09-15 12:12:16 +00:00
self._fsp_value = "FPS: %f" % Clock.get_fps()