예제 #1
0
    def test_auto_size(self):
        container = Container(bounds=[100.0, 100.0])
        self.assert_(container.auto_size == False)

        # Add some components
        c1 = Component(position=[10.0, 10.0], bounds=[50.0, 60.0])
        c2 = Component(position=[15.0, 15.0], bounds=[10.0, 10.0])
        container.add(c1)
        container.add(c2)
        self.assert_dims(container, x=0.0, y=0.0, width=100.0, height=100.0)

        # Turn on auto-sizing
        container.auto_size = True
        self.assert_dims(container, x=10.0, y=10.0, width=49.0, height=59.0)

        # Check that the components' positions changed appropriately
        self.assert_dims(c1, x=0.0, y=0.0)
        self.assert_dims(c2, x=5.0, y=5.0)

        # Move the second component
        c2.position = [100.0, 100.0]
        self.assert_dims(container, x=10.0, y=10.0, width=109.0, height=109.0)
        self.assert_dims(c2, x=100.0, y=100.0)

        # Delete the second component
        container.remove(c2)
        self.assert_dims(container, x=10.0, y=10.0, width=49.0, height=59.0)
        return
    def test_auto_size(self):
        container = Container(bounds=[100.0, 100.0])
        self.assertTrue(container.auto_size == False)

        # Add some components
        c1 = Component(position=[10.0, 10.0], bounds=[50.0, 60.0])
        c2 = Component(position=[15.0, 15.0], bounds=[10.0, 10.0])
        container.add(c1)
        container.add(c2)
        self.assert_dims(container, x=0.0, y=0.0, width=100.0, height=100.0)

        # Turn on auto-sizing
        container.auto_size = True
        self.assert_dims(container, x=10.0, y=10.0, width=49.0, height=59.0)

        # Check that the components' positions changed appropriately
        self.assert_dims(c1, x=0.0, y=0.0)
        self.assert_dims(c2, x=5.0, y=5.0)

        # Move the second component
        c2.position = [100.0, 100.0]
        self.assert_dims(container, x=10.0, y=10.0, width=109.0, height=109.0)
        self.assert_dims(c2, x=100.0, y=100.0)

        # Delete the second component
        container.remove(c2)
        self.assert_dims(container, x=10.0, y=10.0, width=49.0, height=59.0)
        return
예제 #3
0
    def _canvas_default(self):
        parent = ConstraintsContainer(bounds=(500, 500), padding=20)

        one = Component(id="r", bgcolor=0xFF0000)
        two = Component(id="g", bgcolor=0x00FF00)
        three = Component(id="b", bgcolor=0x0000FF)

        parent.add(one, two, three, self.child_canvas)
        return parent
예제 #4
0
    def _child_canvas_default(self):
        parent = ConstraintsContainer(id="child",
                                      share_layout=self.share_layout)

        one = Component(id="c", bgcolor=0x00FFFF)
        two = Component(id="m", bgcolor=0xFF00FF)
        three = Component(id="y", bgcolor=0xFFFF00)
        four = Component(id="k", bgcolor=0x000000)

        parent.add(one, two, three, four)
        return parent
예제 #5
0
 def create_simple_components(self):
     "Returns a container with 3 items in it; used by several tests."
     self.c1 = Component(bounds=[5.0, 10.0])
     self.c2 = Component(bounds=[6.0, 10.0])
     self.c3 = Component(bounds=[7.0, 10.0])
     container = Container(bounds=[100.0, 100.0])
     container.add(self.c1)
     self.c1.position = [20, 10]
     container.add(self.c2)
     self.c2.position = [40, 10]
     container.add(self.c3)
     self.c3.position = [60, 10]
     return container
    def test_adjust_bounds_hanchor_center_stay_inside(self):
        container = Container(bounds=[100.0, 100.0])
        component = Component(bounds=[50.0, 50.0], position=[5.0, 5.0])
        container.add(component)
        view = Viewport(component=container,
                        view_bounds=[50.0, 50.0],
                        view_position=[20, 20],
                        position=[0, 0],
                        bounds=[50, 50],
                        horizontal_anchor='center',
                        stay_inside=True)

        # simple resize
        view.bounds = [60, 60]
        self.assertEqual(view.view_position, [15.0, 20])

        # resize beyond left
        view.height = 95
        view.width = 95
        self.assertEqual(view.view_position, [0.0, 5])

        # resize bigger than view
        view.bounds[0] = 120
        view.bounds[1] = 120
        self.assertEqual(view.view_position, [-10.0, 0])
