Example #1
0
    def get_emptychars(self):
        return '(;)'


class Root(Container):
    def __init__(self, content, **kwds):
        self.content = content
        Container.__init__(self, **kwds)

    def get_content(self):
        return [self.content]


def mk_textmodel(texel):
    model = TextModel()
    model.texel = texel
    return model


frac = Fraction(Characters(u'3'), Characters(u'4'))
root = Root(Characters(u'2'))

text = TextModel(u"A text which contains some math\n\n")
text.append(u'f = ')
text.append(mk_textmodel(frac))
text.append(u'\n\n')
text.append(mk_textmodel(root))
text.append(u' = 1.414214 ...')
text.texel.dump()
Example #2
0
import gc
import sys
sys.path.insert(0, '..')

from textmodel import TextModel
from textmodel.treebase import depth, count



# Create a long text
text = TextModel()
for i in range(10000):
    text.append(TextModel("Line %i\n" % i))

# Colorize it!
colors = 'white', 'red'
i1 = 0
i2 = 10
while i2<len(text):
    text.set_properties(i1, i2, bgcolor=colors[i1%2])
    i1 = i2
    i2 += 10

# Remove garbage so that the statistics are correct
gc.collect() 
    
# Print some statistics
print "Length of text:", len(text)
print "Number of lines:", text.nlines()
print "Depth of texel tree:", depth(text.texel)
print "Number of texels in tree:", count(text.texel)
Example #3
0
def create_text():
    # Create a long text
    global text
    text = TextModel()
    for i in range(10000):
        text.append(TextModel("Line %i: test test test test\n" % i))