Skip to content

Commit 55b3baf

Browse files
committed
release 0.5a0
1 parent 800820a commit 55b3baf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+2342
-630
lines changed

Diff for: CODE_OF_CONDUCT.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ representative at an online or offline event.
6060
## Enforcement
6161

6262
Instances of abusive, harassing, or otherwise unacceptable behavior may be
63-
reported to the community leaders responsible for enforcement at
64-
[INSERT CONTACT METHOD].
63+
reported to the community leaders responsible for enforcement.
6564
All complaints will be reviewed and investigated promptly and fairly.
6665

6766
All community leaders are obligated to respect the privacy and security of the

Diff for: README.rst

+50-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,59 @@
11
py5
22
---
33

4-
py5 is a new version of Processing_ for Python 3.8+. It makes the Processing_ Java libraries available to the CPython interpreter using JPype_.
4+
.. image:: https://img.shields.io/pypi/dm/py5?label=py5%20PyPI%20downloads
55

6-
This entire repository is created by the meta-programming project py5generator_. Therefore, this code should not be edited manually. Any issues, etc, should be directed to the py5generator_ repository.
6+
.. image:: https://mybinder.org/badge_logo.svg
7+
:target: https://mybinder.org/v2/gh/hx2A/py5examples/HEAD?urlpath=lab
8+
9+
py5 is a new version of Processing_ for Python 3.8+. It makes the Processing_ Java libraries available to the CPython interpreter using JPype_. It can do just about everything Processing_ can do, except with Python instead of Java code.
10+
11+
The goal of py5 is to create a new version of Processing that is integrated into the Python ecosystem. Built into the library are thoughtful choices about how to best get py5 to work with other popular Python libraries such as `numpy
12+
<https://www.numpy.org/>`_ or `Pillow
13+
<https://python-pillow.org/>`_.
14+
15+
Here is a simple example of a working py5 Sketch:
16+
17+
.. code::
18+
19+
import py5
20+
21+
22+
def setup():
23+
py5.size(200, 200)
24+
py5.rect_mode(py5.CENTER)
25+
26+
27+
def draw():
28+
py5.square(py5.mouse_x, py5.mouse_y, 10)
29+
30+
31+
py5.run_sketch()
32+
33+
34+
35+
If you have Java 11 installed on your computer, you can install py5 using pip:
36+
37+
.. code::
38+
39+
pip install py5
40+
41+
`Detailed installation instructions
42+
<http://py5.ixora.io/install/>`_ are available on the documentation website. There are some `Special Notes for Mac Users
43+
<http://py5.ixora.io/tutorials/mac-users/>`_ that you should read if you use OSX.
44+
45+
There are currently four basic ways to use py5. They are:
46+
47+
- **module mode**, as shown above
48+
- **class mode**: create a Python class inherited from ``py5.Sketch``, and support multiple Sketches running at the same time.
49+
- **imported mode**: simplified code that omits the ``py5.`` prefix. This mode is supported by the py5 Jupyter notebook kernel and the ``run_sketch`` command line utility.
50+
- **static mode**: functionless code to create static images. This mode is supported by the py5bot Jupyter notebook kernel and the ``%%py5bot`` IPython magic.
51+
52+
The py5 library is created by the meta-programming project py5generator_. Therefore, the py5 code should not be changed manually. Any issues, etc, should be directed to the py5generator_ repository.
753

854
The `py5 documentation website
9-
<http://py5.ixora.io/>`_ provides basic tutorials and reference documentation. See py5examples_ for example code.
55+
<http://py5.ixora.io/>`_ provides basic tutorials and reference documentation. The website is very much a work in progress. The `reference documentation
56+
<http://py5.ixora.io/reference/>`_ is solid but the how-to's and tutorials need a lot of work. See the py5examples_ repository for some working examples.
1057

1158
.. _Processing: https://github.com/processing/processing4
1259
.. _JPype: https://github.com/jpype-project/jpype

Diff for: py5/__init__.py

+464-272
Large diffs are not rendered by default.

Diff for: py5/graphics.py