예제 #7
0
    def test_adjust_bounds_vanchor_center_stay_inside(self):
        container = Container(bounds=[100.0, 100.0])
        component = Component(bounds=[50.0, 50.0], position=[5.0, 5.0])
        container.add(component)
        view = Viewport(
            component=container,
            view_bounds=[50.0, 50.0],
            view_position=[20, 20],
            position=[0, 0],
            bounds=[50, 50],
            vertical_anchor="center",
            stay_inside=True,
        )

        # simple resize
        view.bounds = [60, 60]
        self.assertEqual(view.view_position, [20, 15.0])

        # resize beyond left
        view.bounds = [95, 95]
        self.assertEqual(view.view_position, [5, 0.0])

        # resize bigger than view
        view.bounds = [120, 120]
        self.assertEqual(view.view_position, [0, -10.0])
예제 #8
0
    def test_adjust_bounds_hanchor_top_stay_inside(self):
        container = Container(bounds=[100.0, 100.0])
        component = Component(bounds=[50.0, 50.0], position=[5.0, 5.0])
        container.add(component)
        view = Viewport(
            component=container,
            view_bounds=[50.0, 50.0],
            view_position=[20, 20],
            position=[0, 0],
            bounds=[50, 50],
            horizontal_anchor="right",
            stay_inside=True,
        )

        # simple resize
        view.bounds = [60, 60]
        self.assertEqual(view.view_position, [10, 20.0])

        # resize beyond left
        view.bounds = [80, 80]
        self.assertEqual(view.view_position, [0, 20.0])

        # resize bigger than view
        view.bounds = [120, 120]
        self.assertEqual(view.view_position, [-20.0, 0])
예제 #9
0
 def test_position(self):
     c = Component(bounds=[50.0, 50.0])
     self.assertTrue(c.position[0] == c.x)
     self.assertTrue(c.position[1] == c.y)
     self.assertTrue(c.x == 0.0)
     self.assertTrue(c.y == 0.0)
     return
    def test_adjust_container_bounds_hanchor_right_stay_inside(self):
        container = Container(bounds=[100.0, 100.0])
        component = Component(bounds=[50.0, 50.0], position=[5.0, 5.0])
        container.add(component)
        view = Viewport(component=container,
                        view_bounds=[50.0, 50.0],
                        view_position=[20, 20],
                        position=[0, 0],
                        bounds=[50, 50],
                        horizontal_anchor='right',
                        stay_inside=True)

        # simple resize bigger
        container.bounds = [120, 120]
        self.assertEqual(view.view_position, [40, 20])

        # simple resize smaller
        container.height = 90
        container.width = 90
        self.assertEqual(view.view_position, [10, 20])

        # simple resize much smaller
        container.bounds[0] = 40
        container.bounds[1] = 40
        self.assertEqual(view.view_position, [-10, 0])
예제 #11
0
    def test_adjust_container_bounds_vanchor_top(self):
        container = Container(bounds=[100.0, 100.0])
        component = Component(bounds=[50.0, 50.0], position=[5.0, 5.0])
        container.add(component)
        view = Viewport(
            component=container,
            view_bounds=[50.0, 50.0],
            view_position=[20, 20],
            position=[0, 0],
            bounds=[50, 50],
            vertical_anchor="top",
        )

        # simple resize bigger
        container.bounds = [120, 120]
        self.assertEqual(view.view_position, [20, 40.0])

        # simple resize smaller
        container.height = 90
        container.width = 90
        self.assertEqual(view.view_position, [20, 10.0])

        # simple resize much smaller
        container.bounds[0] = 40
        container.bounds[1] = 40
        self.assertEqual(view.view_position, [20, -40.0])
예제 #12
0
    def test_using_enable_canvas_widget(self):

        canvas = self.view.find('canvas')

        with self.assertAtomChanges(canvas, 'component'):
            self.model.component = Component()

        canvas = None
예제 #13
0
 def test_bounds(self):
     c = Component(bounds=[50.0, 60.0])
     self.assertTrue(c.width == c.bounds[0])
     self.assertTrue(c.height == c.bounds[1])
     self.assertTrue(c.bounds[0] == 50.0)
     self.assertTrue(c.bounds[1] == 60.0)
     self.assertTrue(c.x2 == c.x + 50.0 - 1)
     self.assertTrue(c.y2 == c.y + 60.0 - 1)
 def test_initial_position(self):
     container = Container(bounds=[100.0, 100.0])
     component = Component(bounds=[50.0, 50.0], position=[5.0, 5.0])
     container.add(component)
     view = Viewport(component=container,
                     view_bounds=[50.0, 50.0],
                     position=[0, 0],
                     bounds=[50, 50])
     self.assertEqual(view.view_position, [0, 0])
