Skip to content

Commit

Permalink
Fix debug rendering for constraints and tweak the constraints demo
Browse files Browse the repository at this point in the history
  • Loading branch information
jwiggins authored and brett-patterson committed Jun 25, 2014
1 parent 6ae2e4a commit 6cbb9dc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
24 changes: 12 additions & 12 deletions enable/layout/debug_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ class Coords(HasTraits):
bottom = Float()
left = Float()
right = Float()
width = Float()
height = Float()
layout_width = Float()
layout_height = Float()

v_center = Property()
_v_center = Any()
def _get_v_center(self):
if self._v_center is None:
return self.bottom + 0.5 * self.height
return self.bottom + 0.5 * self.layout_height
else:
return self._v_center
def _set_v_center(self, value):
Expand All @@ -31,7 +31,7 @@ def _set_v_center(self, value):
_h_center = Any()
def _get_h_center(self):
if self._h_center is None:
return self.left + 0.5 * self.width
return self.left + 0.5 * self.layout_width
else:
return self._h_center
def _set_h_center(self, value):
Expand Down Expand Up @@ -90,17 +90,17 @@ def overlay(self, other_component, gc, view_bounds=None, mode="normal"):
for name, attr in sorted(term_attrs):
box = self.boxes[name]
if attr == 'top':
self.hline(gc, box.left, box.top, box.width)
self.hline(gc, box.left, box.top, box.layout_width)
elif attr == 'bottom':
self.hline(gc, box.left, box.bottom, box.width)
self.hline(gc, box.left, box.bottom, box.layout_width)
elif attr == 'left':
self.vline(gc, box.left, box.bottom, box.height)
self.vline(gc, box.left, box.bottom, box.layout_height)
elif attr == 'right':
self.vline(gc, box.right, box.bottom, box.height)
elif attr == 'width':
self.hline(gc, box.left, box.v_center, box.width)
elif attr == 'height':
self.vline(gc, box.h_center, box.bottom, box.height)
self.vline(gc, box.right, box.bottom, box.layout_height)
elif attr == 'layout_width':
self.hline(gc, box.left, box.v_center, box.layout_width)
elif attr == 'layout_height':
self.vline(gc, box.h_center, box.bottom, box.layout_height)
gc.stroke_path()

def vline(self, gc, x, y0, length):
Expand Down
14 changes: 8 additions & 6 deletions examples/enable/constraints_demo.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

from enable.api import Component, ComponentEditor, ConstraintsContainer
from enable.layout.layout_helpers import (expand_constraints, hbox, vbox,
align, grid, horizontal, vertical, spacer)
from traits.api import HasTraits, Any, Instance, List, Property, Str
from enable.layout.layout_helpers import (align, grid, horizontal, hbox, vbox,
spacer, vertical)
from traits.api import HasTraits, Any, Event, Instance, List, Property, Str
from traitsui.api import Item, View, HGroup, VGroup, TabularEditor, CodeEditor
from traitsui.tabular_adapter import TabularAdapter

Expand All @@ -19,7 +19,8 @@ def _get_id_text(self):
class Demo(HasTraits):
canvas = Instance(Component)

constraints = Property(List)
constraints = Property(List, depends_on='constraints_changed')
constraints_changed = Event

constraints_def = Str

Expand Down Expand Up @@ -94,12 +95,13 @@ def _constraints_def_changed(self):
except Exception, ex:
return

self.selected_constraints = []
self.canvas.layout_constraints = new_cns
self.selected_constraints = []
self.constraints_changed = True
self.canvas.request_redraw()

def _selected_constraints_changed(self, new):
if new is None or new == []:
if new is None:
return

if self.canvas.debug:
Expand Down

0 comments on commit 6cbb9dc

Please sign in to comment.