+24-20
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from jpype import JClass
2929

3030
from .base import Py5Base
31-
from .mixins import PixelMixin
31+
from .mixins import PixelPy5GraphicsMixin
3232
from .font import Py5Font # noqa
3333
from .shader import Py5Shader, _return_py5shader, _load_py5shader # noqa
3434
from .shape import Py5Shape, _return_py5shape, _load_py5shape # noqa
@@ -49,7 +49,7 @@ def decorated(self_, *args):
4949
_Py5GraphicsHelper = JClass('py5.core.Py5GraphicsHelper')
5050

5151

52-
class Py5Graphics(PixelMixin, Py5Base):
52+
class Py5Graphics(PixelPy5GraphicsMixin, Py5Base):
5353
"""Main graphics and rendering context, as well as the base ``API`` implementation
5454
for processing "core".
5555

@@ -65,6 +65,11 @@ class Py5Graphics(PixelMixin, Py5Base):
6565
``Py5Graphics.end_draw()`` methods (see example) are necessary to set up the
6666
buffer and to finalize it. The fields and methods for this class are extensive.
6767

68+
It is critically important that calls to this object's drawing methods are only
69+
used between ``Py5Graphics.begin_draw()`` and ``Py5Graphics.end_draw()``.
70+
Forgetting to call ``Py5Graphics.begin_draw()`` will likely result in an ugly
71+
and unhelpful Java exception.
72+
6873
To create a new graphics context, use the ``create_graphics()`` function. Do not
6974
use the syntax ``Py5Graphics()``.
7075
"""
@@ -306,21 +311,19 @@ def _get_pixel_density(self) -> int:
306311
pixel_density: int = property(fget=_get_pixel_density)
307312

308313
def _get_pixel_height(self) -> int:
309-
"""When ``pixel_density(2)`` was used in ``settings()`` to make use of a high
310-
resolution display (called a Retina display on OSX or high-dpi on Windows and
311-
Linux), the width and height of the Py5Graphics drawing surface does not change,
312-
but the number of pixels is doubled.
314+
"""Height of the Py5Graphics drawing surface in pixels.
313315

314316
Underlying Java field: PGraphics.pixelHeight
315317

316318
Notes
317319
-----
318320

319-
When ``pixel_density(2)`` was used in ``settings()`` to make use of a high
320-
resolution display (called a Retina display on OSX or high-dpi on Windows and
321-
Linux), the width and height of the Py5Graphics drawing surface does not change,
322-
but the number of pixels is doubled. As a result, all operations that use pixels
323-
(like ``Py5Graphics.load_pixels()``, ``Py5Graphics.get()``, etc.) happen in this
321+
Height of the Py5Graphics drawing surface in pixels. When ``pixel_density(2)``
322+
was used in ``settings()`` to make use of a high resolution display (called a
323+
Retina display on OSX or high-dpi on Windows and Linux), the width and height of
324+
the Py5Graphics drawing surface does not change, but the number of pixels is
325+
doubled. As a result, all operations that use pixels (like
326+
``Py5Graphics.load_pixels()``, ``Py5Graphics.get()``, etc.) happen in this
324327
doubled space. As a convenience, the variables ``Py5Graphics.pixel_width`` and
325328
``pixel_height`` hold the actual width and height of the drawing surface in
326329
pixels. This is useful for any Py5Graphics objects that use the
@@ -335,21 +338,19 @@ def _get_pixel_height(self) -> int:
335338
pixel_height: int = property(fget=_get_pixel_height)
336339

337340
def _get_pixel_width(self) -> int:
338-
"""When ``pixel_density(2)`` was used in ``settings()`` to make use of a high
339-
resolution display (called a Retina display on OSX or high-dpi on Windows and
340-
Linux), the width and height of the Py5Graphics drawing surface does not change,
341-
but the number of pixels is doubled.
341+
"""Width of the Py5Graphics drawing surface in pixels.
342342

343343
Underlying Java field: PGraphics.pixelWidth
344344

345345
Notes
346346
-----
347347

