ScrollView & unknown Label height

361 views
Skip to first unread message

Craig McInnes

unread,
Apr 22, 2012, 7:59:34 PM4/22/12
to kivy-...@googlegroups.com
Hey there,

In every example of scroll view I can find, the children of the scroll view have their heights specified. The one in the docs adds a lot of buttons to a gridview, and each button has a specific height set:
btn = Button(text=str(i), size_hint_y=None, height=40)
I don't know what height my Label will be, it's a lot of run time generated debug info that I'd like to expose.
I'm trying:
        sv = ScrollView(size_hint=(1, 1))

        summary_label = Label(text=debug_wall_of_text,
                              text_size=(420, None),
                              size_hint_y=None,
                              height=1000,
                              markup=True)

Which works, but if my debug_wall_of_text doesn't fit inside 1000 pixels then I can't scroll the whole thing.
I've tried setting ScrollView to different sizes, rather than the size_hint=(1, 1), but then things just get weird and the scroll view is no longer centred on the screen.

tshirtman mentioned on IRC that:
"from python you can bind on texture_size and update size with the callback"

so I tried this:
...
        summary_label = Label(text= debug_wall_of_text ,
                              text_size=(420, None),
                              size_hint_y=None,
                              markup=True)
        summary_label.bind(on_texture_size=self._set_summary_height)
...
    def _set_summary_height(self, instance, touch):
        print instance
        print touch
        # I'm sure this is wrong, the point is this callback never gets invoked
        instance.height = instance.texture_size.y

but the callback never gets called.
I also tried changing the font size and explicitly calling update_texture(), as per:
but I get an exceptions as update_texture() doesn't exist.

Two problems then, the callback isn't being called and I fail at dynamically setting the text size to get the scroll view to work.

Any help is much appreciated, thanks,
-Craig

Mathieu Virbel

unread,
Apr 23, 2012, 3:21:25 AM4/23/12
to kivy-...@googlegroups.com
Hi,

The callback that tshirtman wanted you to do is correct, only the bind()
call is wrong:

# syntax
# summary_label.bind(propname=callback)

summary_label.bind(texture_size=self._set_summary_height)

Then in the callback, it must be [1] not y:

def _set_summary_height(self, instance, size):
instance.height = size[1]
# same as:
# instance.height = instance.texture_size[1]

Craig McInnes

unread,
Apr 23, 2012, 5:57:43 AM4/23/12
to kivy-...@googlegroups.com
I changed it to use: 
summary_label.bind(texture_size=self._set_summary_height)
and the callback still isn't getting called.

Perhaps it's to do with when I'm setting the callback?
I'll try putting together a simple case. It'll either show me where I'm going wrong or I can give you a replication case.

Thanks,
-Craig

Mathieu Virbel

unread,
Apr 23, 2012, 6:01:01 AM4/23/12
to kivy-...@googlegroups.com
Sorry, it's texture_size, with only one _

In addition, if the texture size is already set, and if no relayout
happen, then you already have the good value. Add that after the bind():
summary_label.height = summary_label.texture_size[0] if
summary_label.texture_size is not None else 100


On 23/04/2012 11:57, Craig McInnes wrote:
> I changed it to use:

> summary_label.bind(texture___size=self._set_summary_height)


> and the callback still isn't getting called.
>
> Perhaps it's to do with when I'm setting the callback?
> I'll try putting together a simple case. It'll either show me where I'm
> going wrong or I can give you a replication case.
>
> Thanks,
> -Craig
>
> On Mon, Apr 23, 2012 at 8:21 AM, Mathieu Virbel <txp...@gmail.com
> <mailto:txp...@gmail.com>> wrote:
>
> Hi,
>
> The callback that tshirtman wanted you to do is correct, only the
> bind() call is wrong:
>
> # syntax

> # summary_label.bind(propname=__callback)
>
> summary_label.bind(texture___size=self._set_summary_height)

> summary_label.bind(on_texture___size=self._set_summary_height)


> ...
> def _set_summary_height(self, instance, touch):
> print instance
> print touch
> # I'm sure this is wrong, the point is this callback never gets
> invoked
> instance.height = instance.texture_size.y
>
> but the callback never gets called.
> I also tried changing the font size and explicitly calling
> update_texture(), as per:

> http://kivy.org/docs/api-kivy.__uix.label.html#kivy.uix.label.__Label.texture

Craig McInnes

unread,
Apr 23, 2012, 6:46:15 AM4/23/12
to kivy-...@googlegroups.com
Yeah I was using the single _, a double gets a key error. :)

Here's what I'm trying to do:

I'd like the text to be scrollable, but I don't know how to set up the scroll view correctly.
Couple of things:
- this: summary_label.height = summary_label.texture_size[0]
gets hit
- the callback never gets hit.
valign='top'
 on the label seems to do nothing? 

Thanks for the help.
-Craig

Craig McInnes

unread,
Apr 23, 2012, 7:25:46 AM4/23/12
to kivy-...@googlegroups.com
Ok, got it working by not setting the text in the label's constructor, and doing it after Label instance creation instead:
The callback does get called when I change the text after creating the Label instance.

Deathcloset

unread,
Aug 8, 2012, 12:38:24 AM8/8/12
to kivy-...@googlegroups.com
Most helpful!

Here I put a touch or two to make a class which can, in-a-way (perhaps poorly), be passed a big bunch of string text when instantiated.
Incidentally while testing I also learned about the extent-limits of the pygame texture canvas thingy.

Thanks all!
Reply all
Reply to author
Forward
0 new messages