mirror of
https://github.com/wxWidgets/Phoenix.git
synced 2026-01-05 11:30:06 +01:00
Add the ability to inject wxClassInfo macros into the sip generated wrapper classes.
Only needed for wxTreeCtrl so far.
This commit is contained in:
22
build.py
22
build.py
@@ -1109,6 +1109,7 @@ def cmd_sip(options, args):
|
||||
(sip, cfg.SIPOPTS, tmpdir, sbf, pycode, src_name)
|
||||
runcmd(cmd)
|
||||
|
||||
classesNeedingClassInfo = { 'sip_corewxTreeCtrl.cpp' : 'wxTreeCtrl', }
|
||||
|
||||
def processSrc(src, keepHashLines=False):
|
||||
with textfile_open(src, 'rt') as f:
|
||||
@@ -1120,8 +1121,29 @@ def cmd_sip(options, args):
|
||||
# ...or totally remove them by replacing those lines with ''
|
||||
import re
|
||||
srcTxt = re.sub(r'^#line.*\n', '', srcTxt, flags=re.MULTILINE)
|
||||
className = classesNeedingClassInfo.get(os.path.basename(src))
|
||||
if className:
|
||||
srcTxt = injectClassInfo(className, srcTxt)
|
||||
return srcTxt
|
||||
|
||||
def injectClassInfo(className, srcTxt):
|
||||
# inject wxClassInfo macros into the sip generated wrapper class
|
||||
lines = srcTxt.splitlines()
|
||||
# find the beginning of the class declaration
|
||||
for idx, line in enumerate(lines):
|
||||
if line.startswith('class sip{}'.format(className)):
|
||||
# next line is '{', insert after that
|
||||
lines[idx+2:idx+2] = ['wxDECLARE_ABSTRACT_CLASS(sip{});'.format(className)]
|
||||
break
|
||||
# find the '};' that terminates the class
|
||||
for idx, line in enumerate(lines[idx+2:], idx+2):
|
||||
if line.startswith('};'):
|
||||
lines[idx+1:idx+1] = ['\nwxIMPLEMENT_ABSTRACT_CLASS(sip{0}, {0});'.format(className)]
|
||||
break
|
||||
# join it back up and return
|
||||
return '\n'.join(lines)
|
||||
|
||||
|
||||
# Check each file in tmpdir to see if it is different than the same file
|
||||
# in cfg.SIPOUT. If so then copy the new one to cfg.SIPOUT, otherwise
|
||||
# ignore it.
|
||||
|
||||
Reference in New Issue
Block a user