I am coming from a 'C'/unix background and learning Python. The kivy framework - for python - implements a wonderful event driven architecture, that I would like to replicate in my own app - but I'm not using Kivy due to reasons I shall avoid documenting here for sake of ease of dicsussion.
On kivy one can observe changes to a propery (set) using 'on_<property-name>'. The on_<property-name> is invoked through the hieratchy when the property value changes. If defining the class yourself:
from kivy import Widget
class MyClass(Widget):
my_property = NumericProperty(1)
def on_my_property(self, instance, value):
super(MyClass, self).on.... ??
print('My property a changed to', value)
How do I replicate this architecute?
I have looked at this Kivy source file for property class
https://github.com/kivy/kivy/blob/master/kivy/properties.pyx#L219 but there is far far more going on than I need and it is difficult for me to undertand the code. I do not see how or where the "On_<property-name>" method/function/event (whatever it is called) is defined so that I can override it in MyClass
So in my design, I want a root class to be:
class MyProperty(object):
So that I can subclass:
class MyModel(EventDispatcher):
data=MyProperty(...)
class MySubModel(MyModel):
def on_data():
But I have no idea how to implement this the on_<property> so that the superclass is called appropriately and on_<property> can be overriden by subclasses I define.
Help please , and don't forget to give the all important explanation. Please, PLEASE dont link me to google because clearly I have got to a point where I have googled and looked at sites and pages, and come here for help. And, PLEASE dont offer another solution because I've spent so long on this, that I must now understand and implement the same design patterns for sanity !! Thank you
What I have tried:
kivy/properties.pyx at master · kivy/kivy · GitHub[
^]