|
7 | 7 | import sys |
8 | 8 | import weakref |
9 | 9 | import importlib |
| 10 | +from typing import Optional, Tuple |
10 | 11 |
|
11 | 12 | from ._events import EventEmitter, EventType # noqa: F401 |
12 | 13 | from ._loop import BaseLoop |
13 | | -from ._scheduler import Scheduler |
| 14 | +from ._scheduler import Scheduler, UpdateMode |
14 | 15 | from ._coreutils import logger, log_exception, BaseEnum |
15 | 16 |
|
16 | 17 |
|
@@ -94,9 +95,8 @@ class BaseRenderCanvas: |
94 | 95 | size (tuple): the logical size (width, height) of the canvas. |
95 | 96 | title (str): The title of the canvas. Can use '$backend' to show the RenderCanvas class name, |
96 | 97 | and '$fps' to show the fps. |
97 | | - update_mode (EventType): The mode for scheduling draws and events. Default 'ondemand'. |
98 | | - min_fps (float): A minimal frames-per-second to use when the ``update_mode`` is 'ondemand'. |
99 | | - The default is 1: even without draws requested, it still draws every second. |
| 98 | + update_mode (UpdateMode): The mode for scheduling draws and events. Default 'ondemand'. |
| 99 | + min_fps (float): A minimal frames-per-second to use when the ``update_mode`` is 'ondemand'. The default is 0: |
100 | 100 | max_fps (float): A maximal frames-per-second to use when the ``update_mode`` is 'ondemand' |
101 | 101 | or 'continuous'. The default is 30, which is usually enough. |
102 | 102 | vsync (bool): Whether to sync the draw with the monitor update. Helps |
@@ -126,13 +126,13 @@ def select_loop(cls, loop): |
126 | 126 | def __init__( |
127 | 127 | self, |
128 | 128 | *args, |
129 | | - size=(640, 480), |
130 | | - title="$backend", |
131 | | - update_mode="ondemand", |
132 | | - min_fps=1.0, |
133 | | - max_fps=30.0, |
134 | | - vsync=True, |
135 | | - present_method=None, |
| 129 | + size: Tuple[int] = (640, 480), |
| 130 | + title: str = "$backend", |
| 131 | + update_mode: UpdateMode = "ondemand", |
| 132 | + min_fps: float = 0.0, |
| 133 | + max_fps: float = 30.0, |
| 134 | + vsync: bool = True, |
| 135 | + present_method: Optional[str] = None, |
136 | 136 | **kwargs, |
137 | 137 | ): |
138 | 138 | # Initialize superclass. Note that super() can be e.g. a QWidget, RemoteFrameBuffer, or object. |
@@ -170,7 +170,7 @@ def __init__( |
170 | 170 | self._events, |
171 | 171 | min_fps=min_fps, |
172 | 172 | max_fps=max_fps, |
173 | | - mode=update_mode, |
| 173 | + update_mode=update_mode, |
174 | 174 | ) |
175 | 175 | self._rc_canvas_group._register_canvas(self, self.__scheduler.get_task()) |
176 | 176 |
|
@@ -354,6 +354,17 @@ def _draw_frame(self): |
354 | 354 | """ |
355 | 355 | pass |
356 | 356 |
|
| 357 | + def set_update_mode(self, update_mode, *, min_fps=None, max_fps=None): |
| 358 | + """Set the update mode for scheduling draws. |
| 359 | +
|
| 360 | + Arguments: |
| 361 | + update_mode (UpdateMode): The mode for scheduling draws and events. |
| 362 | + min_fps (float): The minimum fps with update mode 'ondemand'. |
| 363 | + max_fps (float): The maximum fps with update mode 'ondemand' and 'continuous'. |
| 364 | +
|
| 365 | + """ |
| 366 | + self.__scheduler.set_update_mode(update_mode, min_fps=min_fps, max_fps=max_fps) |
| 367 | + |
357 | 368 | def request_draw(self, draw_function=None): |
358 | 369 | """Schedule a new draw event. |
359 | 370 |
|
|
0 commit comments