From 2bec8b8057891e5a903aa540c7c6bcdf40c94cdf Mon Sep 17 00:00:00 2001 From: Blade Doyle Date: Sun, 26 Jun 2022 19:30:04 -0700 Subject: [PATCH] Fix for FormControlCheckbox updateDependents (support multiple parents) --- npyscreen/wgFormControlCheckbox.py | 41 ++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/npyscreen/wgFormControlCheckbox.py b/npyscreen/wgFormControlCheckbox.py index 7575cdc..6e8df4b 100644 --- a/npyscreen/wgFormControlCheckbox.py +++ b/npyscreen/wgFormControlCheckbox.py @@ -33,26 +33,47 @@ def _register(self, w, vws=True): self.updateDependents() def updateDependents(self): - # This doesn't yet work. + # Support dependents with multiple FormControlCheckbox parents + # A dependent should be visible only when all parents agree if self.value: for w in self._visibleWhenSelected: - w.hidden = False - w.editable = True + try: + w.fc_visible + except AttributeError: + w.fc_visible = {} + w.fc_visible[self.name] = True for w in self._notVisibleWhenSelected: - w.hidden = True - w.editable = False + try: + w.fc_visible + except AttributeError: + w.fc_visible = {} + w.fc_visible[self.name] = False else: for w in self._visibleWhenSelected: - w.hidden = True - w.editable = False + try: + w.fc_visible + except AttributeError: + w.fc_visible = {} + w.fc_visible[self.name] = False for w in self._notVisibleWhenSelected: - w.hidden = False - w.editable = True + try: + w.fc_visible + except AttributeError: + w.fc_visible = {} + w.fc_visible[self.name] = True + for w in self._visibleWhenSelected + self._notVisibleWhenSelected: + w.hidden = False in w.fc_visible.values() + w.editable = not False in w.fc_visible.values() self.parent.display() def h_toggle(self, *args): super(FormControlCheckbox, self).h_toggle(*args) self.updateDependents() + def set_value(self, value): + self.value = value + self.display() - + def display(self): + self.updateDependents() + super()