typemytype / drawbot

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

add `with drawing()` to public API #475

Closed roberto-arista closed 1 year ago

roberto-arista commented 2 years ago

following this discussion: #474

roberto-arista commented 2 years ago

Hey Just, I've read the docs for contextlib.contextmanager but I am a bit confused on how it applies to this case. The docs say

The function being decorated must return a generator-iterator when called. This iterator must yield exactly one value, which will be bound to the targets in the with statement’s as clause, if any.

How can drawing() return a generator-iterator?

typemytype commented 2 years ago

I will add the expected example test images

justvanrossum commented 2 years ago

As per the example from the docs, it should look roughly like this:

    @contextlib.contextmanager
    def drawing(self):
        self.newDrawing()
        try:
            yield
        finally:
            self.endDrawing()
roberto-arista commented 2 years ago

The code should be fine, now it seems I have to figure out the tests images

typemytype commented 2 years ago

the same contextmanager could be used for savedState

roberto-arista commented 2 years ago

👋

I could not open a separate pull request because this one has not been merged yet. I added the kern feature to the documentation as I discovered by chance that it is supported by openTypeFeatures()

roberto-arista commented 2 years ago

Hey all! Is there anything I can do to push forward this pull request? I think it would be a nice addition to the drawbot API!

roberto-arista commented 2 years ago

🎉

justvanrossum commented 2 years ago

I could not open a separate pull request because this one has not been merged yet.

PR's don't need to be merged in order of creation, especially if their respective changes don't conflict.

And once one is merged, it is possible to rebase the other.

roberto-arista commented 1 year ago

Wait, I thought this was merged, instead it was only approved. I'll reopen the pull request!