348-
When ``pixel_density(2)`` was used in ``settings()`` to make use of a high
349-
resolution display (called a Retina display on OSX or high-dpi on Windows and
350-
Linux), the width and height of the Py5Graphics drawing surface does not change,
351-
but the number of pixels is doubled. As a result, all operations that use pixels
352-
(like ``Py5Graphics.load_pixels()``, ``Py5Graphics.get()``, etc.) happen in this
348+
Width of the Py5Graphics drawing surface in pixels. When ``pixel_density(2)``
349+
was used in ``settings()`` to make use of a high resolution display (called a
350+
Retina display on OSX or high-dpi on Windows and Linux), the width and height of
351+
the Py5Graphics drawing surface does not change, but the number of pixels is
352+
doubled. As a result, all operations that use pixels (like
353+
``Py5Graphics.load_pixels()``, ``Py5Graphics.get()``, etc.) happen in this
353354
doubled space. As a convenience, the variables ``pixel_width`` and
354355
``Py5Graphics.pixel_height`` hold the actual width and height of the drawing
355356
surface in pixels. This is useful for any Py5Graphics objects that use the
@@ -7220,6 +7221,9 @@ def hint(self, which: int, /) -> None:
72207221
options might graduate to standard features instead of hints over time, or be
72217222
added and removed between (major) releases.
72227223

7224+
Like other ``Py5Graphics`` methods, ``hint()`` can only be used between calls to
7225+
``Py5Graphics.begin_draw()`` and ``Py5Graphics.end_draw()``.
7226+
72237227
Hints used by the Default Renderer
72247228
----------------------------------
72257229

Diff for: py5/image.py

+47-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from typing import overload, List, Union # noqa
2424

2525
from .base import Py5Base
26-
from .mixins import PixelMixin
26+
from .mixins import PixelPy5ImageMixin
2727

2828

2929
def _return_py5image(f):
@@ -37,7 +37,7 @@ def decorated(self_, *args):
3737
return decorated
3838

3939

40-
class Py5Image(PixelMixin, Py5Base):
40+
class Py5Image(PixelPy5ImageMixin, Py5Base):
4141
"""Datatype for storing images.
4242
4343
Underlying Java class: PImage.PImage
@@ -117,6 +117,51 @@ def _get_height(self) -> int:
117117
return self._instance.height
118118
height: int = property(fget=_get_height)
119119

120+
def _get_pixel_density(self) -> int:
121+
"""Pixel density of the Py5Image object.
122+
123+
Underlying Java field: PImage.pixelDensity
124+
125+
Notes
126+
-----
127+
128+
Pixel density of the Py5Image object. This will always be equal to 1, even if
129+
the Sketch used ``pixel_density()`` to set the pixel density to a value greater
130+
than 1.
131+
"""
132+
return self._instance.pixelDensity
133+
pixel_density: int = property(fget=_get_pixel_density)
134+
135+
def _get_pixel_height(self) -> int:
136+
"""Height of the Py5Image object in pixels.
137+
138+
Underlying Java field: PImage.pixelHeight
139+
140+
Notes
141+
-----
142+
143+
Height of the Py5Image object in pixels. This will be the same as
144+
``Py5Image.height``, even if the Sketch used ``pixel_density()`` to set the
145+
pixel density to a value greater than 1.
146+
"""
147+
return self._instance.pixelHeight
148+
pixel_height: int = property(fget=_get_pixel_height)
149+
150+
def _get_pixel_width(self) -> int:
151+
"""Width of the Py5Image object in pixels.
152+
153+
Underlying Java field: PImage.pixelWidth
154+
155+
Notes
156+
-----
157+
158+
Width of the Py5Image object in pixels. This will be the same as
159+
``Py5Image.width``, even if the Sketch used ``pixel_density()`` to set the pixel
160+
density to a value greater than 1.
161+
"""
162+
return self._instance.pixelWidth
163+
pixel_width: int = property(fget=_get_pixel_width)
164+
120165
def _get_pixels(self) -> NDArray[(Any,), Int]:
121166
"""The pixels[] array contains the values for all the pixels in the image.
122167

