Displaying a large amount of text output

259 views
Skip to first unread message

Corbin Bell

unread,
Dec 1, 2014, 3:36:15 AM12/1/14
to kivy-...@googlegroups.com
Two issues in the same topic:
1) I'm trying to display a large amount of text (several hundred lines).
I build the entire output into one string and then assign that string to the widget.text

Something simple such as:

for i in somelist:
    textinput.text=textinput+str(row)

I've tried doing it both in a read-only TextInput as well as an RST, For some reason, the RST is much faster (not sure why) but I don't like it's formatting. but both take way too long for simple text output.

Is there a better way to do console/text output for both speed and formatting?

2) In order to scroll through the large amount of output, I put the textinput on top of a scrollview. The text is top-aligned to the view and so you actually have to scroll down to see the most recent output at the bottom. Is there a way to reverse this so that it's similar to traditional console output -- you see the most recent output at the bottom and scroll up to see history?

Thanks for the help!

ZenCODE

unread,
Dec 1, 2014, 5:21:19 AM12/1/14
to kivy-...@googlegroups.com
You want to minimize the amount of times you set the text property: that's the expensive part. Build the string first, something like:

text = ''

for i in somelist:
    text
+= str(row)
textinput
.text = text

About 2, sorry, not sure...


ZenCODE

unread,
Dec 1, 2014, 5:40:57 AM12/1/14
to kivy-...@googlegroups.com
Of course,  2 could be solved by:

    text = str(row) + text

Corbin Bell

unread,
Dec 1, 2014, 2:47:15 PM12/1/14
to kivy-...@googlegroups.com
Thank you! Makes a HUGE difference. You're right... it was the constant updating of the text field in the widget. It's nearly immediate render now.

As for #2... yeah I could do that for the order of the info, but the display still defaults to the top of the window. I want it in the order it's in, but I want it to default align to the bottom of the TextInput and default the TextInput window to the bottom of the scroll view.

Thanks again for #1! Huge Help!

ZenCODE

unread,
Dec 2, 2014, 1:05:50 AM12/2/14
to kivy-...@googlegroups.com
Glad that helped ;-)

As for #2, I've not tried it with a textinput, but the Label has a texture property which gives you the size and position of the actual text. We've use this to manually align text by binding to texture changes e.g. to get an autosizing label,

class AutoLabel(Label):
    def __init__(self, **kwargs):
        """ Initialise the widget """
        super(AutoLabel, self).__init__(**kwargs)

        self.size_hint_x = None
        self.bind(on_texture_size=self.on_texture_size)
        self.texture_update()

    def on_texture_size(self, *args):
        if self.texture:
            self.width = self.texture.width + dp(6)

If the TextInput has a similar property, you could use a similar technique to size and place the TextInput where you want it whenever the text changes? Maybe not. Just thought I'd throw that out there..

Cheers
Reply all
Reply to author
Forward
0 new messages