I'm reasonably new to Kivy, but donkey's years as a dev.
I like the concept of kv files (not polluting logic with UI layout) -
so I've laid out my complete app inside the kv file.
The classes behind the major UI elements are in my main.py.
My issue is that:
- I call
theApp.run(),
- In the App build method, I construct my MainWindow().
class PrivateApp(App):
def build(self):
self.main = MainWindow()
print("self.main.ids", self.main.ids)
return self.main
This all works. The app is constructed, all the UI elements are constructed and work.
The problem is that in one corner of the UI I have a ListView (notelist_items below)
And in there I have an adapter. I declare the adapter in kv:
<NotesListContainer>:
notelist_header: notelist_header
notelist_items: notelist_items
orientation: 'vertical'
...
ListView:
id: notelist_items
orientation: 'vertical'
adapter: main.NotesListAdapter(data=root.data, cls=Factory.NoteListItem, args_converter=root.args_converter, allow_empty_selection=False, selection_mode='single', on_selection_change=root.sel_change, propagate_selection_to_data=True)
I have learnt out that you cannot declare the on_selection_change in the kv file - it must be done in code.
So I do that...
class NotesListContainer(BoxLayout):
data = ListProperty()
notelist_items = ObjectProperty()
note_contents = None
def __init__(self, **kwargs):
super(NotesListContainer, self).__init__(**kwargs)
print("IDS", self.ids)
self.ids["notelist_items"].adapter.bind(on_selection_change=self.sel_change)
I have seen example code where you *can* access self.ids in the constructor.
(e.g. see the accepted answer in here: http://stackoverflow.com/questions/24297061/kivy-binding-a-callback-to-simplelistadapter-in-kv)
Which is what I am doing here. But self.ids is *empty* at this point (as the print proved).
You'll notice above that I print ids at the end of the app.build(), and it is full at that point.
But ids is empty end of the NotesListContainer constructor.
It seems I need to bind on_selection_change to my adapters after build, right?
If so, is there a widget event that fires after build is complete?
Or have I got this wrong?
Thx for any advice you can give.
Paul.