ENH: Add pre_draw_event callback#31887
Conversation
| # ValueError can occur when resizing a window. | ||
|
|
||
| artists = self._get_draw_artists(renderer) | ||
| DrawEvent("pre_draw_event", self.canvas, renderer)._process() |
There was a problem hiding this comment.
This seems wrong to me. I think we need a new class for PreDrawEvent as while the code maybe identical, the semantics are quite different (e.g. you can't do any blitting related work)
There was a problem hiding this comment.
Thanks.
What I am planning to do is introduce a dedicated event type (PreRenderEvent) rather than reusing DrawEvent. The callback would still fire at its current location in the pipeline, after layout/geometry calculations but before rendering begins.
Does that sound reasonable?
|
It is not clear to me that "pre draw" is the right name for this. Maybe "pre render" on "LayoutEvent" would be clearer. My confusion is that "pre draw" sounds like it should filre at the very top of |
|
Can we keep the callback private for now? As long as we're only needing this for the overlay system, there is no need to expose this to users. Naming and timing have some issues, which we don't have to fully resolve if it stays private:
|
|
Thanks! I updated the implementation to keep the callback private. Changes made: Renamed pre_render_event to _pre_render_event Updated tests accordingly. |
Closes #17168.
This PR adds a new pre_draw_event callback that is emitted during Figure.draw() after layout and geometry have been finalized but before any rendering occurs.
Currently, draw_event is emitted only after rendering has completed, which makes it difficult for callbacks to inspect or modify artists based on their final geometry before pixels are written to the renderer.
The new event is emitted after _get_draw_artists(renderer) so that:
while still allowing callbacks to run before rendering begins.
One motivating use case is overlay systems that need access to final axes geometry before rendering occurs without requiring an additional draw pass.
Minimum self-contained example
Output:
pre_draw_eventis emitted before rendering begins, whiledraw_eventis emitted after rendering completes.AI Disclosure
AI tools were used to assist in drafting text and suggesting validation scenarios.
All code changes, final implementation decisions, and verification were done manually.
PR checklist