newb alert: grid layout refresh

705 views
Skip to first unread message

Art

unread,
Jan 13, 2012, 8:52:07 AM1/13/12
to Kivy users support
Greeting,

I am clearly missing something. Please excuse.

But..

I have a simple app that present data via a grid layout with labels.

I have two questions.

1) is there a way to refresh the grid. such that the labels are bound
within the grid block. I have a several labels in a grid and when they
get populated the data from one overflows onto the others. My
expectation was that the grid would adjust and keep the labels
distincly within their grid box. <I know my terminology is off>

<Test>
GridLayout:
rows: 4
cols: 1
Button:
text: root.info
on_press: root.update()

Label:
valign: 'top'
size_hint: (1,.5)
id: lbl1
text: '1'
font_size: 30
bold: 1
Label:
valign: 'top'
id: lbl2
text: '2'
Label:
valign: 'top'
id: lbl3
text: '3'
class Test(FloatLayout):
lbl1 = ObjectProperty(None)
lbl2 = ObjectProperty(None)
lbl3 = ObjectProperty(None)

def update(self):
self.lbl1.text='blah/nblah/nblah/nbblah/n'
self.lbl2.text='blah/nblah/nblah/nbblah/n'

class TestApp(App):
icon='T.png'

def build(self):
return WhereAreWe()
#Clock.schedule_interval(partial(self.update), 5)


if __name__ == '__main__':
TestApp().run()

2) The other question is how do I call the clock component down in the
app. If I uncomment it it barks about self being undeclared in that
context (kinda of course).

Thanks for the feedback guys.

My expertise is system management and it was fairly easy to use this
toolset to get some stuff done. This is very cool stuff. look forward
to you response.

Mathieu Virbel

unread,
Jan 13, 2012, 1:08:49 PM1/13/12
to kivy-...@googlegroups.com
Hi,

1. check our examples/widgets/textalign.py. Our approach is that the widget have its own bounding box (determined by x/y/width/height). Its texture (label content) are not bound to the bounding box by default. By default, the texture is rendered without any constraint, and centered in the widget.
Now if you want to resize the widget bounding box according to texture size, you can write something like (only for height for example):

        Label: 
            valign: 'top' 
            id: lbl2 
            text: '2' 
            size_hint_y: None # don't set height from parent height
            height: self.texture_size[1] # bind our widget height to our texture height

2. You're using partial() without any argument. Reread the python documentation about partial, it's done to append your own argument to a callback.
+ self.update => self is your App, and their is no App.update method, update() is in your widget.
So move the schedule_interval to your __init__ in Test widget, or replace self with the instance of your Test widget (not showed in the example)

Mathieu

Art

unread,
Jan 14, 2012, 3:44:26 PM1/14/12
to Kivy users support
Thank Mathieu,

Thats exactly the help I needed.

I know it can sometimes be frustrating to answer simple questions. I
had reviewed the examples, but missed the impact of size_hint and
height -> texture_size.

Really appreciate your help sir. Now the labels are bound as i wished
and the schedule is working fine.

Mathieu Virbel

unread,
Jan 14, 2012, 5:02:51 PM1/14/12
to kivy-...@googlegroups.com
Don't worry, it's the a noob question, it's one of the most asked, cause we decided to not make all this thing automatic, and let the user choose the best approach for its application.
If you ask, that's mean our documentation is lacking, and we must rewrite it on that case :)

Mathieu

Mathieu Virbel

unread,
Jan 15, 2012, 3:26:39 PM1/15/12
to kivy-...@googlegroups.com
Don't worry, it's the a noob question, it's one of the most asked, cause we decided to not make all this thing automatic, and let the user choose the best approach for its application.
If you ask, that's mean our documentation is lacking, and we must rewrite it on that case :)

Mathieu


Le 14 janv. 2012 à 21:44, Art a écrit :

Reply all
Reply to author
Forward
0 new messages