From 5d692b382770c6ac97d8e4673875a54cc072ee59 Mon Sep 17 00:00:00 2001 From: Poruri Sai Rahul Date: Tue, 8 Jun 2021 13:38:07 +0000 Subject: [PATCH] Make chaco v/h plot containers inherit from enable v/h stacked containers (#764) * REF : Redefine class-level attr on StackedPlotContainer subclasses specifically, HPlotContainer and VPlotContainer subclasses. this is a small step towards removing the inheritance from StackedPlotContainer modified: chaco/plot_containers.py * REF : Redefine methods defined on StackedPlotContainer specifically, we redefine get_preferred_size and _do_stack_layout methods on the subclasses of StackedPlotContainer modified: chaco/plot_containers.py * REF : Redefine stack_dimension and other_dimension on subclasses with these two traits, we have finally duplicated all methods and traits defined on the StackedPlotContainer in its subclasses. In the next step, we can finally remove the inheritance from StackedPlotContainer modified: chaco/plot_containers.py * CLN : Remove inheritance from StackedPlotContainer and make the subclasses inherit directly from BasePlotContainer instead. also remove the StackedPlotContainer class. We don't need to worry about external users of StackedPlotContainer as the class is private to this module and isn't exposed outside of this module. See __all__ in chaco.plot_containers modified: chaco/plot_containers.py * REF : Redefine BasePlotContainer traits on subclasses and with this, we can remove their dependence on BasePlotContainer as well modified: chaco/plot_containers.py * REF : chaco stacked plot containers now inherit from enable Container we can now start the process of using stacked container classes in enable modified: chaco/plot_containers.py * CLN : Make HPlotContainer inherit from enable HStackedContainer and remove a number of now redundant trait definitions and methods modified: chaco/plot_containers.py * REF : Make VPlotContainer inherit from enable VStackedContainer and remove a number of now redundant trait and methods definitions. also remove unused imports from enable. modified: chaco/plot_containers.py * FIX : Define necessary private cache trait on VPlotContainer _cached_preferred_size is expected and set by the layout machinery. it is defined explicitly on the HPlotContainer and OverlayPlotContainer but not on the VPlotContainer earlier modified: chaco/plot_containers.py * FIX : Dont import stacked containers from enable.api the classes were added to enable.api on the main branch - and they arent available in a released version yet modified: chaco/plot_containers.py * FIX : Install enable from maint/5.2 branch from git source instead of installing enable 5.1.1 via edm this is a temporary solution until enable 5.2.0 is available via edm - at which point the changes in ci should be removed modified: ci/edmtool.py * FIX : Install GL dependencies even on null toolkit because CI now needs to build enable from source modified: .github/workflows/test-with-edm.yml --- .github/workflows/test-with-edm.yml | 6 ++ chaco/plot_containers.py | 118 ++++++---------------------- ci/edmtool.py | 19 +++++ 3 files changed, 51 insertions(+), 92 deletions(-) diff --git a/.github/workflows/test-with-edm.yml b/.github/workflows/test-with-edm.yml index f9ff7fb0f..5b931b3f9 100644 --- a/.github/workflows/test-with-edm.yml +++ b/.github/workflows/test-with-edm.yml @@ -32,6 +32,12 @@ jobs: sudo apt-get install libxcb-render-util0 sudo apt-get install libxcb-xinerama0 if: matrix.toolkit != 'null' + # NOTE : Temporarily needed for building enable from source + # Should be removed when enable 5.2 is released + - name: Install GL dependencies necessary to build enable + run: | + sudo apt-get update + sudo apt-get install libglu1-mesa-dev - name: Cache EDM packages uses: actions/cache@v2 with: diff --git a/chaco/plot_containers.py b/chaco/plot_containers.py index 95ea1e7db..6dcbe6d4c 100644 --- a/chaco/plot_containers.py +++ b/chaco/plot_containers.py @@ -40,7 +40,7 @@ Int, ) from enable.api import OverlayContainer -from enable.stacked_layout import stack_layout, stacked_preferred_size +from enable.stacked_container import HStackedContainer, VStackedContainer try: from enable.api import ConstraintsContainer @@ -108,35 +108,23 @@ class OverlayPlotContainer(OverlayContainer): draw_layer = Str("plot") -class StackedPlotContainer(BasePlotContainer): +class HPlotContainer(HStackedContainer): """ - Base class for 1-D stacked plot containers, both horizontal and vertical. + A plot container that stacks all of its components horizontally. Resizable + components share the free space evenly. All components are stacked from + according to **stack_order* in the same order that they appear in the + **components** list. """ - draw_order = Instance(list, args=(DEFAULT_DRAWING_ORDER,)) - - # The dimension along which to stack components that are added to - # this container. - stack_dimension = Enum("h", "v", transient=True) - - # The "other" dimension, i.e., the dual of the stack dimension. - other_dimension = Enum("v", "h", transient=True) - - # The index into obj.position and obj.bounds that corresponds to - # **stack_dimension**. This is a class-level and not an instance-level - # attribute. It must be 0 or 1. - stack_index = 0 + #: Redefine the container layers to name the main layer as "plot" instead + #: of the Enable default of "mainlayer" + container_under_layers = Tuple("background", "image", "underlay", "plot") - def get_preferred_size(self, components=None): - """Returns the size (width,height) that is preferred for this component. + draw_layer = Str("plot") - Overrides PlotComponent. - """ - return stacked_preferred_size(container=self, components=components) + draw_order = Instance(list, args=(DEFAULT_DRAWING_ORDER,)) - def _do_stack_layout(self, components, align): - """Helper method that does the actual work of layout.""" - stack_layout(container=self, components=components, align=align) + _cached_preferred_size = Tuple(transient=True) ### Persistence ########################################################### @@ -148,83 +136,29 @@ def __getstate__(self): return state -class HPlotContainer(StackedPlotContainer): - """ - A plot container that stacks all of its components horizontally. Resizable - components share the free space evenly. All components are stacked from - according to **stack_order* in the same order that they appear in the - **components** list. - """ - - draw_order = Instance(list, args=(DEFAULT_DRAWING_ORDER,)) - - #: The order in which components in the plot container are laid out. - stack_order = Enum("left_to_right", "right_to_left") - - #: The amount of space to put between components. - spacing = Float(0.0) - - #: The vertical alignment of objects that don't span the full height. - valign = Enum("bottom", "top", "center") - - _cached_preferred_size = Tuple(transient=True) - - def _do_layout(self): - """Actually performs a layout (called by do_layout()).""" - if self.stack_order == "left_to_right": - components = self.components - else: - components = self.components[::-1] - - if self.valign == "bottom": - align = "min" - elif self.valign == "center": - align = "center" - else: - align = "max" - - return self._do_stack_layout(components, align) - - -class VPlotContainer(StackedPlotContainer): +class VPlotContainer(VStackedContainer): """ A plot container that stacks plot components vertically. """ - draw_order = Instance(list, args=(DEFAULT_DRAWING_ORDER,)) - - #: Overrides StackedPlotContainer. - stack_dimension = "v" - #: Overrides StackedPlotContainer. - other_dimension = "h" - #: Overrides StackedPlotContainer. - stack_index = 1 - - # VPlotContainer attributes + #: Redefine the container layers to name the main layer as "plot" instead + #: of the Enable default of "mainlayer" + container_under_layers = Tuple("background", "image", "underlay", "plot") - #: The horizontal alignment of objects that don't span the full width. - halign = Enum("left", "right", "center") + draw_layer = Str("plot") - #: The order in which components in the plot container are laid out. - stack_order = Enum("bottom_to_top", "top_to_bottom") + draw_order = Instance(list, args=(DEFAULT_DRAWING_ORDER,)) - #: The amount of space to put between components. - spacing = Float(0.0) + _cached_preferred_size = Tuple(transient=True) - def _do_layout(self): - """Actually performs a layout (called by do_layout()).""" - if self.stack_order == "bottom_to_top": - components = self.components - else: - components = self.components[::-1] - if self.halign == "left": - align = "min" - elif self.halign == "center": - align = "center" - else: - align = "max" + ### Persistence ########################################################### - return self._do_stack_layout(components, align) + # PICKLE FIXME: blocked with _pickles, but not sure that was correct. + def __getstate__(self): + state = super().__getstate__() + if "stack_index" in state: + del state["stack_index"] + return state class GridPlotContainer(BasePlotContainer): diff --git a/ci/edmtool.py b/ci/edmtool.py index f8504f341..40163bc01 100644 --- a/ci/edmtool.py +++ b/ci/edmtool.py @@ -218,6 +218,25 @@ def install(runtime, toolkit, environment, editable, source): click.echo("Creating environment '{environment}'".format(**parameters)) execute(commands, parameters) + # NOTE : temporary code to install enable from source instead of relying on + # enable 5.1.1. This should be removed immediately after enable 5.2.0 is + # released. + command = "edm plumbing remove-package --environment {environment} --force enable" # noqa + execute([command], parameters) + source_pkgs = [ + "git+http://github.com/enthought/enable.git@maint/5.2#egg=enable" + ] + # Without the --no-dependencies flag such that new dependencies on + # master are brought in. + commands = [ + "python -m pip install --force-reinstall {pkg} ".format(pkg=pkg) + for pkg in source_pkgs + ] + commands = [ + "edm run -e {environment} -- " + command for command in commands + ] + execute(commands, parameters) + if source: # Remove EDM ETS packages and install them from source cmd_fmt = (