Generic Number of Properties

12 views
Skip to first unread message

Kivy User

unread,
Feb 3, 2020, 5:22:28 AM2/3/20
to Kivy users support
Hey,
my goal is to observe a generic number of properties generated at runtime.
So the manager class will get a number of x nodes and I want my UI and other interfaces (Midi) to observe some of them, since properties have to be declared at class level I'm kind of struggling how to solve this elegant.

The options in Kivy I found so far to solve this problem are:
  • using a DictProperty and add entries at runtime, works but ugly since add every update I have to check the complete Dic if the change is relevant for the specific class
  • I tried playing with "apply_property" but didnt get that to work with a generic name
So my question is, if there are any other options I'm overseeing currently.
thanks in advance
A happy user


Elliot Garbus

unread,
Feb 3, 2020, 8:18:58 AM2/3/20
to kivy-...@googlegroups.com

Properties are declared at the class level, but the are instance properties.

 

Each property will have it’s own event that will fire when the property changes.  If I declare a kivy property called my_prop, if there is a change in self.myprop, it will call self.on_myprop().

 

https://kivy.org/doc/stable/api-kivy.properties.html?highlight=properties#observe-property-changes

 

Alternatively you would walk the widget tree,

https://kivy.org/doc/stable/api-kivy.uix.widget.html?highlight=widget#kivy.uix.widget.Widget.walk

and use hasattr() on the appropriate widget types (type()).

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/1b68ea50-5531-47b6-a630-e8cb60e2205b%40googlegroups.com.

 

Kivy User

unread,
Feb 3, 2020, 8:52:58 AM2/3/20
to Kivy users support
Maybe my question wasnt clear enough. I want a generic number of properties, but only at runtime the number / names will be given from the backend. This collides with the problem that I have to declare them at class level.
Cant declare them If I dont know the number, names, attributes ... ;)

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-...@googlegroups.com.

Elliot Garbus

unread,
Feb 3, 2020, 9:00:45 AM2/3/20
to kivy-...@googlegroups.com

Could you create class instances of a class that contains a property?

The property would have the same name, but the class would have a unique name.

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/8d1f3770-3adf-459f-845a-e2785895c6a4%40googlegroups.com.

 

Reply all
Reply to author
Forward
0 new messages