diff --git a/etgtools/extractors.py b/etgtools/extractors.py index c0a3eced..dc84fa62 100644 --- a/etgtools/extractors.py +++ b/etgtools/extractors.py @@ -291,7 +291,7 @@ class FunctionDef(BaseDef, FixWxPrefix): self.transferThis = False # ownership of 'this' pointer transfered to C++ self.cppCode = None # Use this code instead of the default wrapper self.noArgParser = False # set the NoargParser annotation - self.mustHaveAppFlag = False + self.preMethodCode = None self.__dict__.update(kw) if element is not None: @@ -556,7 +556,11 @@ class FunctionDef(BaseDef, FixWxPrefix): def mustHaveApp(self, value=True): - self.mustHaveAppFlag = value + if value: + self.preMethodCode = "if (!wxPyCheckForApp()) return NULL;\n" + else: + self.preMethodCode = None + #--------------------------------------------------------------------------- @@ -679,7 +683,7 @@ class ClassDef(BaseDef): self.innerclasses = [] self.isInner = False # Is this a nested class? self.klass = None # if so, then this is the outer class - self.mustHaveAppFlag = False + self.preMethodCode = None # Stuff that needs to be generated after the class instead of within # it. Some back-end generators need to put stuff inside the class, and @@ -1133,7 +1137,10 @@ private: self.addItem(wig) def mustHaveApp(self, value=True): - self.mustHaveAppFlag = value + if value: + self.preMethodCode = "if (!wxPyCheckForApp()) return NULL;\n" + else: + self.preMethodCode = None def copyFromClass(self, klass, name): diff --git a/etgtools/sip_generator.py b/etgtools/sip_generator.py index f8c7ed94..d3ff60fc 100644 --- a/etgtools/sip_generator.py +++ b/etgtools/sip_generator.py @@ -194,9 +194,9 @@ from .%s import * # SIP appends them all together. _needDocstring = False - if function.mustHaveAppFlag: + if function.preMethodCode: stream.write('%PreMethodCode\n') - stream.write(nci("if (!wxPyCheckForApp()) return NULL;\n", 4)) + stream.write(nci(function.preMethodCode, 4)) stream.write('%End\n') if function.cppCode: @@ -426,11 +426,11 @@ from .%s import * if klass.ignored: return - # Propagate mustHaveApp setting to the ctors - if klass.mustHaveAppFlag: + # Propagate preMethodCode setting to the ctors + if klass.preMethodCode: for item in klass.allItems(): if isinstance(item, extractors.MethodDef) and item.isCtor: - item.mustHaveApp(True) + item.preMethodCode = klass.preMethodCode # write the class header if klass.templateParams: @@ -680,9 +680,9 @@ from .%s import * # SIP appends them all together. _needDocstring = False - if method.mustHaveAppFlag: + if method.preMethodCode: stream.write('%s%%PreMethodCode\n' % indent) - stream.write(nci("if (!wxPyCheckForApp()) return NULL;\n", len(indent)+4)) + stream.write(nci(method.preMethodCode, len(indent)+4)) stream.write('%s%%End\n' % indent) if method.cppCode: