Widget size on __init__

252 views
Skip to first unread message

Gully

unread,
Jul 25, 2012, 12:58:13 PM7/25/12
to kivy-...@googlegroups.com
Hi,

I'm working on some Kivy application that in which one of the widgets uses pyopengl to render some stuff. The widget instance, being some sort of control, resides inside a BoxLayout and has a size_hint = (1,1).
Since I need an Fbo, and looking on the panda3D example, I'm setting up the canvas on __init__ with an Fbo initialized to self.size and who'se texture is rendered using a rectangle of size=self.size and pos=self.pos.

However, self.pos and self.size both have default values on __init__ ((0,0) and (100,100), respectively). The only way I can get this initialization right is to place it in some method and call it explicitly from some button's on_released() after everything has been layed out...

So my question is (at last!) - is there a some other place in which I should initialize the canvas, some point at which self.pos and self.size have already been set by the parent widget?

Thanks!

Thomas Hansen

unread,
Jul 25, 2012, 1:53:15 PM7/25/12
to kivy-...@googlegroups.com
You could initialize (and reinitialize) the FBI in on_size so that it's always the same size as the widget?

Sent from my iPhone
--
 
 
 

ajc

unread,
Jul 27, 2012, 2:43:28 AM7/27/12
to kivy-...@googlegroups.com
Maybe this is related (turns out to also be a question):

What is the binding order relationship between the .kv file the the .py file. 

Ass some have noticed, sub-children in the .kv file, may not yet be created at the time of the parent widget in the .py file, thus giving None to objects that are bound after the parent's __init__ function is called. [Note: this seems to be a case by case basis, e.g. in some of my code, the parent knows at init about its kids, but in other parts, returns None at the time of the parent init call]

Is there a way that the parent can know, when all of its children have been binded/made, and then do something?

(Note: 2 possible solutions I can think of (but I would like to know if there are better ways of getting around this): possible solution 1: would be a set a Clock.schedule in init of the parent to see if an item (child item) you are waiting to be bound is None, if it is, then re-schedule the clock some short time into the future. Only dismiss the clock, once said object is not None (and therefore finally bound) and of course do whatever extra initialisation steps you needed). possible solution 2: assuming the kid is observed, have a do_observedkid, wrap with a boolean in that function, so you can wrap in some extra initialisation code, at the time the parent becomes aware of this kid, then flip the boolean flag switch).

B. Jack

unread,
Jul 27, 2012, 2:51:42 AM7/27/12
to Kivy Users
An observer method bound to a parent's children property will be called whenever a child is added or removed.


Date: Thu, 26 Jul 2012 23:43:28 -0700
From: clay...@gmail.com
To: kivy-...@googlegroups.com
Subject: Re: [kivy-users] Widget size on __init__
--
 
 
 

Gully

unread,
Jul 29, 2012, 4:16:01 AM7/29/12
to kivy-...@googlegroups.com
Thanks! That indeed did the trick (on_size and on_pos) :)
Reply all
Reply to author
Forward
0 new messages