mirror of
https://github.com/wxWidgets/Phoenix.git
synced 2026-01-04 19:10:09 +01:00
Add comparison and hash operators to wx.WindowIDRef
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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]
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
|
||||
Reference in New Issue
Block a user