Example #1
0
def xxtest_01():
    app = wx.App(redirect = False)
    model = TextModel(testtext)
    layout = Layout(model)

    n = len(model)
    assert len(layout) == n
    model.insert(10, TextModel('XXX'))
    assert len(model) == n+3
    
    layout.inserted(10, 3)
    assert len(layout) == n+3
Example #2
0
def benchmark_00():
    text = ""
    for i in range(1000):
        text += "Copy #%d \n" % i

    model = TextModel(u'Hello World!')
    model.set_properties(6, 11, fontsize=14)
    model.set_properties(0, 11, bgcolor='yellow')
    model.insert(len(model), TextModel(text))
    app = wx.App(False)

    frame = wx.Frame(None)
    view = WXTextView(frame, -1)
    view.model = model
    frame.Show()

    for i in range(100):
        model.insert_text(1000, "TEXT")
Example #3
0
def test_04():
    "insert/remove"
    factory = Factory()
    model = TextModel("123\n\n567890 2 4 6 8 0")
    boxes = factory.create_boxes(model.texel)
    paragraphs = create_paragraphs(boxes)
    updater = Updater(model, factory, 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')]]]"
    assert len(layout) == len(model)
    assert layout.height == 3

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

    factory = Factory()
    model = TextModel("123")
    updater = Updater(model, factory, 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(layout) == "ParagraphStack[Paragraph[Row[TB('123xyz'), NL]], " \
        "Paragraph[Row[TB('abc')]]]"
Example #4
0

model = TextModel(u'Hello World!')
model.set_properties(6, 11, fontsize=14)
model.set_properties(0, 11, bgcolor='yellow')

instructions = """

You can edit this text as you like. Undo
is ctrl-z and redo ctrl-r. The second
window displays exactly the same text and
follows the changes.

"""

model.insert(len(model), TextModel(instructions))

# display the texmodel in a view
frame = wx.Frame(None)
view = WXTextView(frame)
view.model = model
frame.Show()

# set cursor and selection
view.index = 5
view.selection = 0, 5

# display the same textmodel in a second view
frame2 = wx.Frame(None)
view2 = WXTextView(frame2)
view2.model = model