jdf / Processing.py-Bugs

A home for all bugs and feature requests about Python Mode for the Processing Development Environment.
41 stars 8 forks source link

Add context managers for `beginShape()` and `beginDraw()`? #224

Open liavkoren opened 6 years ago

liavkoren commented 6 years ago

Would remove the need to call endShape etc...

jdf commented 6 years ago

Those are already supported; see the WithStatements example.

liavkoren commented 6 years ago

Ah, okay. What confused me is that with beginShape() doesn't work if called on an PGraphic instance -- looks like __exit__ hasn't been implemented on those?

def setup():
    size(650, 650, P3D)
    txt = createGraphics(650, 650)
    with txt.beginDraw():
        txt.line(0, 0, width, height)
    image(txt, 0, 0)

Raises AttributeError.

I don't mind taking a kick at implementing this.

jdf commented 6 years ago

You're welcome to give it a shot. The tricky thing is that you'll have to modify createGraphics to return a Python object that wraps a PGraphics.

liavkoren commented 6 years ago

Do you have any advice on how to bootstrap myself with the project? Should I read about Jython first, or are there Processing.py files that capture the basic patterns, or..?

(O. You're the PeasyCam guy. 👍)

jdf commented 6 years ago

The project is https://github.com/jdf/processing.py, and the relevant source is in https://github.com/jdf/processing.py/tree/master/runtime/src/jycessing, with a lot of the bridge stuff in https://github.com/jdf/processing.py/blob/master/runtime/src/jycessing/core.py, and more in https://github.com/jdf/processing.py/blob/master/runtime/src/jycessing/PAppletJythonDriver.java. Here are instructions for working on the project: https://github.com/jdf/processing.py/blob/master/HOWTO-HACK.txt