Skip to content

Commit 83ce1de

Browse files
authored
Merge pull request #422 from hx2A/fix421
Fix421
2 parents 92eb637 + e790191 commit 83ce1de

4 files changed

Lines changed: 11 additions & 2 deletions

File tree

generator/reference.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@
267267
"hook_post_draw: bool = False",
268268
"queue_limit: int = None",
269269
"block: bool = False",
270+
"display_progress: bool = True",
270271
],
271272
"None",
272273
)

py5_docs/Reference/api_en/Py5Tools_offline_frame_processing.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ category = sketch_hooks
55
subcategory = None
66

77
@@ signatures
8-
offline_frame_processing(func: Callable[[npt.NDArray[np.uint8]], None], *, limit: int = 0, period: float = 0.0, batch_size: int = 1, complete_func: Callable[[], None] = None, stop_processing_func: Callable[[], bool] = None, sketch: Sketch = None, hook_post_draw: bool = False, queue_limit: int = None, block: bool = False) -> None
8+
offline_frame_processing(func: Callable[[npt.NDArray[np.uint8]], None], *, limit: int = 0, period: float = 0.0, batch_size: int = 1, complete_func: Callable[[], None] = None, stop_processing_func: Callable[[], bool] = None, sketch: Sketch = None, hook_post_draw: bool = False, queue_limit: int = None, block: bool = False, display_progress: bool = True) -> None
99

1010
@@ variables
1111
batch_size: int = 1 - number of frames to include in each batch passed to the frame processing function
1212
block: bool = False - method returns immediately (False) or blocks until function returns (True)
1313
complete_func: Callable[[], None] = None - function to call when frame processing is complete
14+
display_progress: bool = True - display progress as frames are processed
1415
func: Callable[[npt.NDArray[np.uint8]], None] - function to process the Sketch's pixels, one batch at a time
1516
hook_post_draw: bool = False - attach hook to Sketch's post_draw method instead of draw
1617
limit: int = 0 - total number of frames to pass to the frame processing function
@@ -30,6 +31,8 @@ The `queue_limit` parameter specifies a maximum queue size. If frames are added
3031

3132
By default this function will return right away and will process frames in the background while the Sketch is running. Set the `block` parameter to `True` to instruct the method to not return until the processing is complete or the Sketch terminates. This blocking feature is not available on macOS when the Sketch is executed through an IPython kernel.
3233

34+
By default this function will report its progress as frames are processed. If you are using a Jupyter Notebook and happen to be processing tens of thousands of frames, this might cause Jupyter to crash. To avoid that fate, set the `display_progress` parameter to `False`.
35+
3336
Use the `sketch` parameter to specify a different running Sketch, such as a Sketch created using Class mode. If your Sketch has a `post_draw()` method, use the `hook_post_draw` parameter to make this function run after `post_draw()` instead of `draw()`. This is important when using Processing libraries that support `post_draw()` such as Camera3D or ColorBlindness.
3437

3538
@@ example

py5_resources/py5_module/py5_tools/hooks/frame_hooks.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ def offline_frame_processing(
151151
hook_post_draw: bool = False,
152152
queue_limit: int = None,
153153
block: bool = None,
154+
display_progress: bool = True,
154155
) -> None:
155156
"""$module_Py5Tools_offline_frame_processing"""
156157
import py5
@@ -179,6 +180,7 @@ def offline_frame_processing(
179180
complete_func=complete_func,
180181
stop_processing_func=stop_processing_func,
181182
queue_limit=queue_limit,
183+
display_progress=display_progress,
182184
)
183185
sketch._add_post_hook(
184186
"post_draw" if hook_post_draw else "draw", hook.hook_name, hook

py5_resources/py5_module/py5_tools/hooks/hooks.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,14 @@ def __init__(
217217
complete_func=None,
218218
stop_processing_func=None,
219219
queue_limit=0,
220+
display_progress=True,
220221
):
221222
super().__init__("py5queued_block_processing_hook")
222223
self.period = period
223224
self.limit = limit
224225
self.batch_size = batch_size
225226
self.queue_limit = queue_limit
227+
self.display_progress = display_progress
226228

227229
self.continue_grabbing_frames = True
228230
self.current_batch = None
@@ -305,7 +307,8 @@ def __call__(self, sketch):
305307
self.processor.stop_processing = True
306308
self.hook_finished(sketch)
307309

308-
self.status_msg(self.msg())
310+
if self.display_progress:
311+
self.status_msg(self.msg())
309312

310313
except Exception as e:
311314
self.hook_error(sketch, e)

0 commit comments

Comments
 (0)