Merge pull request #367 from RobinD42/hashable-treeitemid

Make TreeItemId hashable
This commit is contained in:
Robin Dunn
2017-05-18 11:48:25 -07:00
committed by GitHub
3 changed files with 20 additions and 1 deletions

View File

@@ -42,6 +42,18 @@ def run():
return self->IsOk();
""")
c.addCppMethod('bool', '__eq__', '(const wxTreeItemId* other)', """\
return *self == *other;
""")
c.addCppMethod('bool', '__neq__', '(const wxTreeItemId* other)', """\
return *self != *other;
""")
c.addPyMethod('__hash__', '(self)', """\
return hash(int(self.GetID()))
""")
td = etgtools.TypedefDef(name='wxTreeItemIdValue', type='void*')
module.insertItemBefore(c, td)

View File

@@ -14,7 +14,7 @@
%ModuleHeaderCode
#include <wx/treebase.h>
// A wxTreeItemData that knows what to do with PyObjects for maintianing the refcount
// A wxTreeItemData that knows what to do with PyObjects for maintaining the refcount
class wxPyTreeItemData : public wxPyUserDataHelper<wxTreeItemData>
{
public:

View File

@@ -28,6 +28,13 @@ class treectrl_Tests(wtc.WidgetTestCase):
self.assertTrue(child is not root)
self.assertTrue(child != root)
# Can TreeItemId be a dictionary key?
d = dict()
d[root] = 'root'
d[child] = 'child'
assert d[root] == 'root'
assert d[r] == 'root'
def test_treectrlTreeItemData(self):
value = 'Some Python Object'