Skip to content

Commit

Permalink
Merge pull request #357 from hx2A/fix354
Browse files Browse the repository at this point in the history
Fix #354
  • Loading branch information
hx2A committed Oct 1, 2023
2 parents 7f833df + 227bbe8 commit 8d7697a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion py5_docs/Reference/api_en/Py5Graphics_load_shape.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ Loads geometry into a variable of type `Py5Shape`. SVG and OBJ files may be load

Alternatively, the file maybe be loaded from anywhere on the local computer using an absolute path (something that starts with / on Unix and Linux, or a drive letter on Windows), or the filename parameter can be a URL for a file found on a network.

If the file is not available or an error occurs, `None` will be returned and an error message will be printed to the console. The error message does not halt the program, however the `None` value may cause errors if your code does not check whether the value returned is `None`.
If the shape file is not available or an error occurs, an exception will be thrown.

This method is the same as [](sketch_load_shape) but linked to a `Py5Graphics` object. To see example code for how it can be used, see [](sketch_load_shape).
2 changes: 1 addition & 1 deletion py5_docs/Reference/api_en/Sketch_load_shape.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Loads geometry into a variable of type `Py5Shape`. SVG and OBJ files may be load

Alternatively, the file maybe be loaded from anywhere on the local computer using an absolute path (something that starts with / on Unix and Linux, or a drive letter on Windows), or the filename parameter can be a URL for a file found on a network.

If the file is not available or an error occurs, `None` will be returned and an error message will be printed to the console. The error message does not halt the program, however the `None` value may cause errors if your code does not check whether the value returned is `None`.
If the shape file is not available or an error occurs, an exception will be thrown.

@@ example
def setup():
Expand Down
26 changes: 19 additions & 7 deletions py5_resources/py5_module/py5/shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,13 @@
from jpype.types import JBoolean, JFloat, JInt

from . import spelling
from .decorators import _convert_hex_color # noqa
from .decorators import _context_wrapper, _convert_hex_color2, _ret_str, _return_color
from .decorators import (
_context_wrapper,
_convert_hex_color,
_convert_hex_color2,
_ret_str,
_return_color,
)
from .pmath import _get_pvector_wrapper # noqa

py5shape_class_members_code = None # DELETE
Expand Down Expand Up @@ -79,15 +84,22 @@ def fix_type(arg):
def _load_py5shape(f):
@functools.wraps(f)
def decorated(self_, *args):
msg, pshape = "", None

try:
return Py5Shape(f(self_, *args))
except JException as e:
if (pshape := f(self_, *args)) is None:
msg = "Processing unable to read shape file"
except Exception as e:
msg = e.message()
if msg == "None":
msg = "shape file cannot be found"
raise RuntimeError(
"cannot load shape " + str(args[0]) + ". error message: " + msg
)

if pshape is None:
raise RuntimeError(
"cannot load shape " + str(args[0]) + ". error message: " + msg
)
else:
return Py5Shape(pshape)

return decorated

Expand Down

0 comments on commit 8d7697a

Please sign in to comment.