From 914ab0de2e7fd5a8454e276e927ebe80ca67fc46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=9Clgen=20Sar=C4=B1kavak?= Date: Wed, 16 Sep 2026 21:44:45 +0300 Subject: [PATCH] Add Sketch.is_looping as property --- .../Reference/api_en/Sketch_is_looping.txt | 33 +++++++++++++++++++ py5-resources/data/sketch.csv | 2 +- py5-resources/py5-module/src/py5/sketch.py | 5 +++ .../src/py5_tools/live_coding/syncing.py | 4 +++ 4 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 py5-docs/Reference/api_en/Sketch_is_looping.txt diff --git a/py5-docs/Reference/api_en/Sketch_is_looping.txt b/py5-docs/Reference/api_en/Sketch_is_looping.txt new file mode 100644 index 000000000..f14e22e04 --- /dev/null +++ b/py5-docs/Reference/api_en/Sketch_is_looping.txt @@ -0,0 +1,33 @@ +@@ meta +name = is_looping +type = field +pclass = Sketch +processing_name = isLooping +category = structure +subcategory = None + +@@ description +The `is_looping` property returns whether or not the sketch is currently looping. This will be `True` by default, and `False` after [](sketch_no_loop) has been called. Calling [](sketch_loop) will set it back to `True`. + +@@ example +x = 0.0 + + +def setup(): + py5.size(200, 200) + + +def draw(): + global x + py5.background(204) + py5.line(x, 0, x, py5.height) + x = x + 1 + if x > py5.width: + x = 0 + + +def mouse_pressed(): + if py5.is_looping: + py5.no_loop() + else: + py5.loop() diff --git a/py5-resources/data/sketch.csv b/py5-resources/data/sketch.csv index 2425a404c..b858e9dea 100644 --- a/py5-resources/data/sketch.csv +++ b/py5-resources/data/sketch.csv @@ -347,7 +347,7 @@ create_image,createImage,@_return_py5image,method,image,,JAVA, image,image,@_auto_convert_to_py5image(0),method,image,loading_displaying,JAVA, handle_draw,handleDraw,,method,,,SKIP,public methods that shouldn't be available to users alpha,alpha,@_convert_hex_color(),method,color,creating_reading,JAVA, -is_looping,isLooping,,method,,,SKIP,methods that are not part of the processing framework +is_looping,isLooping,,dynamic variable,structure,,PYTHON,property to determine if sketch is looping looping,looping,,unknown,,,SKIP,methods that are not part of the processing framework post_event,postEvent,,method,,,SKIP,public methods that shouldn't be available to users focus_gained,focusGained,,method,,,SKIP,methods that are not part of the processing framework diff --git a/py5-resources/py5-module/src/py5/sketch.py b/py5-resources/py5-module/src/py5/sketch.py index 6a47e50a1..0cabf9589 100644 --- a/py5-resources/py5-module/src/py5/sketch.py +++ b/py5-resources/py5-module/src/py5/sketch.py @@ -605,6 +605,11 @@ def _get_is_running(self) -> bool: # @decorator fget=_get_is_running, doc="""$class_Sketch_is_running""" ) + @property + def is_looping(self) -> bool: + """$class_Sketch_is_looping""" + return self._instance.isLooping() + def _get_is_dead(self) -> bool: # @decorator """$class_Sketch_is_dead""" surface = self.get_surface() diff --git a/py5-resources/py5-module/src/py5_tools/live_coding/syncing.py b/py5-resources/py5-module/src/py5_tools/live_coding/syncing.py index f3822c4ae..72be11e9d 100644 --- a/py5-resources/py5-module/src/py5_tools/live_coding/syncing.py +++ b/py5-resources/py5-module/src/py5_tools/live_coding/syncing.py @@ -88,6 +88,9 @@ def mock_no_loop(self): UserFunctionWrapper.looping_state = ANIMATION_NO_LOOPING UserFunctionWrapper.freeze_frame_count = self.sketch.frame_count + def mock_is_looping(self): + return UserFunctionWrapper.looping_state in (ANIMATION_LOOPING, ANIMATION_REDRAW) + def mock_redraw(self): UserFunctionWrapper.looping_state = ANIMATION_REDRAW UserFunctionWrapper.freeze_frame_count += 1 @@ -347,6 +350,7 @@ def _init_hooks(self, s): mock_methods = MockMethods(s) s.loop = mock_methods.mock_loop s.no_loop = mock_methods.mock_no_loop + s.is_looping = mock_methods.mock_is_looping s.redraw = mock_methods.mock_redraw s.real_exit_sketch = s.exit_sketch s.exit_sketch = mock_methods.mock_exit_sketch