Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

module mode setup() issue, maybe? #125

Closed
villares opened this issue Aug 16, 2022 · 4 comments · Fixed by #126
Closed

module mode setup() issue, maybe? #125

villares opened this issue Aug 16, 2022 · 4 comments · Fixed by #126

Comments

@villares
Copy link
Collaborator

villares commented Aug 16, 2022

This used to work in module mode, didn't it? Or I'm getting it wrong and the setup disentanglement is just for imported mode?

py5.__version__ '0.8.2.dev0'

Update: it works in '0.8.0a2' it doesn't work in '0.8.1a1'.

from collections import deque  # a double-ended queue
import py5  # check out https://github.com/py5coding 

history = deque(maxlen=512)  # mouse dragged positions

def setup():   # py5 will call this once to set things up
    py5.size(600, 400)
    py5.no_stroke()
    py5.color_mode(py5.HSB)

def draw():   # py5 will call this in a loop
    py5.background(51)
    for i, (x, y) in enumerate(history):
        py5.fill(i / 2, 255, 255, 128)
        py5.circle(x, y, 8 + i / 16)
    if history:
        history.append(history.popleft())

def mouse_dragged():  # py5 will call this when you drag the mouse
    history.append((py5.mouse_x, py5.mouse_y))
    
def key_pressed():   # py5 will call this when a key is pressed
    history.clear()

py5.run_sketch()

Now:

Unable to obtain source code for setup(). Either make it obtainable or create a settings() function for calls to size(), fullscreen(), etc.
When not using the PDE, size() can only be used inside settings().
Remove the size() method from setup(), and add the following:
public void settings() {
  size(600, 400);
}
py5 encountered an error in your code:File "PSurfaceNone.java", line 356, in processing.core.PSurfaceNone$AnimationThread.run
File "PSurfaceAWT.java", line 1386, in processing.awt.PSurfaceAWT$9.callDraw
File "PApplet.java", line 2088, in processing.core.PApplet.handleDraw
File "Sketch.java", line 196, in py5.core.Sketch.setup
File "jdk.proxy2.$Proxy7.java", line -1, in jdk.proxy2.$Proxy7.run_method
File "org.jpype.proxy.JPypeProxy.java", line -1, in org.jpype.proxy.JPypeProxy.invoke
File "org.jpype.proxy.JPypeProxy.java", line -2, in org.jpype.proxy.JPypeProxy.hostInvoke
File "PApplet.java", line 1753, in processing.core.PApplet.size
File "PApplet.java", line 848, in processing.core.PApplet.insideSettings
Exception: Java Exception
The above exception was the direct cause of the following exception:
File "<string>", line 7, in setup
java.lang.IllegalStateException: java.lang.IllegalStateException: size() cannot be used here, see https://processing.org/reference/size_.h
@hx2A
Copy link
Collaborator

hx2A commented Aug 16, 2022

It's the comment after setup():

def setup(): # py5 will call this once to set things up

It will work if you remove the comment.

Last night I said I knew you'd find another bug for me to fix, and you did not disappoint! This is a stupid error in the split setup code that most likely has been in py5 for a long time. It shouldn't be difficult to fix. Thanks for finding this!

@hx2A hx2A mentioned this issue Aug 16, 2022
@hx2A hx2A closed this as completed in #126 Aug 16, 2022
hx2A added a commit that referenced this issue Aug 16, 2022
@hx2A
Copy link
Collaborator

hx2A commented Aug 16, 2022

This is now fixed. Also fixed a similar problem caused by type hints:

def setup() -> None:
    py5.size(200, 200)

That's valid Python code that should work.

@villares
Copy link
Collaborator Author

Just confirmed! 😄
image

@hx2A
Copy link
Collaborator

hx2A commented Aug 16, 2022

@villares , you are very welcome!!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants