From 26234623d504c8e4458be20207d292e8436e38d5 Mon Sep 17 00:00:00 2001 From: Almar Klein Date: Thu, 21 Nov 2024 11:40:27 +0100 Subject: [PATCH] Rename is_closed() to get_closed() --- examples/demo.py | 2 +- examples/offsceen_threaded.py | 2 +- rendercanvas/_loop.py | 2 +- rendercanvas/base.py | 19 ++++++++++++++----- rendercanvas/glfw.py | 2 +- rendercanvas/jupyter.py | 4 ++-- rendercanvas/offscreen.py | 2 +- rendercanvas/qt.py | 2 +- rendercanvas/stub.py | 2 +- rendercanvas/wx.py | 2 +- tests/test_glfw.py | 4 ++-- tests/test_scheduling.py | 2 +- 12 files changed, 27 insertions(+), 18 deletions(-) diff --git a/examples/demo.py b/examples/demo.py index da8c890..436eee5 100644 --- a/examples/demo.py +++ b/examples/demo.py @@ -51,7 +51,7 @@ def process_event(event): # Should see this exactly once, either when pressing escape, or # when pressing the window close button. print("Close detected!") - assert canvas.is_closed() + assert canvas.get_closed() if __name__ == "__main__": diff --git a/examples/offsceen_threaded.py b/examples/offsceen_threaded.py index 0827456..3f5a299 100644 --- a/examples/offsceen_threaded.py +++ b/examples/offsceen_threaded.py @@ -34,7 +34,7 @@ def main(): frame_count = 0 canvas.request_draw(draw_frame) - while not canvas.is_closed(): + while not canvas.get_closed(): image = canvas.draw() frame_count += 1 print(f"Rendered {frame_count} frames, last shape is {image.shape}") diff --git a/rendercanvas/_loop.py b/rendercanvas/_loop.py index 15ae8ec..04e6acd 100644 --- a/rendercanvas/_loop.py +++ b/rendercanvas/_loop.py @@ -451,7 +451,7 @@ def __init__(self, canvas, events, loop, *, mode="ondemand", min_fps=1, max_fps= def get_canvas(self): """Get the canvas, or None if it is closed or gone.""" canvas = self._canvas_ref() - if canvas is None or canvas.is_closed(): + if canvas is None or canvas.get_closed(): # Pretty nice, we can send a close event, even if the canvas no longer exists self._events._rc_close() return None diff --git a/rendercanvas/base.py b/rendercanvas/base.py index 8d1f609..64e66cf 100644 --- a/rendercanvas/base.py +++ b/rendercanvas/base.py @@ -8,7 +8,7 @@ from ._events import EventEmitter, EventType # noqa: F401 from ._loop import Scheduler, BaseLoop, BaseTimer -from ._coreutils import log_exception +from ._coreutils import logger, log_exception # Notes on naming and prefixes: @@ -327,7 +327,7 @@ def _draw_frame_and_present(self): # "draw event" that we requested, or as part of a forced draw. # Cannot draw to a closed canvas. - if self._rc_is_closed(): + if self._rc_get_closed(): return # Process special events @@ -382,9 +382,15 @@ def close(self): """Close the canvas.""" self._rc_close() - def is_closed(self): + def get_closed(self): """Get whether the window is closed.""" - return self._rc_is_closed() + return self._rc_get_closed() + + def is_closed(self): + logger.warning( + "canvas.is_closed() is deprecated, use canvas.get_closed() instead." + ) + return self._rc_get_closed() # %% Secondary canvas management methods @@ -502,7 +508,7 @@ def _rc_close(self): """ pass - def _rc_is_closed(self): + def _rc_get_closed(self): """Get whether the canvas is closed.""" return False @@ -558,5 +564,8 @@ def set_title(self, *args): def close(self): self._subwidget.close() + def get_closed(self): + return self._subwidget.get_closed() + def is_closed(self): return self._subwidget.is_closed() diff --git a/rendercanvas/glfw.py b/rendercanvas/glfw.py index b348701..c3aa38d 100644 --- a/rendercanvas/glfw.py +++ b/rendercanvas/glfw.py @@ -319,7 +319,7 @@ def _rc_close(self): self._window = None self.submit_event({"event_type": "close"}) - def _rc_is_closed(self): + def _rc_get_closed(self): return self._window is None def _rc_set_title(self, title): diff --git a/rendercanvas/jupyter.py b/rendercanvas/jupyter.py index 26a6c64..bdf0001 100644 --- a/rendercanvas/jupyter.py +++ b/rendercanvas/jupyter.py @@ -105,7 +105,7 @@ def _rc_set_logical_size(self, width, height): def _rc_close(self): RemoteFrameBuffer.close(self) - def _rc_is_closed(self): + def _rc_get_closed(self): return self._is_closed def _rc_set_title(self, title): @@ -142,7 +142,7 @@ def run(self): canvases = [r() for r in self._pending_jupyter_canvases] self._pending_jupyter_canvases.clear() for w in canvases: - if w and not w.is_closed(): + if w and not w.get_closed(): display(w) diff --git a/rendercanvas/offscreen.py b/rendercanvas/offscreen.py index a5459a3..fe5f67c 100644 --- a/rendercanvas/offscreen.py +++ b/rendercanvas/offscreen.py @@ -60,7 +60,7 @@ def _rc_set_logical_size(self, width, height): def _rc_close(self): self._closed = True - def _rc_is_closed(self): + def _rc_get_closed(self): return self._closed def _rc_set_title(self, title): diff --git a/rendercanvas/qt.py b/rendercanvas/qt.py index 6323f0f..da8ba47 100644 --- a/rendercanvas/qt.py +++ b/rendercanvas/qt.py @@ -343,7 +343,7 @@ def _rc_close(self): else: QtWidgets.QWidget.close(self) - def _rc_is_closed(self): + def _rc_get_closed(self): return self._is_closed def _rc_set_title(self, title): diff --git a/rendercanvas/stub.py b/rendercanvas/stub.py index 63e35c2..c933b97 100644 --- a/rendercanvas/stub.py +++ b/rendercanvas/stub.py @@ -58,7 +58,7 @@ def _rc_set_logical_size(self, width, height): def _rc_close(self): pass - def _rc_is_closed(self): + def _rc_get_closed(self): return False def _rc_set_title(self, title): diff --git a/rendercanvas/wx.py b/rendercanvas/wx.py index a98cc18..aba9ed8 100644 --- a/rendercanvas/wx.py +++ b/rendercanvas/wx.py @@ -278,7 +278,7 @@ def _rc_close(self): else: self.Hide() - def _rc_is_closed(self): + def _rc_get_closed(self): return self._is_closed def _rc_set_title(self, title): diff --git a/tests/test_glfw.py b/tests/test_glfw.py index 77efb56..00ad05d 100644 --- a/tests/test_glfw.py +++ b/tests/test_glfw.py @@ -58,10 +58,10 @@ def test_glfw_canvas_basics(): assert isinstance(canvas.get_pixel_ratio(), float) # Close - assert not canvas.is_closed() + assert not canvas.get_closed() canvas.close() glfw.poll_events() - assert canvas.is_closed() + assert canvas.get_closed() def test_glfw_canvas_del(): diff --git a/tests/test_scheduling.py b/tests/test_scheduling.py index 97f17f8..785df75 100644 --- a/tests/test_scheduling.py +++ b/tests/test_scheduling.py @@ -52,7 +52,7 @@ def _rc_get_loop(self): def _rc_close(self): self._closed = True - def _rc_is_closed(self): + def _rc_get_closed(self): return self._closed def _process_events(self):