diff --git a/etg/windowid.py b/etg/windowid.py index 1060ac1d..27b041b3 100644 --- a/etg/windowid.py +++ b/etg/windowid.py @@ -72,14 +72,22 @@ def run(): return self->GetValue(); """) - klass.addCppMethod('int', '__int__', '()', doc="Alias for GetValue allowing the IDRef to be passed as the WindowID parameter when creating widgets or etc.", body="""\ return self->GetValue(); """) + + klass.addCppMethod('bool', '__eq__', '(wxWindowID id)', "return self->GetValue() == id;") + klass.addCppMethod('bool', '__ne__', '(wxWindowID id)', "return self->GetValue() != id;") + klass.addCppMethod('bool', '__lt__', '(wxWindowID id)', "return self->GetValue() < id;") + klass.addCppMethod('bool', '__gt__', '(wxWindowID id)', "return self->GetValue() > id;") + klass.addCppMethod('bool', '__le__', '(wxWindowID id)', "return self->GetValue() <= id;") + klass.addCppMethod('bool', '__ge__', '(wxWindowID id)', "return self->GetValue() >= id;") klass.addPyMethod('__repr__', '(self)', 'return "WindowIDRef: {}".format(self.GetId())') + klass.addPyMethod('__hash__', '(self)', 'return hash(self.GetValue())') + # and finish it up by adding it to the module module.addItem(klass) diff --git a/unittests/test_windowid.py b/unittests/test_windowid.py index 02633495..4593e5a6 100644 --- a/unittests/test_windowid.py +++ b/unittests/test_windowid.py @@ -58,7 +58,29 @@ class IdManagerTest(wtc.WidgetTestCase): b.Destroy() + def test_WindowIDRef01(self): + ref1 = wx.WindowIDRef(wx.IdManager.ReserveId()) + ref2 = wx.WindowIDRef(wx.IdManager.ReserveId()) + val = ref1 == ref2 + assert type(val) == bool + val = ref1 != ref2 + assert type(val) == bool + val = ref1 > ref2 + assert type(val) == bool + val = ref1 < ref2 + assert type(val) == bool + val = ref1 >= ref2 + assert type(val) == bool + val = ref1 <= ref2 + assert type(val) == bool + + def test_WindowIDRef02(self): + d = {wx.NewIdRef(): 'one', + wx.NewIdRef(): 'two'} + keys = sorted(d.keys()) + for k in keys: + val = d[k] #---------------------------------------------------------------------------