Diff for: py5/jars/core.jar

-141 KB
Binary file not shown.

Diff for: py5/jars/dxf/dxf.jar

0 Bytes
Binary file not shown.

Diff for: py5/jars/gluegen-rt-natives-linux-aarch64.jar

-5 Bytes
Binary file not shown.

Diff for: py5/jars/gluegen-rt-natives-linux-amd64.jar

-2 Bytes
Binary file not shown.

Diff for: py5/jars/gluegen-rt-natives-linux-armv6hf.jar

-6 Bytes
Binary file not shown.

Diff for: py5/jars/gluegen-rt-natives-linux-i586.jar

-2 Bytes
Binary file not shown.

Diff for: py5/jars/gluegen-rt-natives-macosx-universal.jar

-1 Bytes
Binary file not shown.

Diff for: py5/jars/gluegen-rt-natives-windows-amd64.jar

-1 Bytes
Binary file not shown.

Diff for: py5/jars/gluegen-rt-natives-windows-i586.jar

-2 Bytes
Binary file not shown.

Diff for: py5/jars/gluegen-rt.jar

-2 Bytes
Binary file not shown.

Diff for: py5/jars/javafx-swt.jar

-35.9 KB
Binary file not shown.

Diff for: py5/jars/javafx.base.jar

-732 KB
Binary file not shown.

Diff for: py5/jars/javafx.controls.jar

-2.39 MB
Binary file not shown.

Diff for: py5/jars/javafx.fxml.jar

-124 KB
Binary file not shown.

Diff for: py5/jars/javafx.graphics.jar

-4.21 MB
Binary file not shown.

Diff for: py5/jars/javafx.media.jar

-270 KB
Binary file not shown.

Diff for: py5/jars/javafx.swing.jar

-117 KB
Binary file not shown.

Diff for: py5/jars/javafx.web.jar

-696 KB
Binary file not shown.

Diff for: py5/jars/jogl-all-natives-linux-aarch64.jar

-6 Bytes
Binary file not shown.

Diff for: py5/jars/jogl-all-natives-linux-amd64.jar

-2 Bytes
Binary file not shown.

Diff for: py5/jars/jogl-all-natives-linux-armv6hf.jar

-6 Bytes
Binary file not shown.

Diff for: py5/jars/jogl-all-natives-linux-i586.jar

-2 Bytes
Binary file not shown.

Diff for: py5/jars/jogl-all-natives-macosx-universal.jar

-2 Bytes
Binary file not shown.

Diff for: py5/jars/jogl-all-natives-windows-amd64.jar

-4 Bytes
Binary file not shown.

Diff for: py5/jars/jogl-all-natives-windows-i586.jar

-3 Bytes
Binary file not shown.

Diff for: py5/jars/jogl-all.jar

580 Bytes
Binary file not shown.

Diff for: py5/jars/pdf/pdf.jar

0 Bytes
Binary file not shown.

Diff for: py5/jars/py5.jar

781 Bytes
Binary file not shown.

Diff for: py5/jars/svg/svg.jar

-42 Bytes
Binary file not shown.

Diff for: py5/java_conversion.py

+2
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@ def init_jpype_converters():
2828
data = [
2929
("processing.core.PImage", Py5Image),
3030
("processing.core.PImage", Py5Graphics),
31+
("processing.core.PGraphics", Py5Graphics),
3132
("processing.core.PFont", Py5Font),
3233
("processing.core.PShape", Py5Shape),
3334
("processing.opengl.PShader", Py5Shader),
3435
("processing.core.PApplet", Sketch),
36+
("py5.core.Sketch", Sketch),
3537
]
3638

3739
def convert(jcls, obj):

Diff for: py5/methods.py

+22-8
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,31 @@
1818
#
1919
# *****************************************************************************
2020
import sys
21+
import re
2122
from pathlib import Path
2223
from collections import defaultdict
2324
from typing import Union
2425
import line_profiler
2526

26-
from jpype import JImplements, JOverride, JString, JClass
27+
from jpype import JImplements, JOverride, JString
2728

2829
import stackprinter
2930

