From 520167e24d6374916f49ee815fb03660add0e226 Mon Sep 17 00:00:00 2001 From: John Wiggins Date: Fri, 15 Feb 2013 14:11:18 -0600 Subject: [PATCH] Add a constraint list with selection to the constraints demo. This should help with the layout helper debugging... --- enable/constraints_container.py | 2 -- enable/layout/debug_constraints.py | 4 ++- examples/enable/constraints_demo.py | 51 +++++++++++++++++++++++++---- 3 files changed, 47 insertions(+), 10 deletions(-) diff --git a/enable/constraints_container.py b/enable/constraints_container.py index 51e4d7476..32cd5ff5c 100644 --- a/enable/constraints_container.py +++ b/enable/constraints_container.py @@ -124,8 +124,6 @@ def __layout_constraints_changed(self, name, old, new): """ Invalidate the layout when the private constraints list changes. """ self._layout_manager.replace_constraints(old, new) - if self.debug: - self._debug_overlay.selected_constraints = new self.relayout() def __components_items_changed(self, event): diff --git a/enable/layout/debug_constraints.py b/enable/layout/debug_constraints.py index 152e68955..54b99356c 100644 --- a/enable/layout/debug_constraints.py +++ b/enable/layout/debug_constraints.py @@ -49,7 +49,7 @@ class DebugConstraintsOverlay(AbstractOverlay): boxes = Any() # Style options for the lines. - term_color = ColorTrait('lightblue') + term_color = ColorTrait('orange') term_line_style = LineStyle('solid') def update_from_constraints(self, layout_mgr): @@ -76,7 +76,9 @@ def overlay(self, other_component, gc, view_bounds=None, mode="normal"): """ if len(self.selected_constraints) == 0: return + origin = other_component.position with gc: + gc.translate_ctm(*origin) gc.set_stroke_color(self.term_color_) gc.set_line_dash(self.term_line_style_) gc.set_line_width(3) diff --git a/examples/enable/constraints_demo.py b/examples/enable/constraints_demo.py index 753f963f2..7d0c9797c 100644 --- a/examples/enable/constraints_demo.py +++ b/examples/enable/constraints_demo.py @@ -1,26 +1,51 @@ from enable.api import Component, ComponentEditor, ConstraintsContainer from enable.layout.layout_helpers import hbox, align, grid -from traits.api import HasTraits, Instance -from traitsui.api import Item, View +from traits.api import HasTraits, Any, Instance, List, Property +from traitsui.api import Item, View, HGroup, TabularEditor +from traitsui.tabular_adapter import TabularAdapter + + +class ConstraintAdapter(TabularAdapter): + """ Display Constraints in a TabularEditor. + """ + columns = [('Constraint', 'id')] + id_text = Property + def _get_id_text(self): + return self.item.__repr__() class Demo(HasTraits): canvas = Instance(Component) + constraints = Property(List) + + selected_constraints = Any + traits_view = View( - Item('canvas', - editor=ComponentEditor(), - show_label=False, + HGroup( + Item('constraints', + editor=TabularEditor( + adapter=ConstraintAdapter(), + editable=False, + multi_select=True, + selected='selected_constraints', + ), + show_label=False, + ), + Item('canvas', + editor=ComponentEditor(), + show_label=False, + ), ), resizable=True, title="Constraints Demo", - width=500, + width=1000, height=500, ) def _canvas_default(self): - parent = ConstraintsContainer(bounds=(500,500), debug=True) + parent = ConstraintsContainer(bounds=(500,500), padding=20, debug=True) hugs = {'hug_width':'weak', 'hug_height':'weak'} one = Component(id="one", bgcolor=0xFF0000, **hugs) @@ -39,6 +64,18 @@ def _canvas_default(self): return parent + def _get_constraints(self): + return list(self.canvas._layout_manager._constraints) + + def _selected_constraints_changed(self, new): + if new is None or new == []: + return + + if self.canvas.debug: + canvas = self.canvas + canvas._debug_overlay.selected_constraints = new + canvas.request_redraw() + if __name__ == "__main__": Demo().configure_traits()