Created
May 15, 2013 07:15
-
-
Save Kovak/5582161 to your computer and use it in GitHub Desktop.
Retrieving the definition of properties from kv files on add_widget
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from kivy.app import App | |
from kivy.uix.widget import Widget | |
from kivy.uix.boxlayout import BoxLayout | |
from kivy.properties import StringProperty | |
from kivy.clock import Clock | |
from kivy.lang import Builder | |
class Widget1(Widget): | |
string_id = StringProperty('default') | |
class Widget2(BoxLayout): | |
def __init__(self, **kwargs): | |
super(Widget2, self).__init__(**kwargs) | |
Clock.schedule_once(self.print_children_properties) | |
def add_widget(self, widget): | |
super(Widget2, self).add_widget(widget) | |
print widget.string_id | |
def print_children_properties(self, dt): | |
for each in self.children: | |
print each.string_id | |
Builder.load_string(""" | |
Widget2: | |
<Widget2>: | |
Widget1: | |
string_id: 'widget 1' | |
Widget1: | |
string_id: 'widget 2' | |
""") | |
class TestApp(App): | |
def build(self): | |
pass | |
if __name__ == '__main__': | |
TestApp().run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment