From 71c7514593567435feb8bc5ad93f097c8ac94fc1 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Mon, 31 Aug 2020 15:32:19 -0700 Subject: [PATCH] Temporary workaround for the changes in the wxART IDs C++ implementation --- etg/artprov.py | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/etg/artprov.py b/etg/artprov.py index 83bc378b..657abe90 100644 --- a/etg/artprov.py +++ b/etg/artprov.py @@ -52,18 +52,36 @@ def run(): # deprecated and removed c.find('Insert').ignore() - # Change the types of the art constants from wxString to const char* - # since that is what they really are. + # TEMPORARY WORKAROUND: The following will likely not be needed after an update to the + # newest wxWidgets master... + # + # In C++ the art constants are actually macros that create a wxString on the fly, and + # that doesn't work in the generated wrapper code because it tries to take the address + # of the ID, but in reality it's a temporary object. So we'll create a new set of + # globals which are actual global variables. artConsts = list() + newConsts = list() + newConsts_cpp = list() for item in module: if isinstance(item, etgtools.GlobalVarDef): if item.type in ['wxArtClient', 'wxArtID']: - item.type = 'const char*' artConsts.append(item) - # move them to the front of the module + + # Make a new GlobalVarDef with the wx-less name as a wxString + name = old_name = item.name + name = name.replace('wx', '') + gvd = etgtools.GlobalVarDef(type=item.type, name=name) + newConsts.append(gvd) + + # add some c++ code to implement that new constant + newConsts_cpp.append('{} {}({});'.format(item.type, name, old_name)) + + # Now remove the old, add the new, and insert the c++ code for item in artConsts: module.items.remove(item) + for item in newConsts: module.items.insert(0, item) + module.addCppCode('\n'.join(newConsts_cpp)) #-----------------------------------------------------------------