Exemplo n.º 1
0
    def test_non_resizable(self):
        cont = GridContainer(shape=(2,2), spacing=(10,10),
                             halign="center", valign="center")
        ul = StaticPlotComponent([100,100], resizable="")
        ur = StaticPlotComponent([100,100], resizable="")
        ll = StaticPlotComponent([100,100], resizable="")
        lr = StaticPlotComponent([100,100], resizable="")
        cont.component_grid = [[ul, ur], [ll, lr]]

        cont.bounds = [240, 240]
        cont.do_layout()
        self.assert_tuple(ul.position, (10,130))
        self.assert_tuple(ul.bounds, (100,100))
        self.assert_tuple(ur.position, (130,130))
        self.assert_tuple(ur.bounds, (100, 100))
        self.assert_tuple(ll.position, (10,10))
        self.assert_tuple(ll.bounds, (100,100))
        self.assert_tuple(lr.position, (130,10))
        self.assert_tuple(lr.bounds, (100,100))

        cont.bounds = [280, 280]
        cont.do_layout()
        self.assert_tuple(ul.position, (20,160))
        self.assert_tuple(ul.bounds, (100,100))
        self.assert_tuple(ur.position, (160,160))
        self.assert_tuple(ur.bounds, (100, 100))
        self.assert_tuple(ll.position, (20,20))
        self.assert_tuple(ll.bounds, (100,100))
        self.assert_tuple(lr.position, (160,20))
        self.assert_tuple(lr.bounds, (100,100))
Exemplo n.º 2
0
 def test_nonresizable_container(self):
     cont = GridContainer(shape=(1,1), resizable="")
     comp1 = StaticPlotComponent([200,300])
     cont.add(comp1)
     cont.do_layout()
     self.assert_tuple(comp1.position, (0,0))
     self.assert_tuple(comp1.bounds, (200,300))
     return
Exemplo n.º 3
0
 def test_all_empty_cells(self):
     cont = GridContainer(shape=(2,2), spacing=(0,0))
     cont.component_grid = [[None, None], [None, None]]
     size = cont.get_preferred_size()
     self.assert_tuple(size, (0,0))
     cont.bounds = (100,100)
     cont.do_layout()
     return
Exemplo n.º 4
0
 def test_single_cell(self):
     cont = GridContainer(shape=(1,1))
     comp1 = StaticPlotComponent([200,300])
     cont.add(comp1)
     cont.do_layout()
     # it would be nice to make all boolean tests here trigger
     # assert failures, maybe using Pypy?
     self.assert_tuple(comp1.position, (0,0))
     self.assert_tuple(comp1.bounds, (200,300))
     return
Exemplo n.º 5
0
 def test_some_empty_cells(self):
     cont = GridContainer(shape=(2,2), spacing=(0,0))
     a = StaticPlotComponent([100,30])
     b = StaticPlotComponent([50,40])
     cont.component_grid = [[a, None], [None, b]]
     size = cont.get_preferred_size()
     self.assert_tuple(size, (150, 70))
     cont.bounds = size
     cont.do_layout()
     self.assert_tuple(a.outer_position, (0, 40))
     self.assert_tuple(a.outer_bounds, (100, 30))
     self.assert_tuple(b.outer_position, (100,0))
     self.assert_tuple(b.outer_bounds, (50, 40))
Exemplo n.º 6
0
    def test_empty_container(self):
        # FIXME:
        #   This test is failing when run with nosetests and coverage.
        #   Therefore, it is skipped when coverage is imported.
        #   If you want to fix this, please look at:
        #     https://svn.enthought.com/enthought/ticket/1618
        #   where I posted more details about this problem.
        if 'coverage' in sys.modules:
            raise nose.SkipTest

        cont = GridContainer(shape=(1,1))
        cont.bounds = [100,100]
        cont.do_layout()
        return
Exemplo n.º 7
0
    def test_resizable_mixed_h(self):
        # Tests the layout of a non-resizable component, a resizable with a
        # preferred size, and a fully resizable component in a horizontal
        # GridContainer
        cont = GridContainer(shape=(3,1), spacing=(0,0),
                             halign="center", valign="center")
        left = StaticPlotComponent([50,10], resizable="")
        middle = ResizablePlotComponent([100,10])
        right = StaticPlotComponent([0,0], resizable="hv")

        cont.component_grid = [[left, middle, right]]
        cont.bounds = [200, 10]
        cont.do_layout()
        self.assert_tuple(left.position, (0,0))
        self.assert_tuple(left.bounds, (50,10))
        self.assert_tuple(middle.position, (50,0))
        self.assert_tuple(middle.bounds, (100,10))
        self.assert_tuple(right.position, (150,0))
        self.assert_tuple(right.bounds, (50,10))
Exemplo n.º 8
0
 def test_resizable2(self):
     # Tests a resizable component that also has a preferred size
     cont = GridContainer(shape=(2,2), spacing=(0,0),
                          halign="center", valign="center")
     ul = StaticPlotComponent([150,150], resizable="hv")
     lr = StaticPlotComponent([0,0], resizable="hv")
     top = StaticPlotComponent([0,0], resizable="hv")
     left = StaticPlotComponent([0,0], resizable="hv")
     cont.component_grid = [[ul, top], [left, lr]]
     cont.bounds = [200, 200]
     cont.do_layout()
     self.assert_tuple(ul.position, (0,100))
     self.assert_tuple(ul.bounds, (100,100))
     self.assert_tuple(top.position, (100,100))
     self.assert_tuple(top.bounds, (100,100))
     self.assert_tuple(left.position, (0,0))
     self.assert_tuple(left.bounds, (100,100))
     self.assert_tuple(lr.position, (100,0))
     self.assert_tuple(lr.bounds, (100,100))
