예제 #1
0
 def testRequestSize(self):
     """WindowLayout.requestSize requests the size of its child."""
     my_layout = windowlayout.WindowLayout()
     child = MockWidget(10, 20)
     child.requestSize(True)
     requested_size = my_layout.requestSize([child])
     self.assertEquals(requested_size, Size(10, 20))
예제 #2
0
 def testRequestSize(self):
     """BorderLayout.requestSize adds its margins to the child's size."""
     my_layout = borderlayout.BorderLayout((1, 2, 3, 4))
     child = MockWidget(10, 20)
     child.requestSize(True)
     requested_size = my_layout.requestSize([child])
     self.assertEquals(requested_size.asTuple(), (14, 26))
예제 #3
0
 def testAllocateSizeTooBigNoExpand(self):
     """BorderLayout.allocateSize expands the margins."""
     my_layout = borderlayout.BorderLayout((1, 2, 3, 4))
     child = MockWidget(10, 20)
     child.can_expand_width = False
     child.can_expand_height = False
     child.requestSize(True)
     allocated_size = SizeAllocation((100, 200), (30, 50))
     my_layout.allocateSize(allocated_size, None, [child])
     child_size = child.allocated_size
     # The child does not expand: its size is nominal but the position not.
     #
     # Horizontal margin: 30 - 10 = 20.
     # The original margins are 1 and 3, total 4.
     # ratio = 20 / 4 = 5.
     # New margins are 1 * 5 = 5 and 3 * 5 = 15.
     # Check: 5 + 15 = 50.
     # The child's left is after the first margin: 5.
     #
     # Vertical margin: 50 - 20 = 30.
     # The original margins are 2 and 4, total 6.
     # ratio = 30 / 6 = 5.
     # New margins are 2 * 5 = 10 and 4 * 5 = 20.
     # Check: 10 + 20 = 30.
     # The child's top is after the first margin: 10.
     self.assertEquals(child_size.pos.asTuple(), (105, 210))
     self.assertEquals(child_size.size.asTuple(), (10, 20))
예제 #4
0
 def testAllocateSize(self):
     """ScrollLayout.allocateSize sets the children position to (0, 0)."""
     my_scroll = scrolllayout.ScrollLayout()
     child = MockWidget(10, 100)
     child.requestSize(True)
     requested_size = my_scroll.requestSize([child])
     allocated_size = SizeAllocation((10, 20), (30, 40))
     my_scroll.allocateSize(allocated_size, requested_size, [child])
     child_size = child.allocated_size
     self.assertEquals(child_size, SizeAllocation((0, 0), (30, 100)))
예제 #5
0
 def testAllocateSize(self):
     """WindowLayout.allocateSize sets the children position to (0, 0)."""
     my_layout = windowlayout.WindowLayout()
     child = MockWidget(10, 20)
     child.requestSize(True)
     requested_size = my_layout.requestSize([child])
     allocated_size = SizeAllocation((10, 20), (30, 40))
     my_layout.allocateSize(allocated_size, requested_size, [child])
     cell_size = child.allocated_size
     self.assertEquals(cell_size, SizeAllocation((0, 0), (30, 40)))
예제 #6
0
 def testAllocateSizeTooSmall(self):
     """BorderLayout.allocateSize reduces the size of the child."""
     my_layout = borderlayout.BorderLayout((1, 2, 3, 4))
     child = MockWidget(10, 20)
     child.requestSize(True)
     allocated_size = SizeAllocation((100, 200), (5, 10))
     my_layout.allocateSize(allocated_size, None, [child])
     child_size = child.allocated_size
     self.assertEquals(child_size.pos.asTuple(), (101, 202))
     self.assertEquals(child_size.size.asTuple(), (1, 4))
예제 #7
0
 def testAllocateSizeIdeal(self):
     """BorderLayout.allocateSize in ideal case."""
     my_layout = borderlayout.BorderLayout((1, 2, 3, 4))
     child = MockWidget(10, 20)
     child.requestSize(True)
     requested_size = my_layout.requestSize([child])
     allocated_size = SizeAllocation((100, 200), requested_size)
     my_layout.allocateSize(allocated_size, requested_size, [child])
     child_size = child.allocated_size
     self.assertEquals(child_size.pos.asTuple(), (101, 202))
     self.assertEquals(child_size.size.asTuple(), (10, 20))