예제 #15
0
 def test_border(self):
     c = Component(bounds=[50.0, 60.0],
                   position=[20, 20],
                   padding=10, border_visible=True, border_width=1)
     self.assertTrue(c.outer_x == 10)
     self.assertTrue(c.outer_y == 10)
     self.assertTrue(c.outer_bounds[0] == 70)
     self.assertTrue(c.outer_bounds[1] == 80)
     return
 def test_initial_position_hanchor_center(self):
     container = Container(bounds=[100.0, 100.0])
     component = Component(bounds=[50.0, 50.0], position=[5.0, 5.0])
     container.add(component)
     view = Viewport(component=container,
                     horizontal_anchor='center',
                     view_bounds=[50.0, 50.0],
                     position=[0, 0],
                     bounds=[50, 50])
     self.assertEqual(view.view_position, [25, 0])
예제 #17
0
 def test_initial_position_vanchor_center(self):
     container = Container(bounds=[100.0, 100.0])
     component = Component(bounds=[50.0, 50.0], position=[5.0, 5.0])
     container.add(component)
     view = Viewport(
         component=container,
         vertical_anchor="center",
         view_bounds=[50.0, 50.0],
         position=[0, 0],
         bounds=[50, 50],
     )
     self.assertEqual(view.view_position, [0, 25])
예제 #18
0
 def test_get_outer_position(self):
     c = Component(bounds=[50.0, 60.0], padding=10, border_visible=False)
     self.assertTrue(c.outer_x == -10)
     self.assertTrue(c.outer_y == -10)
     self.assertTrue(c.outer_position[0] == -10)
     self.assertTrue(c.outer_position[1] == -10)
     self.assertTrue(c.outer_x2 == 59)
     self.assertTrue(c.outer_y2 == 69)
     self.assertTrue(c.outer_width == 70)
     self.assertTrue(c.outer_height == 80)
     self.assertTrue(c.outer_bounds[0] == 70)
     self.assertTrue(c.outer_bounds[1] == 80)
예제 #19
0
    def test_set_outer_position(self):
        c = Component(bounds=[50.0, 60.0], padding=10, border_visible=False)
        # Test setting various things
        c.outer_position = [0,0]
        self.assertTrue(c.outer_x == 0)
        self.assertTrue(c.outer_y == 0)
        self.assertTrue(c.x == 10)
        self.assertTrue(c.y == 10)
        self.assertTrue(c.outer_x2 == 69)
        self.assertTrue(c.outer_y2 == 79)
        c.outer_x = 10
        self.assertTrue(c.x == 20)
        self.assertTrue(c.outer_x2 == 79)
        c.outer_x2 = 99
        self.assertTrue(c.outer_x2 == 99)
        self.assertTrue(c.outer_x == 30)
        self.assertTrue(c.x2 == 89)
        self.assertTrue(c.x == 40)
        c.outer_y2 = 99
        self.assertTrue(c.outer_y2 == 99)
        self.assertTrue(c.outer_y == 20)
        self.assertTrue(c.y2 == 89)
        self.assertTrue(c.y == 30)

        return
예제 #20
0
def test_padding_init():
    """ Make sure that padding traits passed to the constructor get set in the
    correct order.
    """
    c = Component()
    assert c.padding_top == 0
    assert c.padding_bottom == 0
    assert c.padding_left == 0
    assert c.padding_right == 0
    c = Component(padding=50)
    assert c.padding_top == 50
    assert c.padding_bottom == 50
    assert c.padding_left == 50
    assert c.padding_right == 50
    c = Component(padding=50, padding_top=15)
    assert c.padding_top == 15
    assert c.padding_bottom == 50
    assert c.padding_left == 50
    assert c.padding_right == 50
    c = Component(padding=50, padding_bottom=15)
    assert c.padding_top == 50
    assert c.padding_bottom == 15
    assert c.padding_left == 50
    assert c.padding_right == 50
    c = Component(padding=50, padding_left=15)
    assert c.padding_top == 50
    assert c.padding_bottom == 50
    assert c.padding_left == 15
    assert c.padding_right == 50
    c = Component(padding=50, padding_right=15)
    assert c.padding_top == 50
    assert c.padding_bottom == 50
    assert c.padding_left == 50
    assert c.padding_right == 15
    def test_adjust_bounds(self):
        container = Container(bounds=[100.0, 100.0])
        component = Component(bounds=[50.0, 50.0], position=[5.0, 5.0])
        container.add(component)
        view = Viewport(component=container,
                        view_bounds=[50.0, 50.0],
                        view_position=[10, 10],
                        position=[0, 0],
                        bounds=[50, 50])

        # simple resize
        view.bounds = [60, 60]
        self.assertEqual(view.view_position, [10, 10])
