From 775d6da37a12ca7cbaadf2c3299dabb37533410a Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Mon, 13 Mar 2017 19:47:19 -0700 Subject: [PATCH] =?UTF-8?q?We=20can=E2=80=99t=20use=20the=20default=20SIP?= =?UTF-8?q?=20machinery=20got=20GetAttributes=20because=20wxPGAttributeSto?= =?UTF-8?q?rage=20doesn=E2=80=99t=20have=20a=20copy-ctor=20and=20the=20def?= =?UTF-8?q?ault=20copy=20ctor=20won=E2=80=99t=20IncRef=20the=20variant=20v?= =?UTF-8?q?alues=20and=20so=20crashes=20happen.=20=20Just=20do=20the=20con?= =?UTF-8?q?version=20directly=20here=20instead.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- etg/propgridproperty.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/etg/propgridproperty.py b/etg/propgridproperty.py index 23fa8c30..d7dc2b0e 100644 --- a/etg/propgridproperty.py +++ b/etg/propgridproperty.py @@ -55,7 +55,31 @@ def run(): c.find('StringToValue.variant').out = True c.find('IntToValue.variant').out = True - # TODO: Some other wxPGProperty methods should be pythonized a bit... + # SIP needs to be able to make a copy of the wxPGAttributeStorage value + # but the C++ class doesn't have a copy ctor and the default will cause it + # to lose references to the variants it contains, so let's just override + # the use of the MappedType and convert it to a Python dictionary here + # instead. + m = c.find('GetAttributes') + m.type = 'PyObject*' + m.setCppCode("""\ + const wxPGAttributeStorage& attrs = self->GetAttributes(); + wxPGAttributeStorage::const_iterator it = attrs.StartIteration(); + wxVariant v; + wxPyThreadBlocker blocker; + + PyObject* dict = PyDict_New(); + if ( !dict ) return NULL; + + while ( attrs.GetNext( it, v ) ) { + const wxString& name = v.GetName(); + PyObject* pyStr = wx2PyString(name); + PyObject* pyVal = wxPGVariant_out_helper(v); + int res = PyDict_SetItem( dict, pyStr, pyVal ); + } + return dict; + """) + c = module.find('wxPGChoicesData')