Exemplo n.º 9
0
 def test_spacing(self):
     cont = GridContainer(shape=(2,2), spacing=(10,10),
                          halign="center", valign="center")
     ul = StaticPlotComponent([50,50])     # upper-left component
     lr = StaticPlotComponent([100,100])   # lower-right component
     top = StaticPlotComponent([0,0], resizable="hv")
     left = StaticPlotComponent([0,0], resizable="hv")
     cont.component_grid = [[ul, top], [left, lr]]
     cont.bounds = [190, 190]
     cont.do_layout()
     self.assert_tuple(ul.position, (10,130))
     self.assert_tuple(ul.bounds, (50,50))
     self.assert_tuple(top.position, (80,130))
     self.assert_tuple(top.bounds, (100, 50))
     self.assert_tuple(left.position, (10,10))
     self.assert_tuple(left.bounds, (50,100))
     self.assert_tuple(lr.position, (80,10))
     self.assert_tuple(lr.bounds, (100,100))
     return
Exemplo n.º 10
0
 def test_two_by_two(self):
     """ Tests a 2x2 grid of components """
     cont = GridContainer(shape=(2,2), halign="center", valign="center")
     ul = StaticPlotComponent([50,50])     # upper-left component
     lr = StaticPlotComponent([100,100])   # lower-right component
     top = StaticPlotComponent([0,0], resizable="hv")
     left = StaticPlotComponent([0,0], resizable="hv")
     cont.component_grid = [[ul, top], [left, lr]]
     cont.bounds = [150, 150]
     cont.do_layout()
     self.assert_tuple(ul.position, (0,100))
     self.assert_tuple(ul.bounds, (50,50))
     self.assert_tuple(top.position, (50,100))
     self.assert_tuple(top.bounds, (100, 50))
     self.assert_tuple(left.position, (0,0))
     self.assert_tuple(left.bounds, (50,100))
     self.assert_tuple(lr.position, (50,0))
     self.assert_tuple(lr.bounds, (100,100))
     return
Exemplo n.º 11
0
 def test_resizable_mixed2(self):
     # Tests laying out resizable components with preferred
     # sized alongside non-resizable components.
     cont = GridContainer(shape=(2,2), spacing=(0,0),
                          halign="center", valign="center")
     ul = ResizablePlotComponent([150,150])
     lr = StaticPlotComponent([50,50], resizable="")
     top = StaticPlotComponent([0,0], resizable="hv")
     left = StaticPlotComponent([0,0], resizable="hv")
     cont.component_grid = [[ul, top], [left, lr]]
     cont.bounds = [200, 200]
     cont.do_layout()
     self.assert_tuple(ul.position, (0,50))
     self.assert_tuple(ul.bounds, (150,150))
     self.assert_tuple(top.position, (150,50))
     self.assert_tuple(top.bounds, (50,150))
     self.assert_tuple(left.position, (0,0))
     self.assert_tuple(left.bounds, (150,50))
     self.assert_tuple(lr.position, (150,0))
     self.assert_tuple(lr.bounds, (50,50))
Exemplo n.º 12
0
 def test_resizable_mixed(self):
     """ Tests mixing resizable and non-resizable components """
     cont = GridContainer(shape=(2,2), spacing=(10,10),
                          halign="center", valign="center")
     ul = StaticPlotComponent([0,0], resizable="hv")
     lr = StaticPlotComponent([0,0], resizable="hv")
     top = StaticPlotComponent([0,0], resizable="hv")
     left = StaticPlotComponent([100,100], resizable="")
     cont.component_grid = [[ul, top], [left, lr]]
     cont.bounds = [240, 240]
     cont.do_layout()
     self.assert_tuple(ul.position, (10,130))
     self.assert_tuple(ul.bounds, (100,100))
     self.assert_tuple(top.position, (130,130))
     self.assert_tuple(top.bounds, (100, 100))
     self.assert_tuple(left.position, (10,10))
     self.assert_tuple(left.bounds, (100,100))
     self.assert_tuple(lr.position, (130,10))
     self.assert_tuple(lr.bounds, (100,100))
     return
Exemplo n.º 13
0
    def test_row(self):
        cont = GridContainer(shape=(1,3), halign="center", valign="center")
        c1 = StaticPlotComponent([50,50])
        c2 = StaticPlotComponent([30,30])
        c3 = StaticPlotComponent([0,0], resizable="hv")
        cont.add(c1, c2, c3)
        cont.bounds = list(cont.get_preferred_size())
        cont.do_layout()
        self.assert_tuple(c1.position, (0,0))
        self.assert_tuple(c1.bounds, (50,50))
        self.assert_tuple(c2.position, (50,10))
        self.assert_tuple(c2.bounds, (30,30))
        self.assert_tuple(c3.position, (80,0))
        self.assert_tuple(c3.bounds, (0,50))

        cont.bounds = [100, 50]
        cont.do_layout()
        self.assert_tuple(c1.position, (0,0))
        self.assert_tuple(c1.bounds, (50,50))
        self.assert_tuple(c2.position, (50,10))
        self.assert_tuple(c2.bounds, (30,30))
        self.assert_tuple(c3.position, (80,0))
        self.assert_tuple(c3.bounds, (20,50))
        return