Skip to content
Merged
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
1 change: 1 addition & 0 deletions generator/reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
"sketch_args: list[str] = None",
"sketch_functions: dict[str, Callable] = None",
"jclassname: str = None",
"jclass_params: tuple[Any] = ()",
],
"None",
)
Expand Down
5 changes: 3 additions & 2 deletions py5_docs/Reference/api_en/Sketch_run_sketch.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ category = structure
subcategory = None

@@ signatures
run_sketch(block: bool = None, *, py5_options: list[str] = None, sketch_args: list[str] = None, sketch_functions: dict[str, Callable] = None, jclassname: str = None) -> None
run_sketch(block: bool = None, *, py5_options: list[str] = None, sketch_args: list[str] = None, sketch_functions: dict[str, Callable] = None, jclassname: str = None, jclass_params: tuple[Any] = ()) -> None

@@ variables
block: bool = None - method returns immediately (False) or blocks until Sketch exits (True)
jclass_params: tuple[Any] = () - parameters to pass to constructor when using py5 in processing mode
jclassname: str = None - canonical name of class to instantiate when using py5 in processing mode
py5_options: list[str] = None - command line arguments to pass to Processing as arguments
sketch_args: list[str] = None - command line arguments that become Sketch arguments
Expand All @@ -27,7 +28,7 @@ When programming in [module mode](content-py5-modes-module-mode) and [imported m

When running a Sketch asynchronously through Jupyter Notebook, any `print` statements using Python's builtin function will always appear in the output of the currently active cell. This will rarely be desirable, as the active cell will keep changing as the user executes code elsewhere in the notebook. As an alternative, use py5's [](sketch_println) method, which will place all text in the output of the cell that made the `run_sketch()` call. This will continue to be true if the user moves on to execute code in other Notebook cells. Use [](sketch_set_println_stream) to customize this behavior. All py5 error messages and stack traces are routed through the [](sketch_println) method. Be aware that some error messages and warnings generated inside the Processing Jars cannot be controlled in the same way, and may appear in the output of the active cell or mixed in with the Jupyter Kernel logs.

The `jclassname` parameter should only be used when programming in Processing Mode. This value must be the canonical name of your Processing Sketch class (i.e. `"org.test.MySketch"`). The class must inherit from `py5.core.SketchBase`. Read py5's online documentation to learn more about Processing Mode.
The `jclassname` parameter should only be used when programming in Processing Mode. This value must be the canonical name of your Processing Sketch class (i.e. `"org.test.MySketch"`). The class must inherit from `py5.core.SketchBase`. To pass parameters to your Processing Sketch class constructor, use the `jclass_params` parameter. Read py5's online documentation to learn more about [Processing Mode](/content/processing_mode).

@@ example
py5.run_sketch(block=True)
Expand Down
3 changes: 2 additions & 1 deletion py5_resources/py5_module/py5/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ def run_sketch(
sketch_args: list[str] = None,
sketch_functions: dict[str, Callable] = None,
jclassname: str = None,
jclass_params: tuple[Any] = (),
_osx_alt_run_method: bool = True,
) -> None:
"""$module_Sketch_run_sketch"""
Expand Down Expand Up @@ -179,7 +180,7 @@ def run_sketch(
)
return
if _py5sketch.is_dead or jclassname:
_py5sketch = Sketch(jclassname=jclassname)
_py5sketch = Sketch(jclassname=jclassname, jclass_params=jclass_params)

_prepare_dynamic_variables(caller_locals, caller_globals)

Expand Down
3 changes: 2 additions & 1 deletion py5_resources/py5_module/py5/sketch.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ def __new__(cls, *args, **kwargs):
def __init__(self, *args, **kwargs):
_instance = kwargs.get("_instance")
jclassname = kwargs.get("jclassname")
jclass_params = kwargs.get("jclass_params", ())

if _instance:
if _instance == getattr(self, "_instance", None):
Expand All @@ -216,7 +217,7 @@ def __init__(self, *args, **kwargs):
)

Sketch._cls = JClass(jclassname) if jclassname else _Sketch
instance = Sketch._cls()
instance = Sketch._cls(*jclass_params)
if not isinstance(instance, _SketchBase):
raise RuntimeError("Java instance must inherit from py5.core.SketchBase")

Expand Down