3

I want to bind a property of a widget to a property of a child widget. Thus when the root widget property is changed, the change is propagated to the child property as well.

I tried it this way:

self._Child._MyProperty = self._MyProperty

This works... sometimes. But sometimes it does not work. I cannot find out when it works or why and under which conditions it does not work.

In all cases I have a binding to a method in the root widget as well:

self.bind(_MyPropert = self._MyPropertyChange)

This method is called in all cases, but sometimes the change is not propagated to the child property.

This does not work even if it feels very natural:

self.bind(_MyProperty = self._Child._MyProperty)

But in Kivy, I could do:

<RootWidget>
    <ChildWidget>
        _MyProperty: self.parent._MyProperty

The problem is I want to do it in Python, not in Kivy.

TylerH
  • 20,799
  • 66
  • 75
  • 101
CountVonCount
  • 85
  • 1
  • 5

1 Answers1

4

To bind one property to another you should use the setter event:

self.bind(_MyProperty=self._Child.setter('_MyProperty'))
TylerH
  • 20,799
  • 66
  • 75
  • 101
Mikhail Gerasimov
  • 36,989
  • 16
  • 116
  • 159
  • This didn't work for me for some reason. [This](https://pastebin.com/Ppfervuh) is my code so far. But I don't understand what I'm doing wrong in `makeLabel()`. – wimworks Jul 16 '19 at 19:07
  • 1
    @FergusWyrm It works, it just doesn't do anything because you doesn't change value of property you bind to. Change your function [as shown here](https://pastebin.com/xrNBAqcT). You'll see how "Lorem ipsum" appeared. – Mikhail Gerasimov Jul 17 '19 at 03:24
  • Yep. That's exactly what it is. I'll have to figure out if there's a way to manually trigger a property event without actually changing the value. – wimworks Jul 17 '19 at 04:39
  • 1
    @FergusWyrm just to be clear: `self.property('c_description').dispatch(self)` - is a way to trigger a property event without changing the value. – Mikhail Gerasimov Jul 17 '19 at 07:17