Skip to content

Can "_draw_component" methods be removed? #781

@rahulporuri

Description

@rahulporuri

enable/enable/component.py

Lines 344 to 350 in a1a6059

def _draw_component(self, gc, view_bounds=None, mode="normal"):
""" Renders the component.
Subclasses must implement this method to actually render themselves.
Note: This method is used only by the "old" drawing calls.
"""
pass

enable/enable/container.py

Lines 601 to 616 in a1a6059

def _draw_component(self, gc, view_bounds=None, mode="normal"):
""" Draws the component.
This method is preserved for backwards compatibility. Overrides
the implementation in Component.
"""
with gc:
gc.set_antialias(False)
self._draw_container(gc, mode)
self._draw_background(gc, view_bounds, mode)
self._draw_underlay(gc, view_bounds, mode)
self._draw_children(
gc, view_bounds, mode
) # This was children_draw_mode
self._draw_overlays(gc, view_bounds, mode)

These seem to have been introduced in the commit - d8fc3d1. This commit seems to have changed the DEFAULT_DRAWING_ORDER to what we are mostly familiar with - "background", "mainlayer", "border", "overlay". _draw_component seems to have been introduced as a backwards compatibility measure.

As you can see from here -

enable/enable/component.py

Lines 787 to 799 in a1a6059

for layer in self.draw_order:
if layer != "overlay":
self._dispatch_draw(layer, bb, view_bounds, mode)
self._backbuffer = bb
self.draw_valid = True
# Blit the backbuffer and then draw the overlay on top
gc.draw_image(self._backbuffer, (x, y, width, height))
self._dispatch_draw("overlay", gc, view_bounds, mode)
else:
for layer in self.draw_order:
self._dispatch_draw(layer, gc, view_bounds, mode)
- the _dispatch_draw methods looks for methods like e.g. _draw_mainlayer where layer is mainlayer. And there are no layer which is container so we should be able to remove the _draw_container methods.

enable/enable/component.py

Lines 815 to 817 in a1a6059

handler = getattr(self, "_draw_" + layer, None)
if handler:
handler(gc, view_bounds, mode)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions