From a8d8c7ed903c616953fa8a1386c844552f6e89ff Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Wed, 21 Mar 2018 19:36:03 -0700 Subject: [PATCH] Merge pull request #791 from ExplodingCabbage/fix-intctrl-none-handling Fix setting IntCtrl to None wrongly raising --- unittests/test_lib_intctrl.py | 7 +++++++ wx/lib/intctrl.py | 6 +++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/unittests/test_lib_intctrl.py b/unittests/test_lib_intctrl.py index 027101a6..34fba200 100644 --- a/unittests/test_lib_intctrl.py +++ b/unittests/test_lib_intctrl.py @@ -15,6 +15,13 @@ class IntCtrlTests(wtc.WidgetTestCase): t3.ChangeValue(16) self.assertTrue(not t3.IsInBounds()) + def test_canSetValueToNone(self): + t1 = IC.IntCtrl(self.frame, allow_none=True, value=None) + assert t1.GetValue() is None + t2 = IC.IntCtrl(self.frame, allow_none=True) + t2.SetValue(None) + assert t2.GetValue() is None + #--------------------------------------------------------------------------- diff --git a/wx/lib/intctrl.py b/wx/lib/intctrl.py index 51d44e0d..08633e1a 100644 --- a/wx/lib/intctrl.py +++ b/wx/lib/intctrl.py @@ -804,10 +804,10 @@ class IntCtrl(wx.TextCtrl): Colors text with oob_color if current value exceeds bounds set for control. """ - if not self.IsInBounds(value): - self.SetForegroundColour(self.__oob_color) - else: + if value is None or self.IsInBounds(value): self.SetForegroundColour(self.__default_color) + else: + self.SetForegroundColour(self.__oob_color) self.Refresh()