예제 #1
0
def test_04():
    "copy cells"
    model = TextModel('')
    tmp = TextModel(u'for a in range(5):\n    print a')
    cell = Cell([tmp.texel], [Characters(u'')])
    model.insert(len(model), mk_textmodel(cell))
    tmp = model.copy(0, len(model))
    model.insert(0, tmp)
예제 #2
0
def test_03():
    "find_cell"
    tmp1 = TextModel(u'for a in range(3):\n    print a')
    tmp2 = TextModel(u'for a in range(10):\n    print a')
    cell1 = Cell([tmp1.texel], [Characters(u'')])
    cell2 = Cell([tmp2.texel], [Characters(u'')])

    model = TextModel('')
    model.insert(len(model), mk_textmodel(cell1))
    model.insert(len(model), mk_textmodel(cell2))

    assert find_cell(model.texel, 1) == (0, cell1)
    assert find_cell(model.texel, len(cell1) - 1) == (0, cell1)

    assert find_cell(model.texel, len(cell1)) == (len(cell1), cell2)
    assert find_cell(model.texel, len(cell1) + 5) == (len(cell1), cell2)
예제 #3
0
class Buffer:
    i = 0
    def __init__(self):
        self.model = TextModel()

    def output(self, obj, iserr=False):
        if iserr:
            properties = {'textcolor':'red'}
        else:
            properties = {}
        if has_classname(obj, "matplotlib.figure.Figure"):
            new = mk_textmodel(Figure(obj))
        elif isinstance(obj, unicode):
            new = TextModel(obj, **properties)
        elif isinstance(obj, str):
            u = unicode(obj, 'utf-8')
            new = TextModel(u, **properties)
        else:
            new = TextModel(str(obj), **properties)
        self.model.insert(self.i, new)
        self.i += len(new)
예제 #4
0
def test_04():
    "insert/remove"
    factory = Factory()
    model = TextModel("123\n\n567890 2 4 6 8 0")
    updater = Updater(model, maxw=0)
    layout = updater._layout
    assert repr(layout) == "ParagraphStack[Paragraph[Row[TB('123'), " \
        "NL]], Paragraph[Row[NL]], Paragraph[Row[TB('567890 2 4 6 8 0'), " \
        "ENDMARK]]]"
    assert len(layout) == len(model) + 1
    assert layout.height == 3

    ins = TextModel("xyz\n")
    model.insert(2, ins)
    updater.inserted(2, len(ins))
    assert len(updater._layout) == len(model) + 1
    assert repr(updater._layout) == "ParagraphStack[Paragraph[Row[TB('12xyz'),"\
        " NL]], Paragraph[Row[TB('3'), NL]], Paragraph[Row[NL]], "\
        "Paragraph[Row[TB('567890 2 4 6 8 0'), ENDMARK]]]"
    assert updater._layout.height == 4
    model.remove(2, 2 + len(ins))
    updater.removed(2, len(ins))
    assert len(updater._layout) == len(model) + 1
    assert repr(updater._layout) == "ParagraphStack[Paragraph[Row[TB('123'), " \
        "NL]], Paragraph[Row[NL]], Paragraph[Row[TB('567890 2 4 6 8 0'), " \
        "ENDMARK]]]"
    assert updater._layout.height == 3

    factory = Factory()
    model = TextModel("123")
    updater = Updater(model, maxw=0)
    layout = updater._layout

    ins = TextModel("xyz\n")
    i = len(model)
    model.insert(i, ins)
    updater.inserted(i, len(ins))

    for c in "abc":
        ins = TextModel(c)
        i = len(model)
        model.insert(i, ins)
        updater.inserted(i, len(ins))
    assert str(updater._layout) == \
        "ParagraphStack[Paragraph[Row[TB('123xyz'), NL]], " \
        "Paragraph[Row[TB('abc'), ENDMARK]]]"