RootWidget:
<RootWidget>:
BoxLayout:
PlayerLayout:
ScrollableGridLayout:
<ScrollableGridLayout>:
ScrollView:
CustomGridLayout:
<CustomGridLayout>:for i in range(rows):
for j in range(cols):
widget = Label(text= 'hey look at me') # create an instance of Label and assign it to widget
self.add_widget(widget)
WidgetGrid[i][j]=widget #assign same widget to WidgetGrid. WidgetGrid can be modified outside of layout definitionThanks for correcting my inelegant verbiage. I knew "copy" wasn't quite right.
I'm not sure if children will help much. I think you can only talk directly to the root widget. So to burrow down the hierarchy of children to get to the level you want could be quite tedious. Maybe keeping a reference to the widgets you care about is the least inelegant solution.
class CustomGridLayout(GridLayout):
def __init__(self, **kwargs):
global MyCustomGridLayout
super(CustomGridLayout, self).__init__(**kwargs)
MyCustomGridLayout = self #MyCustomGridLayout now can be changed outside the
#class definition and the on screen form will change too
class MyWidget(Widget):
container = ObjectProperty(None) #`container` will be your `CustomGridLayout` AFTER initialization
def some_callback(self, conditions, *args):
if conditions == True:
self.container.clear_widgets()
self.container.rows = args[?]; self.container.cols = args[?]
for i in range(self.container.rows):
for j in range(self.container.cols):
widget = Label(text='hey look at me')
self.container.add_widget(widget)
WidgetGrid[i][j] = widget #...Whatever that is.
RootWidget:
<CustomGridLayout>:
foo: self.foo
bar: self.bar
<MyWidget>:
container: container_id
CustomGridLayout:
id: container_id
pos: root.pos
size: root.size
<ScrollableGridLayout>:
ScrollView:
MyWidget:
<RootWidget>:
BoxLayout:
PlayerLayout:
ScrollableGridLayout:@Noob, Zencode
. . . if you want to be notified of changes, you can always store a callback? Ot, if you want to do it the Kivy way, define an "event" that can catch from anywhere? . . .
class CustomGridLayout(GridLayout):
def on_rows(self, *args):
# If the # of players change...
self.clear_widgets()
self.re_populate_widgets()
#############################################
<NumberOfPlayers@Widget>:
container: container_id
num_of_players: self.num_of_players
CustomGridLayout:
id: container_id
cols: 4
rows: root.num_of_players