-
-
Notifications
You must be signed in to change notification settings - Fork 18
Add Sketch.is_looping as property #804
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure this is actually needed and how to handle the property. Will revisit.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Good catch. I think mocking this would be important for |
||
| s.redraw = mock_methods.mock_redraw | ||
| s.real_exit_sketch = s.exit_sketch | ||
| s.exit_sketch = mock_methods.mock_exit_sketch | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is_readyandis_runninghandles similar implementations by creating a helper method, then wrapping it as a property. I checked the codebase but couldn't understand the benefit of this approach, it seems to complicate the code for no reason.Property-wrapping approach causes a typing issue too:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
py5generator is essentially a custom template engine that takes code templates and adds more code to them to make complete python files. The template engine needs to be able to read and parse the code in the templates and extract information from them to maintain the type signatures and compare them with the documentation files. The code that extracts information expects the code to be written in a certain way to be easily parsed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any chance to give some context about why template engine needs it? I couldn't see how
_get...+ property wrapper approach provides anything extra over the approach in this PR.