rowspan/colspan in Grid Layout

2,374 views
Skip to first unread message

Alexey Smishlayev

unread,
Mar 10, 2013, 12:45:38 PM3/10/13
to kivy-...@googlegroups.com
Hello!
I would like to have rowspan/colspan behavior in my application. As I can see, Kivy does not support this. Is it possible to implement similar mechanics in extended GridLayout class?

Cheers, Alexey

Gabriel Pettier

unread,
Mar 10, 2013, 2:33:20 PM3/10/13
to kivy-...@googlegroups.com
Hi

I did a quick example of one way to do it recently

https://gist.github.com/tshirtman/5003739

cheers, Gabriel
> --
> You received this message because you are subscribed to the Google Groups "Kivy users support" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Alexey Smishlayev

unread,
Mar 10, 2013, 4:01:30 PM3/10/13
to kivy-...@googlegroups.com

Hello,
Very nice exaple, thank you for helping out!

Cheers

You received this message because you are subscribed to a topic in the Google Groups "Kivy users support" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/kivy-users/ZzQg-xxKnVc/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to kivy-users+...@googlegroups.com.

Alexey Smishlayev

unread,
Apr 24, 2013, 5:28:15 PM4/24/13
to kivy-...@googlegroups.com
Hello!
How do i reproduce the part
        # let's rowspan 2
       Widget:
           Button:
               y: placeholder1.y
               x: self.parent.x
               width: self.parent.width
               height: self.parent.height + placeholder1.height
               text: '='
               on_press: app.calc(calc)

in the Python code? I have tried
button = Button(text="=")
widget
= Widget()
widget
.add_widget(button)
button
.x = button.parent.x
button
.y = button.parent.y
button
.height = button.parent.height
button
.width = button.parent.width

But the Button is still hanging around in the corner :(

Best regards,
Alexey

Gabriel Pettier

unread,
Apr 24, 2013, 8:11:41 PM4/24/13
to kivy-...@googlegroups.com
Hi

Yes, if you do it this way, the positions of the widget you just created
aren't computed yet, so your new button will have the default values,
i.e: no changes.

So you need to bind these values to the values of the original, instead
of just copying, something like.

widget.bind(pos=button.setter('pos'))
widget.bind(size=button.setter('size'))

so when widget.pos or widget.size changes (here, it will at least change
just after this frame), button's properties are adapted to these new
values.

This is a reason for kv to exist, it makes things easier.

cheers.

Alexey Smishlayev

unread,
Apr 25, 2013, 3:38:38 AM4/25/13
to kivy-...@googlegroups.com
Yes, of course! Forgot, that they are all properties. Coding at night was probably not the best idea (:

Thank you, Gabriel.

Yes, I agree, kv language improves widgets' code read/write-ability, but currently I am working on a subclass of GridLayout, to implement support for rowspan/colspan widget attributes. So have to do it in Python (:

Best regards,
Alexey

200...@gmail.com

unread,
Sep 17, 2015, 4:37:28 PM9/17/15
to Kivy users support
Hi there, thanks for the example. It is possible to do this for buttons, but could you do something like this if you wanted to span a label across multiple columns and rows?
 
Thanks.

Alexey Smishlayev

unread,
Sep 18, 2015, 3:23:46 AM9/18/15
to Kivy users support
Hello!
Two years ago I implemented GridLayout sublass, which accepts rowspan/colspan properties for nested widgets. I can't tell you much about the realization now, as I don't remember, but here is the code for my layout.py module: http://pastebin.com/tsc5KTMB and here is a local ".widgets" module: http://pastebin.com/7P0kEVLw


Regards, Alexey

200...@gmail.com

unread,
Sep 18, 2015, 4:47:39 PM9/18/15
to Kivy users support
Thank you very much Alexey, very useful :)
Reply all
Reply to author
Forward
0 new messages