py5coding / py5generator

Meta-programming project that creates the py5 library code.
https://py5coding.org/
GNU General Public License v3.0
52 stars 13 forks source link

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

Closed hx2A closed 2 years ago

hx2A commented 2 years ago

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.

tabreturn commented 2 years ago

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 :+1:

villares commented 2 years ago

A bit of context: pyp5js wasn't working "in static mode" so I got into the habit of making students work static sketches in setup()

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

On Thu, 23 Jun 2022, 06:38 tabreturn, @.***> wrote:

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 👍

— Reply to this email directly, view it on GitHub https://github.com/py5coding/py5generator/issues/89#issuecomment-1164182465, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA4GADATLVSHX2NN5LV7CWTVQQV73ANCNFSM5ZNX75ZQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

hx2A commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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