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

run_sketch utility won't leave the window open if the sketch has setup() but no draw() #89

Closed
hx2A opened this issue Jun 21, 2022 · 7 comments

Comments

@hx2A
Copy link
Collaborator

hx2A commented Jun 21, 2022

When I put this in Thonny and run it:

def setup():
    size(400, 400)
    rect(10, 10, 20, 20)

The window appears for a split second and then exits. If I add this:

def draw():
    pass

Then the window appears. Need the same dummy draw method trick I use for static sketches.

@hx2A hx2A changed the title run_sketch utility won't leave the window open in the sketch has a setup() method but no draw() method run_sketch utility won't leave the window open if the sketch has a setup() method but no draw() method Jun 21, 2022
@hx2A hx2A changed the title run_sketch utility won't leave the window open if the sketch has a setup() method but no draw() method run_sketch utility won't leave the window open if the sketch has setup() but no draw() Jun 21, 2022
@tabreturn
Copy link

Seems like an odd scenario -- like, why bother with setup() at all? Then again, Processing.py will resort to static mode behavior -- so your dummy draw proposal replicates that 👍

@villares
Copy link
Collaborator

villares commented Jun 23, 2022 via email

@hx2A
Copy link
Collaborator Author

hx2A commented Jun 23, 2022

Seems like an odd scenario -- like, why bother with setup() at all? Then again, Processing.py will resort to static mode behavior -- so your dummy draw proposal replicates that 👍

Right, it is an odd scenario, but it should still work in that situation. I don't think it will be a hard fix.

Now, pedagogically, I find it useful to make students work in setup(), makes the transition to setup/draw easier.

What if they don't know about functions yet?

@villares
Copy link
Collaborator

villares commented Jun 23, 2022

What if they don't know about functions yet?

Yep, that's a challenge. Some noise they are putting up with!
"Trust me, put your code indented into this setup() block here and py5 will call this for you. I'll explain this def thing later."
It might indeed be a bad idea, I'm not sure. I had to use it with pyp5js and rationalized it probably.

I noticed I use it in my own static sketches too. It lets me put the helper functions down the listing.

@hx2A
Copy link
Collaborator Author

hx2A commented Jun 24, 2022

Yep, that's a challenge. Some noise they are putting up with!

Maybe consider using py5bot to help with that! Here's a notebook I used to do just that in a intro presentation two weeks ago:

https://github.com/py5coding/py5examples/blob/main/Python%20with%20py5bot/Intro%20to%20Python%20with%20py5bot.ipynb

@hx2A
Copy link
Collaborator Author

hx2A commented Jul 7, 2022

When I put this in Thonny and run it:

def setup():
    size(400, 400, P2D)
    rect(10, 10, 20, 20)

the window stays open, as it should. This bug only affects Sketches that use the default renderer.

Also, this bug is related to #82. A proper fix for #82 will fix this bug as well. Any fix for this issue that does not also fix #82 is a hack.

hx2A added a commit that referenced this issue Jul 10, 2022
@hx2A
Copy link
Collaborator Author

hx2A commented Jul 10, 2022

I fixed two seemingly unrelated bugs by removing one line of code. :)

@hx2A hx2A closed this as completed Jul 10, 2022
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

No branches or pull requests

3 participants