0

I would like to know where can I see and use the parameters given on the data during the creation of the widgets.

Problem: it looks like __init__ doesn't have the information so the call has to be after so I would like to know when to be able to use my custom paramaters.

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.recycleview import RecycleView
from kivy.factory import Factory as F

Builder.load_string('''
<RV>:
    viewclass: 'CustomLabel'
    RecycleBoxLayout:
        default_size: None, dp(56)
        default_size_hint: 1, None
        size_hint_y: None
        height: self.minimum_height
        orientation: 'vertical'
''')

class CustomLabel(F.Label):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        print(kwargs, "why can't I see the stuff from data ???")

class RV(RecycleView):
    def __init__(self, **kwargs):
        super(RV, self).__init__(**kwargs)
        self.data = [{'text': str(x), "new_parameter":"idk where am I"} for x in range(100)]


class TestApp(App):
    def build(self):
        return RV()

if __name__ == '__main__':
    TestApp().run()
Utopion
  • 935
  • 1
  • 4
  • 15

1 Answers1

0

The properties from the data are not set in the __init__() method of the CustomLabel, they are each set individually after creating the basic CustomLabel. You can see this by adding an on_text() method to your CustomLabel:

class CustomLabel(F.Label):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        print(kwargs, "why can't I see the stuff from data ???")

    def on_text(self, instance, new_text):
        print('CustomLabel', id(instance), 'text set to:', new_text)
John Anderson
  • 35,991
  • 4
  • 13
  • 36
  • Can we access this event ? Can we be prevent when the data is added ? (and add some stuff then, I need to do use the stuff from data the moment I get the access) – Utopion Aug 13 '21 at 14:33
  • Not sure what you mean. A change to the `data` triggers a refresh of the `CustomLabels`. You can bind a method to `data` (or just add an `on_data()` method in the `RV` class), but changing the `data` in such a method will trigger another call to that method. Easy to create an infinite loop like that. – John Anderson Aug 13 '21 at 17:43
  • I have multiple `TextInput` in a "Row" (`BoxLayout`). My `RecycleView` is full of "Row". I give "text_list" as parameter in the data but I don't know how to write them in the launch. (I tried to write it on `__init__` and `on_kv_post` but that doesn't work. This is why I need to find the function I have to bind to (or overide). I know how to use the `refresh()` but it's already too late in the process line. – Utopion Aug 13 '21 at 18:40
  • (I didn't want to afraid people with a complex example, this is why I simplified it but the purpose is more obscur, indeed :p) – Utopion Aug 13 '21 at 18:41