Skip to content

Commit

Permalink
Make chaco v/h plot containers inherit from enable v/h stacked contai…
Browse files Browse the repository at this point in the history
…ners (#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
  • Loading branch information
Poruri Sai Rahul authored Jun 8, 2021
1 parent 01cb3f3 commit 5d692b3
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 92 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/test-with-edm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
118 changes: 26 additions & 92 deletions chaco/plot_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ###########################################################

Expand All @@ -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):
Expand Down
19 changes: 19 additions & 0 deletions ci/edmtool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down

0 comments on commit 5d692b3

Please sign in to comment.