What is the problem or limitation you are having?
One of the things I found really confusing when I first started looking at the Canvas API — and to be honest, still trips me up — is the way that in addition to the snake_case-named drawing operation methods, there's the whole other set of identically-named (but CamelCase) methods that do the same thing but as a context manager. It's a lot to take in and make sense of.
Describe the solution you'd like
I have an alternative proposal: why not behave like open(), and consolidate the two behaviors in one method? That way each method is in intuitive snake_case, and is either a simple drawing operation when called alone, or a context manager when invoked through with.
I'm sure the nitty gritty details will inevitably be fiddlier than I anticipate, but I believe the basic idea would be to remove the @contextmanager decorator from the methods, return the context object, and define __enter__ and __exit__ on Context itself.
Describe alternatives you've considered
Fleshing out the documentation — maybe even writing a topic guide for Canvas — would certainly help one grok the naming conventions... Honestly, this would be a good idea in any event, I've just been intimidated by it so far!
Additional context
I see that the current paradigm was put in place in #2029:
To make it clear(er) when an operation is a context producing operation, rather than a simple drawing operation, context-producing operations have been renamed to TitleCase. This also avoids a collision caused by introducing the Canvas.context property; the operation on canvas to produce a new sub-context is now Canvas.Context().
Edit: Current status
We've reached consensus on the shape of the API we're after, described in this comment.
To-do list
What is the problem or limitation you are having?
One of the things I found really confusing when I first started looking at the Canvas API — and to be honest, still trips me up — is the way that in addition to the snake_case-named drawing operation methods, there's the whole other set of identically-named (but CamelCase) methods that do the same thing but as a context manager. It's a lot to take in and make sense of.
Describe the solution you'd like
I have an alternative proposal: why not behave like
open(), and consolidate the two behaviors in one method? That way each method is in intuitive snake_case, and is either a simple drawing operation when called alone, or a context manager when invoked throughwith.I'm sure the nitty gritty details will inevitably be fiddlier than I anticipate, but I believe the basic idea would be to remove the
@contextmanagerdecorator from the methods, return the context object, and define__enter__and__exit__on Context itself.Describe alternatives you've considered
Fleshing out the documentation — maybe even writing a topic guide for Canvas — would certainly help one grok the naming conventions... Honestly, this would be a good idea in any event, I've just been intimidated by it so far!
Additional context
I see that the current paradigm was put in place in #2029:
Edit: Current status
We've reached consensus on the shape of the API we're after, described in this comment.
To-do list
Tighten Canvas backend API and align more with HTML #4057
Rename
DrawingObjecttoDrawingAction#4084Rename Context to State #4114
Split drawing action methods out into mixin class #4105, for sharing between
StateandCanvas(and aPath2Danalogue?)Remove
State.canvasbackreference, combine drawing actions, move drawing methods #4159State's reference to its parentCanvas, makingStateobjects canvas-agnostic.Canvasgets all the drawing methods (which add to currentState), and they're deprecated onState.Add drawing context attributes and save/restore to Canvas #4332
Canvas docs revamp #4362
Align Canvas method parameters better with JavaScript #4330
Turn Canvas transform methods into states #4477
Add keyword parameters to Canvas.state() #4485
Canvas: deprecate write_text, add fill_text & stroke_text #4432
Implement other missing methods / functionality of Context2D, including:
round_rect()onCanvas#4161arc_toonCanvas#4158