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

Feature request: with function()-Feature #41

Closed
kantel opened this issue Sep 11, 2021 · 5 comments
Closed

Feature request: with function()-Feature #41

kantel opened this issue Sep 11, 2021 · 5 comments

Comments

@kantel
Copy link

kantel commented Sep 11, 2021

Processing.py has some syntatic sugar with the with function()-Feature (I documented it here – sorry in German only). With its indents it feels more pythonic the push_matrix()pop_matrix(). I missed these feature in Py5 and I would like to have it.

But it's not a show stopper and not very urgent. I only want to say that there is something missing. And pls excuse my bad (d)english.

BTW: I'm working with Py5 on macOS X (Catalina 10.15.7) with Thonny and Tristan Bunn's Thonny-Plugin for Py5.

@hx2A
Copy link
Collaborator

hx2A commented Sep 11, 2021

@kantel Thank you for the suggestion! I understand what you are asking for: I recall @villares mentioned this feature a while back. I agree, it would be nice syntactic sugar to have in py5. I'll work on adding it for the next release. I don't think I can make it exactly as it is in processing.py, but I will do what I can to make it as close as possible.

hx2A added a commit that referenced this issue Sep 19, 2021
@hx2A
Copy link
Collaborator

hx2A commented Sep 19, 2021

@kantel I started working on this today and have a working prototype. The following code works, demonstrating that the push_matrix() context manager is re-entrant and can still be used the regular way.

size(250, 250)
rect_mode(CENTER)

translate(50, 50)
rect(0, 0, 20, 20)

with push_matrix():
    translate(50, 50)
    rect(0, 0, 15, 15)
    with push_matrix():
        translate(50, 50)
        rect(0, 0, 10, 10)
        push_matrix()
        translate(50, 50)
        rect(0, 0, 5, 5)
        pop_matrix()

rect(0, 0, 5, 5)

Later this week I'll expand it to work for push_style(), begin_shape(), etc.

@kantel
Copy link
Author

kantel commented Sep 19, 2021

Cool. Thanks!

@hx2A
Copy link
Collaborator

hx2A commented Sep 19, 2021

I was feeling inspired and now have begin_shape() and begin_closed_shape() working:

size(250, 250)

translate(125, 125)
with begin_closed_shape():
    vertex(-50, -50)
    vertex(50, -50)
    vertex(50, 50)
    vertex(-50, 50)

begin_closed_shape() was the hard part. Now that that's done, I just have to add the feature to the relevant functions and update the reference documentation.

@hx2A
Copy link
Collaborator

hx2A commented Sep 28, 2021

I finished this a few days ago. Next release will be in October sometime.

@hx2A hx2A closed this as completed Sep 28, 2021
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

2 participants