Beispiel #1
0
def test_container_2():
    c = Container()
    b = TextBlock(1,1,maxcols=3)
    c.add_component(b, 1, 1)

    b2 = TextBlock(1,1,maxcols=3)
    c.add_component(b2, 1, 0, b, 'botleft')

    b.add_line(0, 'abcd')
    b2.add_line(0, 'efgh')
    assert c[:,:] == ['    ',' ab-',' cd ',' ef-',' gh ']
Beispiel #2
0
        """
        self[:, :] = ' '
        for cc in self.components:
            row, col = self.get_absolute_position(cc)
            self[row:row + cc.c.get_nrows(),
                 col:col + cc.c.get_ncols()] = cc.c.get_lines()

    def _get_lines(self):
        self._render_components()
        return super(Container, self)._get_lines()

    def __getitem__(self, index):
        self._render_components()
        return super(Container, self).__getitem__(index)

    # def __setitem__(self, index, value):


if __name__ == '__main__':
    c = Container()
    b = TextBlock(1, 1, maxcols=3)
    c.add_component(b, 1, 1)

    b2 = TextBlock(1, 1, maxcols=3)
    c.add_component(b2, 1, 0, b, 'botleft')

    b.add_line(0, 'abcd')
    b2.add_line(0, 'efgh')
    print c
    # assert c[:, :] == ['    ', ' ab-', ' cd ', ' ef-', ' gh ']
Beispiel #3
0
def test_text_block_2(text_block2):
    b = TextBlock(3, 3, fixrows=False, fixcols=True, maxrows=5, wrap=True)
    b.add_line(0, 'abcdefg')
    assert b[:, :] == ['ab-', 'cd-', 'efg']

    b = TextBlock(3, 3, fixrows=False, fixcols=True, maxrows=5, wrap=True)
    b.add_line(0, 'abcdefgh')
    assert b[:, :] == ['ab-', 'cd-', 'ef-', 'gh ']

    b = TextBlock(3, 3, fixrows=False, fixcols=True, maxrows=5, wrap=True)
    b.add_line(0, 'abcdefghijklmnop')
    assert b[:, :] == ['ab-', 'cd-', 'ef-', 'gh-', 'ij-']

    b = TextBlock(3,
                  3,
                  fixrows=False,
                  fixcols=True,
                  maxrows=5,
                  wrap=True,
                  wrap_hyphen=False)
    b.add_line(0, 'abcdefghijklmnop')
    assert b[:, :] == ['abc', 'def', 'ghi', 'jkl', 'mno']

    b = TextBlock(3, 3, fixrows=False, fixcols=False, maxcols=1000, wrap=True)
    b.add_line(0, 'abcdefg')
    assert b[:, :] == ['abcdefg', '       ', '       ']
    b.add_line(1, '12345678')
    assert b[:, :] == ['abcdefg ', '12345678', '        ']