From 4e3c39df4378268b3fe813bd7a04005ab24f3608 Mon Sep 17 00:00:00 2001 From: Poruri Sai Rahul Date: Mon, 7 Jun 2021 20:45:02 +0530 Subject: [PATCH 01/12] 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 --- chaco/plot_containers.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/chaco/plot_containers.py b/chaco/plot_containers.py index 95ea1e7db..732cd3f12 100644 --- a/chaco/plot_containers.py +++ b/chaco/plot_containers.py @@ -156,6 +156,11 @@ class HPlotContainer(StackedPlotContainer): **components** list. """ + # The index into obj.position and obj.bounds that corresponds to + # **stack_dimension**. This is a class-level and not an instance-level + # attribute. + stack_index = 0 + draw_order = Instance(list, args=(DEFAULT_DRAWING_ORDER,)) #: The order in which components in the plot container are laid out. @@ -185,6 +190,15 @@ def _do_layout(self): return self._do_stack_layout(components, align) + ### Persistence ########################################################### + + # 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 VPlotContainer(StackedPlotContainer): """ @@ -197,7 +211,10 @@ class VPlotContainer(StackedPlotContainer): stack_dimension = "v" #: Overrides StackedPlotContainer. other_dimension = "h" - #: Overrides StackedPlotContainer. + + # The index into obj.position and obj.bounds that corresponds to + # **stack_dimension**. This is a class-level and not an instance-level + # attribute. stack_index = 1 # VPlotContainer attributes @@ -226,6 +243,15 @@ def _do_layout(self): return self._do_stack_layout(components, align) + ### Persistence ########################################################### + + # 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): """A GridPlotContainer consists of rows and columns in a tabular format. From 2f1c4526079fffcc39d8cba7c0c086df8e1d0c1c Mon Sep 17 00:00:00 2001 From: Poruri Sai Rahul Date: Mon, 7 Jun 2021 20:48:57 +0530 Subject: [PATCH 02/12] 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 --- chaco/plot_containers.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/chaco/plot_containers.py b/chaco/plot_containers.py index 732cd3f12..453f3f5e6 100644 --- a/chaco/plot_containers.py +++ b/chaco/plot_containers.py @@ -174,6 +174,17 @@ class HPlotContainer(StackedPlotContainer): _cached_preferred_size = Tuple(transient=True) + def get_preferred_size(self, components=None): + """Returns the size (width,height) that is preferred for this component. + + Overrides PlotComponent. + """ + return stacked_preferred_size(container=self, components=components) + + def _do_stack_layout(self, components, align): + """Helper method that does the actual work of layout.""" + stack_layout(container=self, components=components, align=align) + def _do_layout(self): """Actually performs a layout (called by do_layout()).""" if self.stack_order == "left_to_right": @@ -228,6 +239,17 @@ class VPlotContainer(StackedPlotContainer): #: The amount of space to put between components. spacing = Float(0.0) + def get_preferred_size(self, components=None): + """Returns the size (width,height) that is preferred for this component. + + Overrides PlotComponent. + """ + return stacked_preferred_size(container=self, components=components) + + def _do_stack_layout(self, components, align): + """Helper method that does the actual work of layout.""" + stack_layout(container=self, components=components, align=align) + def _do_layout(self): """Actually performs a layout (called by do_layout()).""" if self.stack_order == "bottom_to_top": From d69479175d1c28dc4550ff876f7f19abe88c4f7b Mon Sep 17 00:00:00 2001 From: Poruri Sai Rahul Date: Mon, 7 Jun 2021 20:53:43 +0530 Subject: [PATCH 03/12] 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 --- chaco/plot_containers.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/chaco/plot_containers.py b/chaco/plot_containers.py index 453f3f5e6..0ba31129f 100644 --- a/chaco/plot_containers.py +++ b/chaco/plot_containers.py @@ -163,6 +163,13 @@ class HPlotContainer(StackedPlotContainer): draw_order = Instance(list, args=(DEFAULT_DRAWING_ORDER,)) + # The dimension along which to stack components that are added to + # this container. + stack_dimension = Str("h", transient=True) + + # The "other" dimension, i.e., the dual of the stack dimension. + other_dimension = Str("v", transient=True) + #: The order in which components in the plot container are laid out. stack_order = Enum("left_to_right", "right_to_left") @@ -218,10 +225,12 @@ class VPlotContainer(StackedPlotContainer): draw_order = Instance(list, args=(DEFAULT_DRAWING_ORDER,)) - #: Overrides StackedPlotContainer. - stack_dimension = "v" - #: Overrides StackedPlotContainer. - other_dimension = "h" + # The dimension along which to stack components that are added to + # this container. + stack_dimension = Str("v", transient=True) + + # The "other" dimension, i.e., the dual of the stack dimension. + other_dimension = Str("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 From 79163bec5ec26300eac7e4c0021c7dde92395990 Mon Sep 17 00:00:00 2001 From: Poruri Sai Rahul Date: Mon, 7 Jun 2021 20:55:47 +0530 Subject: [PATCH 04/12] 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 --- chaco/plot_containers.py | 44 ++-------------------------------------- 1 file changed, 2 insertions(+), 42 deletions(-) diff --git a/chaco/plot_containers.py b/chaco/plot_containers.py index 0ba31129f..8c96cb1e9 100644 --- a/chaco/plot_containers.py +++ b/chaco/plot_containers.py @@ -108,47 +108,7 @@ class OverlayPlotContainer(OverlayContainer): draw_layer = Str("plot") -class StackedPlotContainer(BasePlotContainer): - """ - Base class for 1-D stacked plot containers, both horizontal and vertical. - """ - - 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 - - def get_preferred_size(self, components=None): - """Returns the size (width,height) that is preferred for this component. - - Overrides PlotComponent. - """ - return stacked_preferred_size(container=self, components=components) - - def _do_stack_layout(self, components, align): - """Helper method that does the actual work of layout.""" - stack_layout(container=self, components=components, align=align) - - ### Persistence ########################################################### - - # 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 HPlotContainer(StackedPlotContainer): +class HPlotContainer(BasePlotContainer): """ A plot container that stacks all of its components horizontally. Resizable components share the free space evenly. All components are stacked from @@ -218,7 +178,7 @@ def __getstate__(self): return state -class VPlotContainer(StackedPlotContainer): +class VPlotContainer(BasePlotContainer): """ A plot container that stacks plot components vertically. """ From f6aae86ac2eb52dc66859f1612ac7b4999b5abd8 Mon Sep 17 00:00:00 2001 From: Poruri Sai Rahul Date: Mon, 7 Jun 2021 20:58:07 +0530 Subject: [PATCH 05/12] REF : Redefine BasePlotContainer traits on subclasses and with this, we can remove their dependence on BasePlotContainer as well modified: chaco/plot_containers.py --- chaco/plot_containers.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/chaco/plot_containers.py b/chaco/plot_containers.py index 8c96cb1e9..5f28c7e39 100644 --- a/chaco/plot_containers.py +++ b/chaco/plot_containers.py @@ -121,6 +121,12 @@ class HPlotContainer(BasePlotContainer): # attribute. 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") + + draw_layer = Str("plot") + draw_order = Instance(list, args=(DEFAULT_DRAWING_ORDER,)) # The dimension along which to stack components that are added to @@ -183,6 +189,12 @@ class VPlotContainer(BasePlotContainer): A plot container that stacks plot components vertically. """ + #: 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") + + draw_layer = Str("plot") + draw_order = Instance(list, args=(DEFAULT_DRAWING_ORDER,)) # The dimension along which to stack components that are added to From 82a68051a4d1d4f6b1b3410010019b566bbab7d0 Mon Sep 17 00:00:00 2001 From: Poruri Sai Rahul Date: Mon, 7 Jun 2021 20:59:41 +0530 Subject: [PATCH 06/12] 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 --- chaco/plot_containers.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/chaco/plot_containers.py b/chaco/plot_containers.py index 5f28c7e39..b758714ff 100644 --- a/chaco/plot_containers.py +++ b/chaco/plot_containers.py @@ -39,7 +39,7 @@ Tuple, Int, ) -from enable.api import OverlayContainer +from enable.api import Container, OverlayContainer from enable.stacked_layout import stack_layout, stacked_preferred_size try: @@ -108,7 +108,7 @@ class OverlayPlotContainer(OverlayContainer): draw_layer = Str("plot") -class HPlotContainer(BasePlotContainer): +class HPlotContainer(Container): """ A plot container that stacks all of its components horizontally. Resizable components share the free space evenly. All components are stacked from @@ -184,7 +184,7 @@ def __getstate__(self): return state -class VPlotContainer(BasePlotContainer): +class VPlotContainer(Container): """ A plot container that stacks plot components vertically. """ From 9c1b41f20f29f9c7243c2c76dceb2b643ee6a5fc Mon Sep 17 00:00:00 2001 From: Poruri Sai Rahul Date: Mon, 7 Jun 2021 21:05:32 +0530 Subject: [PATCH 07/12] CLN : Make HPlotContainer inherit from enable HStackedContainer and remove a number of now redundant trait definitions and methods modified: chaco/plot_containers.py --- chaco/plot_containers.py | 52 ++-------------------------------------- 1 file changed, 2 insertions(+), 50 deletions(-) diff --git a/chaco/plot_containers.py b/chaco/plot_containers.py index b758714ff..f48e60642 100644 --- a/chaco/plot_containers.py +++ b/chaco/plot_containers.py @@ -39,7 +39,7 @@ Tuple, Int, ) -from enable.api import Container, OverlayContainer +from enable.api import Container, HStackedContainer, OverlayContainer from enable.stacked_layout import stack_layout, stacked_preferred_size try: @@ -108,7 +108,7 @@ class OverlayPlotContainer(OverlayContainer): draw_layer = Str("plot") -class HPlotContainer(Container): +class HPlotContainer(HStackedContainer): """ A plot container that stacks all of its components horizontally. Resizable components share the free space evenly. All components are stacked from @@ -116,11 +116,6 @@ class HPlotContainer(Container): **components** list. """ - # The index into obj.position and obj.bounds that corresponds to - # **stack_dimension**. This is a class-level and not an instance-level - # attribute. - 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") @@ -129,51 +124,8 @@ class HPlotContainer(Container): draw_order = Instance(list, args=(DEFAULT_DRAWING_ORDER,)) - # The dimension along which to stack components that are added to - # this container. - stack_dimension = Str("h", transient=True) - - # The "other" dimension, i.e., the dual of the stack dimension. - other_dimension = Str("v", transient=True) - - #: 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 get_preferred_size(self, components=None): - """Returns the size (width,height) that is preferred for this component. - - Overrides PlotComponent. - """ - return stacked_preferred_size(container=self, components=components) - - def _do_stack_layout(self, components, align): - """Helper method that does the actual work of layout.""" - stack_layout(container=self, components=components, align=align) - - 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) - ### Persistence ########################################################### # PICKLE FIXME: blocked with _pickles, but not sure that was correct. From e5cd0ee96159dd0b72df72cef6a9f01767d15222 Mon Sep 17 00:00:00 2001 From: Poruri Sai Rahul Date: Mon, 7 Jun 2021 21:09:40 +0530 Subject: [PATCH 08/12] 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 --- chaco/plot_containers.py | 54 ++-------------------------------------- 1 file changed, 2 insertions(+), 52 deletions(-) diff --git a/chaco/plot_containers.py b/chaco/plot_containers.py index f48e60642..72a54488b 100644 --- a/chaco/plot_containers.py +++ b/chaco/plot_containers.py @@ -39,8 +39,7 @@ Tuple, Int, ) -from enable.api import Container, HStackedContainer, OverlayContainer -from enable.stacked_layout import stack_layout, stacked_preferred_size +from enable.api import HStackedContainer, OverlayContainer, VStackedContainer try: from enable.api import ConstraintsContainer @@ -136,7 +135,7 @@ def __getstate__(self): return state -class VPlotContainer(Container): +class VPlotContainer(VStackedContainer): """ A plot container that stacks plot components vertically. """ @@ -149,55 +148,6 @@ class VPlotContainer(Container): draw_order = Instance(list, args=(DEFAULT_DRAWING_ORDER,)) - # The dimension along which to stack components that are added to - # this container. - stack_dimension = Str("v", transient=True) - - # The "other" dimension, i.e., the dual of the stack dimension. - other_dimension = Str("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. - stack_index = 1 - - # VPlotContainer attributes - - #: The horizontal alignment of objects that don't span the full width. - halign = Enum("left", "right", "center") - - #: The order in which components in the plot container are laid out. - stack_order = Enum("bottom_to_top", "top_to_bottom") - - #: The amount of space to put between components. - spacing = Float(0.0) - - def get_preferred_size(self, components=None): - """Returns the size (width,height) that is preferred for this component. - - Overrides PlotComponent. - """ - return stacked_preferred_size(container=self, components=components) - - def _do_stack_layout(self, components, align): - """Helper method that does the actual work of layout.""" - stack_layout(container=self, components=components, align=align) - - 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" - - return self._do_stack_layout(components, align) - ### Persistence ########################################################### # PICKLE FIXME: blocked with _pickles, but not sure that was correct. From d85fdf20221040dd27591d92fb9b81f7bc21b026 Mon Sep 17 00:00:00 2001 From: Poruri Sai Rahul Date: Mon, 7 Jun 2021 21:10:26 +0530 Subject: [PATCH 09/12] 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 --- chaco/plot_containers.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/chaco/plot_containers.py b/chaco/plot_containers.py index 72a54488b..a972ea6f8 100644 --- a/chaco/plot_containers.py +++ b/chaco/plot_containers.py @@ -148,6 +148,8 @@ class VPlotContainer(VStackedContainer): draw_order = Instance(list, args=(DEFAULT_DRAWING_ORDER,)) + _cached_preferred_size = Tuple(transient=True) + ### Persistence ########################################################### # PICKLE FIXME: blocked with _pickles, but not sure that was correct. From 4f524dda89d980dd598eeb9ffce169d1327f5ee2 Mon Sep 17 00:00:00 2001 From: Poruri Sai Rahul Date: Mon, 7 Jun 2021 21:29:26 +0530 Subject: [PATCH 10/12] 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 --- chaco/plot_containers.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/chaco/plot_containers.py b/chaco/plot_containers.py index a972ea6f8..6dcbe6d4c 100644 --- a/chaco/plot_containers.py +++ b/chaco/plot_containers.py @@ -39,7 +39,8 @@ Tuple, Int, ) -from enable.api import HStackedContainer, OverlayContainer, VStackedContainer +from enable.api import OverlayContainer +from enable.stacked_container import HStackedContainer, VStackedContainer try: from enable.api import ConstraintsContainer From b74c8c77b2af48bc91271b86dd0543bb31da1454 Mon Sep 17 00:00:00 2001 From: Poruri Sai Rahul Date: Mon, 7 Jun 2021 22:07:38 +0530 Subject: [PATCH 11/12] 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 --- ci/edmtool.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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 = ( From 68ce2f87de28831d22c41c1e42be0e0cb48461fc Mon Sep 17 00:00:00 2001 From: Poruri Sai Rahul Date: Mon, 7 Jun 2021 22:20:37 +0530 Subject: [PATCH 12/12] 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 ++++++ 1 file changed, 6 insertions(+) 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: