1
I’m using Kivy for an app.
I have a database in Google Firebase working well, I can save there quietly. I would like to return this data to my app, but before I have problems with it, I can’t list anything in Kivy.
I wanted to use Kivy’s Listview, but in the documentation it already says to use Recycleview, but I found it somewhat confusing (the documentation). It made me doubt and I couldn’t use.
In the documentation of Recycleview there is the following:
Builder.load_string('''
<RV>:
viewclass: 'Label'
RecycleBoxLayout:
default_size: None, dp(56)
default_size_hint: 1, None
size_hint_y: None
height: self.minimum_height
orientation: 'vertical'
''')
class RV(RecycleView):
def __init__(self, **kwargs):
super(RV, self).__init__(**kwargs)
self.data = [{'text': str(x)} for x in range(100)]
class TestApp(App):
def build(self):
return RV()
if __name__ == '__main__':
TestApp().run()
But I use the Screenmanager to control my screens, so in the Testapp class I return a 'Sm', as in the example gives own documentation:
# Declare both screens
class MenuScreen(Screen):
pass
class SettingsScreen(Screen):
pass
# Create the screen manager
sm = ScreenManager()
sm.add_widget(MenuScreen(name='menu'))
sm.add_widget(SettingsScreen(name='settings'))
class TestApp(App):
def build(self):
return sm
if __name__ == '__main__':
TestApp().run()
If you observe the syntax are different, and then I get lost, not knowing what to do and how to write so that the two work together and I can generate a list of items in one of my screens Screenmanager.
I could not find in the doc something to help me, but I did the test codes of these two pages and they worked, but I did not know how to do everything together.
I tried the following (In what I imagine, it was to list 20 items as Label). In my document where I control the screens (it works for all others):
class ListaEvento(Screen, RecycleView):
def __init__(self, **kwargs):
super(ListaEvento, self).__init__(**kwargs)
self.data = [{'text': str(x)} for x in range(20)]
In my document Kv, which works well for the visual part of the other screens too:
<ListaEvento>:
canvas:
Rectangle:
source: 'design/fundo.png'
size: self.width, self.height
viewclass: 'Label'
RecycleBoxLayout:
default_size: None, dp(56)
default_size_hint: 1, None
size_hint_y: None
height: self.minimum_height
orientation: 'vertical'
But I had no result, it just displays the blue screen, which is the one I pull on the canvas, but does not list anything. I even put up a print too to test, but it does not appear in the terminal, so nothing is happening. This test of displaying 20 items is based on the documentation, in which there are 100 items.
From this, I intend to list items coming from my database, but one problem at a time. I’ve been trying for a couple of days, sorry if it’s too silly, but in Kivy’s documentation I couldn’t find the answer.
Thank you for your attention.