def _get_layout(self, container): """ Returns a list of constraits that is meant to be passed to a ConstraintsContainer. """ constraints = [] # NOTE: inequality expressions seem a lil shaky in that it requires # some tweaking to finding a set of constraints that works well ! # But this is much better than manually tweaking padding etc. # Another option is to simply calculate the values of the height etc # and set it as simple inequalities (as opposed to using height as # another variable in the expressions) # FIXME: also, the layouts can prob. be specified as input similar to # the other plot properties. uv_comp = self.plot_contexts.get(LOG_FAMILY_UV) if uv_comp is not None: # uv_comp should exist in container.components assert(uv_comp in container.components) # NOTE: # 1. `>` doesent work but `>=` works ! # 2. adding both >= and <= breaks if `contents_height` is specified # but works if integer values are specified constraints.append( uv_comp.layout_height >= 0.4 * container.contents_height ) # split components into groups. For now, just UV and others other_components = [_comp for _comp in container.components if _comp is not uv_comp] for plot in other_components: # FIXME: just setting `<=` constraint results in plot not showing # up *if* its the only plot in the container # need to figure out the appropriate layout helper function here # constraints.append( # plot.layout_height <= 0.2 * container.contents_height # ) # constraints.append( # plot.layout_height >= 10 # ) pass # NOTE: looks like every comp in the container needs a constraint, # else they get messed up or ignored. # create an ordered (top to bottom) list of components sorted_components = [uv_comp] + other_components constraints.extend([ # all components are in a vertical box vbox(*sorted_components, spacing=50, margins=50), # align widths of all components to be the same align('layout_width', *sorted_components), # align heights of *other* components to be the same align('layout_height', *other_components), ]) return constraints
def test_vbox_order(self): """ Test the order of components in a vbox. """ self.container.layout_constraints = [ vbox(self.c1, self.c2) ] dy = self.c2.position[1] - self.c1.position[1] self.assert_(dy < 0)
def test_vbox_order(self): """ Test the order of components in a vbox. """ from enable.layout.api import vbox self.container.layout_constraints = [vbox(self.c1, self.c2)] dy = self.c2.position[1] - self.c1.position[1] self.assertTrue(dy < 0)
def test_vbox_order(self): """ Test the order of components in a vbox. """ from enable.layout.api import vbox self.container.layout_constraints = [ vbox(self.c1, self.c2) ] dy = self.c2.position[1] - self.c1.position[1] self.assertTrue(dy < 0)
def test_layout_manager_replace_constraints(self): """ Test replacing constraints in the layout manager. """ manager = LayoutManager() cns = hbox(self.c1, self.c2).get_constraints(self.container) new_cns = vbox(self.c1, self.c2).get_constraints(self.container) self.assertRaises(RuntimeError, manager.replace_constraints, cns[0], new_cns[0]) manager.initialize(cns) manager.replace_constraints(cns, new_cns) self.assert_(not manager._solver.hasConstraint(cns[0])) self.assert_(manager._solver.hasConstraint(new_cns[0]))
def test_layout_manager_replace_constraints(self): """ Test replacing constraints in the layout manager. """ from enable.layout.api import hbox, vbox from enable.layout.layout_manager import LayoutManager manager = LayoutManager() cns = hbox(self.c1, self.c2).get_constraints(self.container) new_cns = vbox(self.c1, self.c2).get_constraints(self.container) self.assertRaises(RuntimeError, manager.replace_constraints, cns[0], new_cns[0]) manager.initialize(cns) manager.replace_constraints(cns, new_cns) self.assertTrue(not manager._solver.hasConstraint(cns[0])) self.assertTrue(manager._solver.hasConstraint(new_cns[0]))