Don't unregister subtree if only the child is unset.

Because now, grandchildren may have set values.
This commit is contained in:
Valentin Lorentz 2019-08-24 23:37:23 +02:00
parent 633eea0730
commit e9bf05bbab
1 changed files with 11 additions and 4 deletions

View File

@ -446,16 +446,23 @@ class Value(Group):
100) convert to an integer in set() and check that the integer is less 100) convert to an integer in set() and check that the integer is less
than 100 in this method. You *must* call this parent method in your than 100 in this method. You *must* call this parent method in your
own setValue.""" own setValue."""
self._setValue(v, inherited=False)
def _setValue(self, v, inherited):
"""Like setValue, but accepted an extra 'inherited' argument.
inherited=True means the value is inherited from the parent, so if
the parent gets a new value, this group will get the new value as
well."""
self._lastModified = time.time() self._lastModified = time.time()
self.value = v self.value = v
if self._supplyDefault: if self._supplyDefault:
for (name, v) in list(self._children.items()): for (name, child) in list(self._children.items()):
if not v._wasSet: if not child._wasSet:
self.unregister(name) child._setValue(v, inherited=True)
# We call the callback once everything is clean # We call the callback once everything is clean
for callback, args, kwargs in self._callbacks: for callback, args, kwargs in self._callbacks:
callback(*args, **kwargs) callback(*args, **kwargs)
self._wasSet = True self._wasSet = not inherited
def context(self, value): def context(self, value):
"""Return a context manager object, which sets this variable to a """Return a context manager object, which sets this variable to a