23
23
"""
24
24
import sys
25
25
from pathlib import Path
26
- import logging
27
26
import inspect
28
27
from typing import overload, Any, Callable, Union, Dict, List, Tuple # noqa
29
28
from nptyping import NDArray, Float, Int # noqa
30
29
31
- import json # noqa
30
+ # import json # noqa
32
31
import numpy as np # noqa
33
32
from PIL import Image # noqa
34
33
from jpype import JClass # noqa
62
61
pass
63
62
64
63
65
- __version__ = '0.4a1 '
64
+ __version__ = '0.4a2 '
66
65
67
66
_PY5_USE_IMPORTED_MODE = py5_tools.imported.get_imported_mode()
68
67
69
- logger = logging.getLogger(__name__)
70
-
71
68
java_conversion.init_jpype_converters()
72
69
73
70
@@ -18944,6 +18941,80 @@ def list_threads() -> None:
18944
18941
"""
18945
18942
return _py5sketch.list_threads()
18946
18943
18944
+ ##############################################################################
18945
+ # module functions from print_tools.py
18946
+ ##############################################################################
18947
+
18948
+
18949
+ def set_println_stream(println_stream: Any) -> None:
18950
+ """Customize where the output of ``println()`` goes.
18951
+
18952
+ Parameters
18953
+ ----------
18954
+
18955
+ println_stream: Any
18956
+ println stream object to be used by println method
18957
+
18958
+ Notes
18959
+ -----
18960
+
18961
+ Customize where the output of ``println()`` goes.
18962
+
18963
+ When running a Sketch asynchronously through Jupyter Notebook, any ``print``
18964
+ statements using Python's builtin function will always appear in the output of
18965
+ the currently active cell. This will rarely be desirable, as the active cell
18966
+ will keep changing as the user executes code elsewhere in the notebook. The
18967
+ ``println()`` method was created to provide users with print functionality in a
18968
+ Sketch without having to cope with output moving from one cell to the next. Use
18969
+ ``set_println_stream`` to change how the output is handled. The
18970
+ ``println_stream`` object must provide ``init()`` and ``print()`` methods, as
18971
+ shown in the example. The example demonstrates how to configure py5 to output
18972
+ text to an IPython Widget.
18973
+ """
18974
+ return _py5sketch.set_println_stream(println_stream)
18975
+
18976
+
18977
+ def println(
18978
+ *args,
18979
+ sep: str = ' ',
18980
+ end: str = '\n',
18981
+ stderr: bool = False) -> None:
18982
+ """Print text or other values to the screen.
18983
+
18984
+ Parameters
18985
+ ----------
18986
+
18987
+ args
18988
+ values to be printed
18989
+
18990
+ end: str = '\\n'
18991
+ string appended after the last value, defaults to newline character
18992
+
18993
+ sep: str = ' '
18994
+ string inserted between values, defaults to a space
18995
+
18996
+ stderr: bool = False
18997
+ use stderr instead of stdout
18998
+
18999
+ Notes
19000
+ -----
19001
+
19002
+ Print text or other values to the screen. For a Sketch running outside of a
19003
+ Jupyter Notebook, this method will behave the same as the Python's builtin
19004
+ ``print`` method. For Sketches running in a Jupyter Notebook, this will place
19005
+ text in the output of the cell that made the ``run_sketch()`` call.
19006
+
19007
+ When running a Sketch asynchronously through Jupyter Notebook, any ``print``
19008
+ statements using Python's builtin function will always appear in the output of
19009
+ the currently active cell. This will rarely be desirable, as the active cell
19010
+ will keep changing as the user executes code elsewhere in the notebook. This
19011
+ method was created to provide users with print functionality in a Sketch without
19012
+ having to cope with output moving from one cell to the next.
19013
+
19014
+ Use ``set_println_stream()`` to customize the behavior of ``println()``.
19015
+ """
19016
+ return _py5sketch.println(*args, sep=sep, end=end, stderr=stderr)
19017
+
18947
19018
##############################################################################
18948
19019
# module functions from sketch.py
18949
19020
##############################################################################
@@ -19376,10 +19447,10 @@ def run_sketch(block: bool = None, *,
19376
19447
functions will be used to actualize your Sketch.
19377
19448
19378
19449
Use the ``block`` parameter to specify if the call to ``run_sketch()`` should
19379
- return immediately or block until the Sketch exits. If the ``block`` parameter
19380
- is not specified, py5 will first attempt to determine if the Sketch is running
19381
- in a Jupyter Notebook or an IPython shell. If it is, ``block`` will default to
19382
- ``False``, and ``True`` otherwise.
19450
+ return immediately (asynchronous Sketch execution) or block until the Sketch
19451
+ exits. If the ``block`` parameter is not specified, py5 will first attempt to
19452
+ determine if the Sketch is running in a Jupyter Notebook or an IPython shell. If
19453
+ it is, ``block`` will default to ``False``, and ``True`` otherwise.
19383
19454
19384
19455
A list of strings passed to ``py5_options`` will be passed to the Processing
19385
19456
PApplet class as arguments to specify characteristics such as the window's
@@ -19394,13 +19465,26 @@ def run_sketch(block: bool = None, *,
19394
19465
``sketch_functions`` parameter to pass a dictionary of the desired callable
19395
19466
functions. The ``sketch_functions`` parameter is not available when coding py5
19396
19467
in class mode. Don't forget you can always replace the ``draw()`` function in a
19397
- running Sketch using ``hot_reload_draw()``."""
19468
+ running Sketch using ``hot_reload_draw()``.
19469
+
19470
+ When running a Sketch asynchronously through Jupyter Notebook, any ``print``
19471
+ statements using Python's builtin function will always appear in the output of
19472
+ the currently active cell. This will rarely be desirable, as the active cell
19473
+ will keep changing as the user executes code elsewhere in the notebook. As an
19474
+ alternative, use py5's ``println()`` method, which will place all text in the
19475
+ output of the cell that made the ``run_sketch()`` call. This will continue to be
19476
+ true if the user moves on to execute code in other Notebook cells. Use
19477
+ ``set_println_stream()`` to customize this behavior. All py5 error messages and
19478
+ stack traces are routed through the ``println()`` method. Be aware that some
19479
+ error messages and warnings generated inside the Processing Jars cannot be
19480
+ controlled in the same way, and may appear in the output of the active cell or
19481
+ mixed in with the Jupyter Kernel logs."""
19398
19482
if block is None:
19399
19483
block = not _in_ipython_session
19400
19484
19401
19485
sketch_functions = sketch_functions or inspect.stack()[1].frame.f_locals
19402
19486
functions = dict([(e, sketch_functions[e])
19403
- for e in reference.METHODS if e in sketch_functions and callable(sketch_functions[e])])
19487
+ for e in reference.METHODS if e in sketch_functions and callable(sketch_functions[e])])
19404
19488
19405
19489
if not set(functions.keys()) & set(['settings', 'setup', 'draw']):
19406
19490
print(("Unable to find settings, setup, or draw functions. "
0 commit comments