Skip to content

Commit c7e58ac

Browse files
committed
Fix widget.disabled handling of value change of equal truthiness
Comparing for equality is too strict, when what we want is to know if thue value is Truthy or Falsy, this mismatch in condition created cases where a widget was set to disabled, but wasn't, as well as widgets staying disabled, when they should have been enabled again.
1 parent 76ab2aa commit c7e58ac

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

kivy/tests/test_widget.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,10 @@ def test_export_to_png(self):
118118
rmtree(tmp)
119119

120120
self.root.remove_widget(wid)
121+
122+
def test_disabled(self):
123+
from kivy.uix.widget import Widget
124+
w = Widget(disabled=None)
125+
w.disabled = False
126+
w.disabled = True
127+
self.assertEqual(w.disabled, True)

kivy/uix/widget.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1433,6 +1433,9 @@ def get_disabled(self):
14331433
return self._disabled_count > 0
14341434

14351435
def set_disabled(self, value):
1436+
# Necessary to ensure a change between value of equal truthiness
1437+
# doesn't mess up the count
1438+
value = bool(value)
14361439
if value != self._disabled_value:
14371440
self._disabled_value = value
14381441
if value:

0 commit comments

Comments
 (0)