Forum Archive

Incremental textView content

rb

Next question:)
Is it possible to animate the .text attribute of a ui textView?
Ie print the text one letter or a few letters at a time?
Any pointers on how best to do this?

cvp

@rb Not sure it is what you want

import ui
full = 'this is the entire text'
tv = ui.TextView()
tv.text = ''
tv.present('sheet')
def animation():
    global full
    tv.text = full[:len(tv.text)+1]
    if tv.text != full:
        ui.delay(animation,0.2)
ui.delay(animation,0.2)
cvp

@rb or

import ui
class mytv(ui.View):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.update_interval = 0.2
        self.tv = ui.TextView()
        self.tv.text = ''
        self.add_subview(self.tv)
        self.full = 'this is the entire text' 
    def update(self):
        self.tv.text = self.full[:len(self.tv.text)+1]
        if self.tv.text == self.full:
            self.update_interval = 0.0      
v = mytv()
v.present('sheet')
rb

Thankyou! Exactly what I wanted - delay() was what I needed

mikael

@rb, note that in my experience, using the update method is more stable.

mikael

And if you are going to be adding lots of these small nice animations, I will plug my Scripter module, that e.g. has reveal_text available as a simple function to call on a textual view.

rb

@mikael awesome I will check this out looks like exactly what I’m after thankyou :)