<s> from kivy . app import runTouchApp <EOL> from kivy . uix . gridlayout import GridLayout <EOL> from kivy . properties import StringProperty <EOL> from kivy . lang import Builder <EOL> from kivy . utils import get_hex_from_color , get_random_color <EOL> import timeit <EOL> import re <EOL> import random <EOL> from functools import partial <EOL> def layout_perf ( label , repeat ) : <EOL> if repeat : <EOL> repeat = int ( repeat ) <EOL> else : <EOL> return '<STR_LIT:None>' <EOL> return str ( timeit . Timer ( label . _label . render ) . repeat ( <NUM_LIT:1> , repeat ) ) <EOL> def layout_real_perf ( label , repeat ) : <EOL> if repeat : <EOL> repeat = int ( repeat ) <EOL> else : <EOL> return '<STR_LIT:None>' <EOL> old_text = label . _label . texture <EOL> label . _label . texture = label . _label . texture_1px <EOL> res = str ( timeit . Timer ( partial ( label . _label . render , True ) ) . repeat ( <NUM_LIT:1> , <EOL> repeat ) ) <EOL> label . _label . texture = old_text <EOL> return res <EOL> kv = '''<STR_LIT>''' <EOL> text = '''<STR_LIT>''' <EOL> words = re . split ( '<STR_LIT>' , text ) <EOL> def annotate ( pre , post , callable , words ) : <EOL> state = False <EOL> i = random . randint ( <NUM_LIT:0> , <NUM_LIT:4> ) <EOL> while i < len ( words ) : <EOL> if '<STR_LIT:U+0020>' in words [ i ] or '<STR_LIT:\n>' in words [ i ] : <EOL> i += <NUM_LIT:1> <EOL> continue <EOL> if not state : <EOL> words [ i ] = pre . format ( callable ( ) , words [ i ] ) <EOL> else : <EOL> words [ i ] = post . format ( words [ i ] ) <EOL> state = not state <EOL> i += random . randint ( <NUM_LIT:1> , <NUM_LIT:7> ) <EOL> annotate ( '<STR_LIT>' , '<STR_LIT>' , partial ( random . randint , <NUM_LIT:8> , <NUM_LIT> ) , words ) <EOL> annotate ( '<STR_LIT>' , '<STR_LIT>' , str , words ) <EOL> annotate ( '<STR_LIT>' , '<STR_LIT>' , str , words ) <EOL> annotate ( '<STR_LIT>' , '<STR_LIT>' , <EOL> lambda : get_hex_from_color ( get_random_color ( ) ) , words ) <EOL> annotated_text = '<STR_LIT>' . join ( words ) <EOL> class LabelTest ( GridLayout ) : <EOL> text = StringProperty ( text ) <EOL> sized_text = StringProperty ( annotated_text ) <EOL> if __name__ in ( '<STR_LIT:__main__>' , ) : <EOL> Builder . load_string ( kv ) <EOL> runTouchApp ( LabelTest ( ) ) </s>