31+
import py5_tools
3032
from . import custom_exceptions
3133

32-
33-
_JavaNullPointerException = JClass('java.lang.NullPointerException')
34-
3534
# *** stacktrace configuration ***
3635
# set stackprinter color style. Default is plaintext. Other choices are darkbg,
3736
# darkbg2, darkbg3, lightbg, lightbg2, lightbg3.
3837
_stackprinter_style = 'plaintext'
3938
# prune tracebacks to only show only show stack levels in the user's py5 code.
4039
_prune_tracebacks = True
41-
_module_install_dir = str(Path(__file__).parent)
4240

41+
_MODULE_INSTALL_DIR = str(Path(__file__).parent)
42+
_PY5TOOLS_MODULE_INSTALL_DIR = str(Path(py5_tools.__file__).parent)
43+
44+
_PY5_STATIC_CODE_FILENAME_REGEX = re.compile(
45+
r'File "[^\"]*?_PY5_STATIC_(SETUP|SETTINGS|FRAMEWORK)_CODE_\.py", line \d+, in .*')
4346

4447
_EXCEPTION_MSGS = {
4548
**custom_exceptions.CUSTOM_EXCEPTION_MSGS,
@@ -78,11 +81,16 @@ def handle_exception(println, exc_type, exc_value, exc_tb):
7881
tb = exc_tb.tb_next
7982
while hasattr(tb, 'tb_next') and hasattr(tb, 'tb_frame'):
8083
f_code = tb.tb_frame.f_code
81-
if f_code.co_filename.startswith(_module_install_dir):
82-
py5info.append((Path(f_code.co_filename[(len(_module_install_dir) + 1):]).parts,
84+
if f_code.co_filename.startswith(_MODULE_INSTALL_DIR):
85+
py5info.append((Path(f_code.co_filename[(len(_MODULE_INSTALL_DIR) + 1):]).parts,
8386
f_code.co_name))
8487
if trim_tb is None:
8588
trim_tb = prev_tb
89+
elif f_code.co_filename.startswith(_PY5TOOLS_MODULE_INSTALL_DIR):
90+
py5info.append((Path(f_code.co_filename[(
91+
len(_PY5TOOLS_MODULE_INSTALL_DIR) + 1):]).parts, f_code.co_name))
92+
if trim_tb is None:
93+
trim_tb = prev_tb
8694
prev_tb = tb
8795
tb = tb.tb_next
8896
if trim_tb:
@@ -97,7 +105,8 @@ def handle_exception(println, exc_type, exc_value, exc_tb):
97105
show_vals='line',
98106
style=_stackprinter_style,
99107
suppressed_paths=[r"lib/python.*?/site-packages/numpy/",
100-
r"lib/python.*?/site-packages/py5/"])
108+
r"lib/python.*?/site-packages/py5/",
109+
r"lib/python.*?/site-packages/py5tools/"])
101110

102111
if _prune_tracebacks:
103112
errmsg = errmsg.replace(
@@ -108,6 +117,11 @@ def handle_exception(println, exc_type, exc_value, exc_tb):
108117
str(exc_value),
109118
py5info))
110119

120+
m = _PY5_STATIC_CODE_FILENAME_REGEX.search(errmsg)
121+
if m:
122+
errmsg = "py5 encountered an error in your code:" + \
123+
errmsg[m.span()[1]:]
124+
111125
println(errmsg, stderr=True)
112126

113127
sys.last_type, sys.last_value, sys.last_traceback = exc_type, exc_value, exc_tb

Diff for: py5/mixins/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@
2020
from .math import MathMixin # noqa
2121
from .data import DataMixin # noqa
2222
from .threads import ThreadsMixin # noqa
23-
from .pixels import PixelMixin # noqa
23+
from .pixels import PixelMixin, PixelPy5GraphicsMixin, PixelPy5ImageMixin # noqa
2424
from .print_tools import PrintlnStream, _WidgetPrintlnStream, _DefaultPrintlnStream, _DisplayPubPrintlnStream # noqa

0 commit comments

Comments
 (0)