From f9cd6bdb3cfa09e6b626a6a8d05fed81e09d8c0c Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Sat, 13 Apr 2019 13:56:16 -0700 Subject: [PATCH] Set wxVisualAttributes members as read-only (no setter) and make copies of the member objects in the getter --- etg/window.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/etg/window.py b/etg/window.py index a6b85e5e..7ee3e3b8 100644 --- a/etg/window.py +++ b/etg/window.py @@ -35,6 +35,29 @@ def run(): # Tweak the parsed meta objects in the module object as needed for # customizing the generated code and docstrings. + c = module.find('wxVisualAttributes') + assert isinstance(c, etgtools.ClassDef) + # Mark the stucture memebers as read-only, and make copies of the values + # when fetching them. This is to protect against cases where the + # VisualAttributes object is transient and may be GC'd while we still are + # using a reference to a C++ member value. + c.find('colBg').noSetter = True + c.find('colBg').getCode = """\ + wxColour* clr = new wxColour(sipCpp->colBg); + sipPy = wxPyConstructObject((void*)clr, "wxColour", true); + """ + c.find('colFg').noSetter = True + c.find('colFg').getCode = """\ + wxColour* clr = new wxColour(sipCpp->colFg); + sipPy = wxPyConstructObject((void*)clr, "wxColour", true); + """ + c.find('font').noSetter = True + c.find('font').getCode = """\ + wxFont* font = new wxFont(sipCpp->font); + sipPy = wxPyConstructObject((void*)font, "wxFont", true); + """ + + c = module.find('wxWindow') assert isinstance(c, etgtools.ClassDef) module.addGlobalStr('wxPanelNameStr', c)