예제 #22
0
 def create_simple_components(self):
     "Returns a container with 3 items in it; used by several tests."
     c1 = Component(bounds=[5.0, 10.0])
     c2 = Component(bounds=[6.0, 10.0])
     c3 = Component(bounds=[7.0, 10.0])
     container = Container(bounds=[100.0, 100.0])
     container.add(c1)
     c1.position = [20, 10]
     container.add(c2)
     c2.position = [40, 10]
     container.add(c3)
     c3.position = [60, 10]
     return container
    def test_basic_viewport(self):
        container = Container(bounds=[100.0, 100.0])
        component = Component(bounds=[50.0, 50.0], position=[5.0, 5.0])
        container.add(component)
        view = Viewport(component=container,
                        view_position=[10.0, 10.0],
                        view_bounds=[50.0, 50.0],
                        position=[0, 0],
                        bounds=[50, 50])

        self.assertEqual(view.view_position, [10, 10])
        print(view.components_at(0.0, 0.0), view.view_position)
        self.assertTrue(view.components_at(0.0, 0.0)[0] == component)
        self.assertTrue(view.components_at(44.9, 0.0)[0] == component)
        self.assertTrue(view.components_at(0.0, 44.9)[0] == component)
        self.assertTrue(view.components_at(44.9, 44.9)[0] == component)

        self.assertTrue(view.components_at(46.0, 45.0) == [])
        self.assertTrue(view.components_at(46.0, 0.0) == [])
        self.assertTrue(view.components_at(45.0, 46.0) == [])
        self.assertTrue(view.components_at(0.0, 46.0) == [])
예제 #24
0
    def setUp(self):

        EnamlTestAssistant.setUp(self)

        enaml_source = """
from enaml.widgets.api import MainWindow
from traits_enaml.widgets.enable_canvas import EnableCanvas

enamldef MainView(MainWindow):
    attr model

    EnableCanvas:
        name = 'canvas'
        component << model.component
"""
        self.component = Component()
        self.model = Model(component=self.component)

        view, toolkit_view = self.parse_and_create(enaml_source,
                                                   model=self.model)

        self.view = view
    def test_adjust_bounds_vanchor_top(self):
        container = Container(bounds=[100.0, 100.0])
        component = Component(bounds=[50.0, 50.0], position=[5.0, 5.0])
        container.add(component)
        view = Viewport(component=container,
                        view_bounds=[50.0, 50.0],
                        view_position=[20, 20],
                        position=[0, 0],
                        bounds=[50, 50],
                        vertical_anchor='top')

        # simple resize
        view.bounds = [60, 60]
        self.assertEqual(view.view_position, [20, 10.0])

        # resize beyond bottom
        view.bounds = [80, 80]
        self.assertEqual(view.view_position, [20, -10.0])

        # resize bigger than view
        view.bounds = [120, 120]
        self.assertEqual(view.view_position, [20, -50.0])
    def test_adjust_bounds_hanchor_center(self):
        container = Container(bounds=[100.0, 100.0])
        component = Component(bounds=[50.0, 50.0], position=[5.0, 5.0])
        container.add(component)
        view = Viewport(component=container,
                        view_bounds=[50.0, 50.0],
                        view_position=[20, 20],
                        position=[0, 0],
                        bounds=[50, 50],
                        horizontal_anchor='center')

        # simple resize
        view.bounds = [60, 60]
        self.assertEqual(view.view_position, [15.0, 20])

        # resize beyond left
        view.bounds = [95, 95]
        self.assertEqual(view.view_position, [-2.5, 20])

        # resize bigger than view
        view.bounds = [120, 120]
        self.assertEqual(view.view_position, [-15.0, 20])
예제 #27
0
 def __init__(self, **traits):
     Component.__init__(self, **traits)
     self.pointer = self.normal_pointer
     return
예제 #28
0
파일: cliptest.py 프로젝트: swift-nav/chaco
 def __init__(self, *args, **kw):
     Component.__init__(self, *args, **kw)
예제 #29
0
 def __init__(self, **traits):
     Component.__init__(self, **traits)
     self.pointer = self.normal_pointer
     return
예제 #30
0
 def check_container(self):
     c = Component()
     self.assertTrue(c.container is None)
예제 #31
0
파일: cliptest.py 프로젝트: B-Rich/chaco
 def __init__(self, *args, **kw):
     Component.__init__(self, *args, **kw)