Skip to content

Commit

Permalink
Rename is_closed() to get_closed()
Browse files Browse the repository at this point in the history
  • Loading branch information
almarklein committed Nov 21, 2024
1 parent ea67187 commit 2623462
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 18 deletions.
2 changes: 1 addition & 1 deletion examples/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__":
Expand Down
2 changes: 1 addition & 1 deletion examples/offsceen_threaded.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down
2 changes: 1 addition & 1 deletion rendercanvas/_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 14 additions & 5 deletions rendercanvas/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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()
2 changes: 1 addition & 1 deletion rendercanvas/glfw.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions rendercanvas/jupyter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)


Expand Down
2 changes: 1 addition & 1 deletion rendercanvas/offscreen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion rendercanvas/qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion rendercanvas/stub.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion rendercanvas/wx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_glfw.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
2 changes: 1 addition & 1 deletion tests/test_scheduling.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 2623462

Please sign in to comment.