예제 #8
0
 def testAllocateSizeTooBigExpand(self):
     """BorderLayout.allocateSize expands the child."""
     my_layout = borderlayout.BorderLayout((1, 2, 3, 4))
     child = MockWidget(10, 20)
     child.can_expand_width = True
     child.can_expand_height = True
     child.requestSize(True)
     allocated_size = SizeAllocation((100, 200), (30, 50))
     my_layout.allocateSize(allocated_size, None, [child])
     child_size = child.allocated_size
     # The child expands, so only its size changes.  Its location doesn't.
     self.assertEquals(child_size.pos.asTuple(), (101, 202))
     self.assertEquals(child_size.size.asTuple(), (30 - 4, 50 - 6))
예제 #9
0
 def testNegotiateSize(self):
     """Sizeable.negotiateSize allocates what it requests."""
     widget = MockWidget(32, 16)
     self.assertFalse(widget.requested_size)
     self.assertFalse(widget.allocated_size)
     widget.negotiateSize(True)
     self.assertTrue(widget.requested_size)
     self.assertTrue(widget.allocated_size)
     self.assertEquals(widget.allocated_size.size, widget.requested_size)
     self.assertEquals(widget.allocated_size.pos, size.Pos(0, 0))
     # Check that the position is maintained.
     widget.allocated_size.width = 0
     widget.allocated_size.height = 0
     widget.allocated_size.left = 100
     widget.allocated_size.top = 200
     widget.negotiateSize(True)
     self.assertEquals(widget.allocated_size.size, widget.requested_size)
     self.assertEquals(widget.allocated_size.pos, size.Pos(100, 200))
예제 #10
0
 def testRequestSizeForwardRequest(self):
     """Container.requestSize obeys the forward_request parameter."""
     widget1 = MockWidget(10, 20)
     widget2 = MockWidget(30, 40)
     my_container = container.Container()
     my_container.addChild(widget1, 'end')
     my_container.addChild(widget2, 'end')
     #
     my_container._layout = MockLayout()
     my_container.requestSize(True)
     requested_size = my_container.requested_size
     self.assertEquals(requested_size, Size(40, 60))
     #
     widget1.width = 20
     my_container.requestSize(False)
     requested_size = my_container.requested_size
     self.assertEquals(requested_size, Size(40, 60))
     #
     widget1.requestSize(True) # True/False doesn't matter here.
     my_container.requestSize(False)
     requested_size = my_container.requested_size
     self.assertEquals(requested_size, Size(50, 60))
     #
     widget2.width = 40
     my_container.requestSize(True)
     requested_size = my_container.requested_size
     self.assertEquals(requested_size, Size(60, 60))
예제 #11
0
    def testExpand(self):
        """Sizeable.allocateSize checks the expandability."""
        big_width = size.SizeAllocation((0, 0), (100, 20))
        big_height = size.SizeAllocation((0, 0), (10, 200))
        widget = MockWidget(10, 20)
        widget.requestSize(True)

        widget.can_expand_width = False
        widget.can_expand_height = False
        self.assertRaises(sizeable.ExpandError,
                          widget.allocateSize, big_width)
        self.assertRaises(sizeable.ExpandError,
                          widget.allocateSize, big_height)

        widget.can_expand_width = True
        widget.can_expand_height = False
        widget.allocateSize(big_width)
        self.assertRaises(sizeable.ExpandError,
                          widget.allocateSize, big_height)

        widget.can_expand_width = False
        widget.can_expand_height = True
        self.assertRaises(sizeable.ExpandError,
                          widget.allocateSize, big_width)
        widget.allocateSize(big_height)

        widget.can_expand_width = True
        widget.can_expand_height = True
        widget.allocateSize(big_width)
        widget.allocateSize(big_height)