Example #1
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)
Example #2
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))
Example #3
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))