From 85d6a274bec611faae7498b175f41b445b16582b Mon Sep 17 00:00:00 2001 From: Almar Klein Date: Tue, 22 Oct 2024 13:20:47 +0200 Subject: [PATCH] enum for update modes --- wgpu/gui/_loop.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/wgpu/gui/_loop.py b/wgpu/gui/_loop.py index 7e0ae734..4aa02ffa 100644 --- a/wgpu/gui/_loop.py +++ b/wgpu/gui/_loop.py @@ -6,6 +6,7 @@ import weakref from ._gui_utils import log_exception +from ..enums import Enum # Note: technically, we could have a global loop proxy object that defers to any of the other loops. # That would e.g. allow using glfw with qt together. Probably to too weird use-case for the added complexity. @@ -240,6 +241,15 @@ class AnimationScheduler: # scheduler._event_emitter.submit_and_dispatch(event) +class UpdateMode(Enum): + """The different modes to schedule draws for the canvas.""" + + manual = None #: Draw events are never scheduled. Draws only happen when you ``canvas.force_draw()``, and maybe when the GUI system issues them (e.g. when resizing). + ondemand = None #: Draws are only scheduled when ``canvas.request_draw()`` is called when an update is needed. Safes your laptop battery. Honours ``min_fps`` and ``max_fps``. + continuous = None #: Continuously schedules draw events, honouring ``max_fps``. Calls to ``canvas.request_draw()`` have no effect. + fastest = None #: Continuously schedules draw events as fast as possible. Gives high FPS (and drains your battery). + + class Scheduler: """Helper class to schedule event processing and drawing.""" @@ -309,6 +319,10 @@ def __init__(self, canvas, loop, *, mode="ondemand", min_fps=1, max_fps=30): loop._register_scheduler(self) # Scheduling variables + if mode not in UpdateMode: + raise ValueError( + f"Invalid update_mode '{mode}', must be in {set(UpdateMode)}." + ) self._mode = mode self._min_fps = float(min_fps) self._max_fps = float(max_fps)