mirror of
https://github.com/wxWidgets/Phoenix.git
synced 2026-01-09 05:20:08 +01:00
Add ability to use %PreMethodCode% for more than just the mustHaveApp check
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user