typemytype / drawbot

http://www.drawbot.com
Other
398 stars 61 forks source link

with context for newDrawing() / endDrawing() #474

Closed roberto-arista closed 1 year ago

roberto-arista commented 2 years ago

👋

I find myself more and more running drawBot outside of the app, and I often encapsulate my code between newDrawing() and endDrawing(). Would you be open to add a with context as with savedState() to the API?

If yes, I could take care of opening a pull request using savedState as a reference : )

justvanrossum commented 2 years ago

Yes.

What name do you propose?

with newDrawing():
    ....

Or a new name?

roberto-arista commented 2 years ago

I assume

with newDrawing():
    ...

could cause overshadowing issues, right?

What about a simple

with drawing():
    ...

?

Maybe too simple?

justvanrossum commented 2 years ago

Or maybe even "Drawing" (cap-D)?

roberto-arista commented 2 years ago

Yep!

typemytype commented 2 years ago

+1

why capitalise? it will not be a class name

justvanrossum commented 2 years ago

Not sure this should be an argument, but in drawbot-skia, the place to implement this, is a class named "Drawing" :) https://github.com/justvanrossum/drawbot-skia/blob/master/src/drawbot_skia/drawing.py

justvanrossum commented 2 years ago

But in terms of API is should probably just be a contextlib.contextmanager function, indeed not unlike savedState(). Perhaps "drawing" is fine, too.