Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions py5-docs/Reference/api_en/Sketch_is_looping.txt
Original file line number Diff line number Diff line change
@@ -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()
2 changes: 1 addition & 1 deletion py5-resources/data/sketch.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions py5-resources/py5-module/src/py5/sketch.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,18 @@ def _get_is_running(self) -> bool: # @decorator
fget=_get_is_running, doc="""$class_Sketch_is_running"""
)

def _get_is_looping(self) -> bool: # @decorator
"""$class_Sketch_is_looping"""
if not self._instance:
# Sketch has not been run yet
return False

return self._instance.isLooping()

is_looping: bool = property(
fget=_get_is_looping, doc="""$class_Sketch_is_looping"""
)

def _get_is_dead(self) -> bool: # @decorator
"""$class_Sketch_is_dead"""
surface = self.get_surface()
Expand Down
4 changes: 4 additions & 0 deletions py5-resources/py5-module/src/py5_tools/live_coding/syncing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
if UserFunctionWrapper.looping_state == ANIMATION_NO_LOOPING and isinstance(
UserFunctionWrapper.freeze_frame_count, int
Expand Down Expand Up @@ -350,6 +353,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
Comment thread
ulgens marked this conversation as resolved.
s.redraw = mock_methods.mock_redraw
s.real_exit_sketch = s.exit_sketch
s.exit_sketch = mock_methods.mock_exit_sketch
Expand Down