Skip to content

Commit c10c2d4

Browse files
committed
release 0.9.1a1
1 parent 479699e commit c10c2d4

File tree

16 files changed

+1133
-381
lines changed

16 files changed

+1133
-381
lines changed

py5/__init__.py

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,15 @@
8989
pass
9090

9191

92-
__version__ = '0.9.0a0'
92+
__version__ = '0.9.1a1'
9393

9494
_PY5_USE_IMPORTED_MODE = py5_tools.get_imported_mode()
9595
py5_tools._lock_imported_mode()
9696

9797
object_conversion.init_jpype_converters()
9898

99+
warnings.filterwarnings("once", category=DeprecationWarning, module="py5")
100+
99101

100102
_py5sketch = Sketch()
101103

@@ -2786,8 +2788,6 @@ def bezier_vertex(*args):
27862788
def bezier_vertices(coordinates: npt.NDArray[np.floating], /) -> None:
27872789
"""Create a collection of bezier vertices.
27882790

2789-
Underlying Processing method: PApplet.bezierVertices
2790-
27912791
Parameters
27922792
----------
27932793

@@ -6395,8 +6395,6 @@ def curve_vertex(*args):
63956395
def curve_vertices(coordinates: npt.NDArray[np.floating], /) -> None:
63966396
"""Create a collection of curve vertices.
63976397

6398-
Underlying Processing method: PApplet.curveVertices
6399-
64006398
Parameters
64016399
----------
64026400

@@ -9269,8 +9267,6 @@ def line(*args):
92699267
def lines(coordinates: npt.NDArray[np.floating], /) -> None:
92709268
"""Draw a collection of lines to the screen.
92719269

9272-
Underlying Processing method: PApplet.lines
9273-
92749270
Parameters
92759271
----------
92769272

@@ -10705,8 +10701,6 @@ def points(coordinates: npt.NDArray[np.floating], /) -> None:
1070510701
"""Draw a collection of points, each a coordinate in space at the dimension of one
1070610702
pixel.
1070710703

10708-
Underlying Processing method: PApplet.points
10709-
1071010704
Parameters
1071110705
----------
1071210706

@@ -11114,8 +11108,6 @@ def quadratic_vertex(*args):
1111411108
def quadratic_vertices(coordinates: npt.NDArray[np.floating], /) -> None:
1111511109
"""Create a collection of quadratic vertices.
1111611110

11117-
Underlying Processing method: PApplet.quadraticVertices
11118-
1111911111
Parameters
1112011112
----------
1112111113

@@ -17331,8 +17323,6 @@ def vertex(*args):
1733117323
def vertices(coordinates: npt.NDArray[np.floating], /) -> None:
1733217324
"""Create a collection of vertices.
1733317325

17334-
Underlying Processing method: PApplet.vertices
17335-
1733617326
Parameters
1733717327
----------
1733817328

@@ -21047,8 +21037,8 @@ class mode. Don't forget you can always replace the `draw()` function in a
2104721037
Mode. This value must be the canonical name of your Processing Sketch class
2104821038
(i.e. `"org.test.MySketch"`). The class must inherit from `py5.core.SketchBase`.
2104921039
Read py5's online documentation to learn more about Processing Mode."""
21050-
caller_globals = inspect.stack()[1].frame.f_globals
2105121040
caller_locals = inspect.stack()[1].frame.f_locals
21041+
caller_globals = inspect.stack()[1].frame.f_globals
2105221042
functions, function_param_counts = bridge._extract_py5_user_function_data(
2105321043
sketch_functions if sketch_functions else caller_locals)
2105421044
functions = _split_setup.transform(
@@ -21078,13 +21068,12 @@ class mode. Don't forget you can always replace the `draw()` function in a
2107821068

2107921069
_prepare_dynamic_variables(caller_locals, caller_globals)
2108021070

21081-
_py5sketch._run_sketch(
21082-
functions,
21083-
function_param_counts,
21084-
block,
21085-
py5_options,
21086-
sketch_args,
21087-
_osx_alt_run_method)
21071+
_py5sketch._run_sketch(functions, function_param_counts, block,
21072+
py5_options=py5_options,
21073+
sketch_args=sketch_args,
21074+
_caller_locals=caller_locals,
21075+
_caller_globals=caller_globals,
21076+
_osx_alt_run_method=_osx_alt_run_method)
2108821077

2108921078

2109021079
def get_current_sketch() -> Sketch:

py5/bridge.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ class Py5Bridge:
163163

164164
def __init__(self, sketch):
165165
self._sketch = sketch
166+
self._caller_locals = dict()
167+
self._caller_globals = dict()
166168
self._functions = dict()
167169
self._function_param_counts = dict()
168170
self._pre_hooks = defaultdict(dict)
@@ -175,6 +177,10 @@ def __init__(self, sketch):
175177
self._convert_to_python_types = convert_to_python_types
176178
self._convert_to_java_type = convert_to_java_type
177179

180+
def set_caller_locals_globals(self, locals, globals):
181+
self._caller_locals = locals
182+
self._caller_globals = globals
183+
178184
def set_functions(self, functions, function_param_counts):
179185
self._function_param_counts = dict()
180186
self._functions = dict()
@@ -283,9 +289,20 @@ def _get_current_running_method(self):
283289

284290
@JOverride
285291
def call_function(self, key, params):
286-
d = py5_tools.config._PY5_PROCESSING_MODE_KEYS
287292
try:
288-
*str_hierarchy, c = str(key).split('.')
293+
key = str(key)
294+
*str_hierarchy, c = key.split('.')
295+
key_start = key.split('.')[0]
296+
297+
if key_start in py5_tools.config._PY5_PROCESSING_MODE_KEYS:
298+
d = py5_tools.config._PY5_PROCESSING_MODE_KEYS
299+
elif key_start in self._caller_locals:
300+
d = self._caller_locals
301+
elif key_start in self._caller_globals:
302+
d = self._caller_globals
303+
else:
304+
return _JAVA_RUNTIMEEXCEPTION(
305+
f'callable {c} not found with key {key}')
289306

290307
for s in str_hierarchy:
291308
if s in d:

py5/custom_exceptions.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,20 @@ def handle_nameerror(exc_type_name, exc_msg, py5info):
5656
if m:
5757
fname = m.group(1)
5858
exc_msg = 'The name "' + fname + '" is not defined.'
59-
suggestion_list = spelling.suggestions(
60-
fname, py5_tools.reference.PY5_DIR_STR)
61-
if suggestion_list:
62-
exc_msg += ' Did you mean ' + suggestion_list + '?'
59+
if fname == 'py5':
60+
return exc_msg + (' Your Sketch is also running in Imported Mode. ' +
61+
'Remember that in imported mode you do not access py5\'s methods ' +
62+
'with the `py5.` module prefix.')
63+
elif fname in py5_tools.reference.PY5_DIR_STR:
64+
return exc_msg + (' Your Sketch is also running in Imported Mode. ' +
65+
'If the code throwing this exception was imported into your ' +
66+
'main py5 Sketch code, please ensure the py5 Imported Mode marker ' +
67+
'"# PY5 IMPORTED MODE CODE" has been properly added to the module.')
68+
else:
69+
suggestion_list = spelling.suggestions(
70+
fname, py5_tools.reference.PY5_DIR_STR)
71+
if suggestion_list:
72+
exc_msg += ' Did you mean ' + suggestion_list + '?'
6373

6474
return exc_msg
6575

0 commit comments

Comments
 (0)