mirror of
https://github.com/wxWidgets/Phoenix.git
synced 2025-12-16 09:40:07 +01:00
Trim trailing space etgtools directory
This commit is contained in:
@@ -38,12 +38,12 @@ def parseDoxyXML(module, class_or_filename_list):
|
||||
"""
|
||||
Parse a list of Doxygen XML files and add the item(s) found there to the
|
||||
ModuleDef object.
|
||||
|
||||
|
||||
If a name in the list a wx class name then the Doxygen XML filename is
|
||||
calculated from that name, otherwise it is treated as a filename in the
|
||||
Doxygen XML output folder.
|
||||
"""
|
||||
|
||||
|
||||
def _classToDoxyName(name, attempts, base='class'):
|
||||
import string
|
||||
filename = base
|
||||
@@ -51,11 +51,11 @@ def parseDoxyXML(module, class_or_filename_list):
|
||||
if c in string.ascii_uppercase:
|
||||
filename += '_' + c.lower()
|
||||
else:
|
||||
filename += c
|
||||
filename += c
|
||||
filename = os.path.join(XMLSRC, filename) + '.xml'
|
||||
attempts.append(filename)
|
||||
return filename
|
||||
|
||||
|
||||
def _includeToDoxyName(name):
|
||||
name = os.path.basename(name)
|
||||
name = name.replace('.h', '_8h')
|
||||
@@ -65,7 +65,7 @@ def parseDoxyXML(module, class_or_filename_list):
|
||||
else:
|
||||
name = 'interface_2wx_2' + name
|
||||
return os.path.join(XMLSRC, name) + '.xml', name + '.xml'
|
||||
|
||||
|
||||
for class_or_filename in class_or_filename_list:
|
||||
attempts = []
|
||||
pathname = _classToDoxyName(class_or_filename, attempts)
|
||||
@@ -80,23 +80,23 @@ def parseDoxyXML(module, class_or_filename_list):
|
||||
print(msg)
|
||||
print("Tried: %s" % ('\n '.join(attempts)))
|
||||
raise DoxyXMLError(msg)
|
||||
|
||||
|
||||
if verbose():
|
||||
print("Loading %s..." % pathname)
|
||||
_filesparsed.add(pathname)
|
||||
|
||||
|
||||
root = et.parse(pathname).getroot()
|
||||
for element in root:
|
||||
# extract and add top-level elements from the XML document
|
||||
item = module.addElement(element)
|
||||
|
||||
|
||||
# Also automatically parse the XML for the include file to get related
|
||||
# typedefs, functions, enums, etc.
|
||||
# Make sure though, that for interface files we only parse the one
|
||||
# that belongs to this class. Otherwise, enums, etc. will be defined
|
||||
# in multiple places.
|
||||
xmlname = class_or_filename.replace('wx', '').lower()
|
||||
|
||||
|
||||
if hasattr(item, 'includes'):
|
||||
for inc in item.includes:
|
||||
pathname, name = _includeToDoxyName(inc)
|
||||
@@ -104,15 +104,15 @@ def parseDoxyXML(module, class_or_filename_list):
|
||||
and pathname not in _filesparsed \
|
||||
and ("interface" not in name or xmlname in name) \
|
||||
and name not in class_or_filename_list:
|
||||
class_or_filename_list.append(name)
|
||||
class_or_filename_list.append(name)
|
||||
|
||||
_filesparsed.clear()
|
||||
|
||||
|
||||
module.parseCompleted()
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -17,18 +17,18 @@ import sys
|
||||
|
||||
class WrapperGeneratorBase(object):
|
||||
def __init__(self):
|
||||
pass
|
||||
pass
|
||||
def generate(self, module, destFile=None):
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
|
||||
|
||||
class DocsGeneratorBase(object):
|
||||
def __init__(self):
|
||||
pass
|
||||
pass
|
||||
def generate(self, module):
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
|
||||
|
||||
class StubbedDocsGenerator(DocsGeneratorBase):
|
||||
def generate(self, module):
|
||||
pass
|
||||
@@ -44,7 +44,7 @@ class SphinxGenerator(DocsGeneratorBase):
|
||||
def nci(text, numSpaces=0, stripLeading=True):
|
||||
"""
|
||||
Normalize Code Indents
|
||||
|
||||
|
||||
First use the count of leading spaces on the first line and remove that
|
||||
many spaces from the front of all lines, and then indent each line by
|
||||
adding numSpaces spaces. This is used so we can convert the arbitrary
|
||||
@@ -59,20 +59,20 @@ def nci(text, numSpaces=0, stripLeading=True):
|
||||
break
|
||||
count += 1
|
||||
return count
|
||||
|
||||
|
||||
def _allSpaces(text):
|
||||
for c in text:
|
||||
if c != ' ':
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
|
||||
lines = text.rstrip().split('\n')
|
||||
if stripLeading:
|
||||
numStrip = _getLeadingSpaceCount(lines[0])
|
||||
else:
|
||||
numStrip = 0
|
||||
|
||||
|
||||
for idx, line in enumerate(lines):
|
||||
assert _allSpaces(line[:numStrip]), "Indentation inconsistent with first line"
|
||||
lines[idx] = ' '*numSpaces + line[numStrip:]
|
||||
@@ -102,8 +102,8 @@ class Utf8EncodingStream(io.StringIO):
|
||||
if isinstance(text, str):
|
||||
text = text.decode('utf-8')
|
||||
return io.StringIO.write(self, text)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def textfile_open(filename, mode='rt'):
|
||||
@@ -119,7 +119,7 @@ def textfile_open(filename, mode='rt'):
|
||||
return codecs.open(filename, mode, encoding='utf-8')
|
||||
else:
|
||||
return open(filename, mode, encoding='utf-8')
|
||||
|
||||
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ header_pi = """\
|
||||
# -*- coding: utf-8 -*-
|
||||
#---------------------------------------------------------------------------
|
||||
# This file is generated by wxPython's PI generator. Do not edit by hand.
|
||||
#
|
||||
#
|
||||
# The *.pi files are used by WingIDE to provide more information than it is
|
||||
# able to glean from introspection of extension types and methods. They are
|
||||
# not intended to be imported, executed or used for any other purpose other
|
||||
@@ -72,13 +72,13 @@ header_pyi = """\
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
class PiWrapperGenerator(generators.WrapperGeneratorBase, FixWxPrefix):
|
||||
|
||||
|
||||
def generate(self, module, destFile=None):
|
||||
stream = Utf8EncodingStream()
|
||||
|
||||
|
||||
# process the module object and its child objects
|
||||
self.generateModule(module, stream)
|
||||
|
||||
|
||||
# Write the contents of the stream to the destination file
|
||||
if not destFile:
|
||||
name = module.module
|
||||
@@ -115,14 +115,14 @@ class PiWrapperGenerator(generators.WrapperGeneratorBase, FixWxPrefix):
|
||||
sectionEndLine = -1
|
||||
sectionBeginMarker = '#-- begin-%s --#' % sectionName
|
||||
sectionEndMarker = '#-- end-%s --#' % sectionName
|
||||
|
||||
|
||||
lines = textfile_open(destFile, 'rt').readlines()
|
||||
for idx, line in enumerate(lines):
|
||||
if line.startswith(sectionBeginMarker):
|
||||
sectionBeginLine = idx
|
||||
if line.startswith(sectionEndMarker):
|
||||
sectionEndLine = idx
|
||||
|
||||
|
||||
if sectionBeginLine == -1:
|
||||
# not there already, add to the end
|
||||
lines.append(sectionBeginMarker + '\n')
|
||||
@@ -131,12 +131,12 @@ class PiWrapperGenerator(generators.WrapperGeneratorBase, FixWxPrefix):
|
||||
else:
|
||||
# replace the existing lines
|
||||
lines[sectionBeginLine+1:sectionEndLine] = [sectionText]
|
||||
|
||||
|
||||
f = textfile_open(destFile, 'wt')
|
||||
f.writelines(lines)
|
||||
f.close()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
def generateModule(self, module, stream):
|
||||
@@ -145,14 +145,14 @@ class PiWrapperGenerator(generators.WrapperGeneratorBase, FixWxPrefix):
|
||||
"""
|
||||
assert isinstance(module, extractors.ModuleDef)
|
||||
self.isCore = module.module == '_core'
|
||||
|
||||
|
||||
for item in module.imports:
|
||||
if item.startswith('_'):
|
||||
item = item[1:]
|
||||
if item == 'core':
|
||||
continue
|
||||
stream.write('import wx.%s\n' % item)
|
||||
|
||||
|
||||
# Move all PyCode items with an order value to the begining of the
|
||||
# list as they most likely should appear before everything else.
|
||||
pycode = list()
|
||||
@@ -162,7 +162,7 @@ class PiWrapperGenerator(generators.WrapperGeneratorBase, FixWxPrefix):
|
||||
for item in pycode:
|
||||
module.items.remove(item)
|
||||
module.items = pycode + module.items
|
||||
|
||||
|
||||
methodMap = {
|
||||
extractors.ClassDef : self.generateClass,
|
||||
extractors.DefineDef : self.generateDefine,
|
||||
@@ -173,18 +173,18 @@ class PiWrapperGenerator(generators.WrapperGeneratorBase, FixWxPrefix):
|
||||
extractors.WigCode : self.generateWigCode,
|
||||
extractors.PyCodeDef : self.generatePyCode,
|
||||
extractors.PyFunctionDef : self.generatePyFunction,
|
||||
extractors.PyClassDef : self.generatePyClass,
|
||||
extractors.PyClassDef : self.generatePyClass,
|
||||
extractors.CppMethodDef : self.generateCppMethod,
|
||||
extractors.CppMethodDef_sip : self.generateCppMethod_sip,
|
||||
}
|
||||
|
||||
|
||||
for item in module:
|
||||
if item.ignored:
|
||||
continue
|
||||
function = methodMap[item.__class__]
|
||||
function(item, stream)
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
def generateEnum(self, enum, stream, indent=''):
|
||||
assert isinstance(enum, extractors.EnumDef)
|
||||
@@ -193,9 +193,9 @@ class PiWrapperGenerator(generators.WrapperGeneratorBase, FixWxPrefix):
|
||||
for v in enum.items:
|
||||
if v.ignored:
|
||||
continue
|
||||
name = v.pyName or v.name
|
||||
name = v.pyName or v.name
|
||||
stream.write('%s%s = 0\n' % (indent, name))
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
def generateGlobalVar(self, globalVar, stream):
|
||||
assert isinstance(globalVar, extractors.GlobalVarDef)
|
||||
@@ -216,9 +216,9 @@ class PiWrapperGenerator(generators.WrapperGeneratorBase, FixWxPrefix):
|
||||
valTyp = valTyp.replace(' ', '')
|
||||
valTyp = self.fixWxPrefix(valTyp)
|
||||
valTyp += '()'
|
||||
|
||||
|
||||
stream.write('%s = %s\n' % (name, valTyp))
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
def generateDefine(self, define, stream):
|
||||
assert isinstance(define, extractors.DefineDef)
|
||||
@@ -229,7 +229,7 @@ class PiWrapperGenerator(generators.WrapperGeneratorBase, FixWxPrefix):
|
||||
stream.write('%s = ""\n' % (define.pyName or define.name))
|
||||
else:
|
||||
stream.write('%s = 0\n' % (define.pyName or define.name))
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
def generateTypedef(self, typedef, stream, indent=''):
|
||||
assert isinstance(typedef, extractors.TypedefDef)
|
||||
@@ -241,20 +241,20 @@ class PiWrapperGenerator(generators.WrapperGeneratorBase, FixWxPrefix):
|
||||
# ignore the typedef and return.
|
||||
if not ('<' in typedef.type and '>' in typedef.type) and not typedef.docAsClass:
|
||||
return
|
||||
|
||||
|
||||
# Otherwise write a mock class for it that combines the template and class.
|
||||
# First, extract the info we need.
|
||||
if typedef.docAsClass:
|
||||
bases = [self.fixWxPrefix(b, True) for b in typedef.bases]
|
||||
name = self.fixWxPrefix(typedef.name)
|
||||
|
||||
|
||||
elif '<' in typedef.type and '>' in typedef.type:
|
||||
t = typedef.type.replace('>', '')
|
||||
t = t.replace(' ', '')
|
||||
bases = t.split('<')
|
||||
bases = [self.fixWxPrefix(b, True) for b in bases]
|
||||
name = self.fixWxPrefix(typedef.name)
|
||||
|
||||
|
||||
# Now write the Python equivallent class for the typedef
|
||||
if not bases:
|
||||
bases = ['object'] # this should not happpen, but just in case...
|
||||
@@ -272,14 +272,14 @@ class PiWrapperGenerator(generators.WrapperGeneratorBase, FixWxPrefix):
|
||||
def generateWigCode(self, wig, stream, indent=''):
|
||||
assert isinstance(wig, extractors.WigCode)
|
||||
# write nothing for this one
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
def generatePyCode(self, pc, stream, indent=''):
|
||||
assert isinstance(pc, extractors.PyCodeDef)
|
||||
code = pc.code
|
||||
if hasattr(pc, 'klass'):
|
||||
code = code.replace(pc.klass.pyName+'.', '')
|
||||
code = code.replace(pc.klass.pyName+'.', '')
|
||||
stream.write('\n')
|
||||
stream.write(nci(code, len(indent)))
|
||||
|
||||
@@ -288,9 +288,9 @@ class PiWrapperGenerator(generators.WrapperGeneratorBase, FixWxPrefix):
|
||||
assert isinstance(pf, extractors.PyFunctionDef)
|
||||
stream.write('\n')
|
||||
if pf.deprecated:
|
||||
stream.write('%s@wx.deprecated\n' % indent)
|
||||
stream.write('%s@wx.deprecated\n' % indent)
|
||||
if pf.isStatic:
|
||||
stream.write('%s@staticmethod\n' % indent)
|
||||
stream.write('%s@staticmethod\n' % indent)
|
||||
stream.write('%sdef %s%s:\n' % (indent, pf.name, pf.argsString))
|
||||
indent2 = indent + ' '*4
|
||||
if pf.briefDoc:
|
||||
@@ -298,11 +298,11 @@ class PiWrapperGenerator(generators.WrapperGeneratorBase, FixWxPrefix):
|
||||
stream.write(nci(pf.briefDoc, len(indent2)))
|
||||
stream.write('%s"""\n' % indent2)
|
||||
stream.write('%spass\n' % indent2)
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
def generatePyClass(self, pc, stream, indent=''):
|
||||
assert isinstance(pc, extractors.PyClassDef)
|
||||
|
||||
|
||||
# write the class declaration and docstring
|
||||
if pc.deprecated:
|
||||
stream.write('%s@wx.deprecated\n' % indent)
|
||||
@@ -355,8 +355,8 @@ class PiWrapperGenerator(generators.WrapperGeneratorBase, FixWxPrefix):
|
||||
stream.write(' """\n')
|
||||
stream.write(nci(function.pyDocstring, 4))
|
||||
stream.write(' """\n')
|
||||
|
||||
|
||||
|
||||
|
||||
def generateParameters(self, parameters, stream, indent):
|
||||
def _lastParameter(idx):
|
||||
if idx == len(parameters)-1:
|
||||
@@ -365,7 +365,7 @@ class PiWrapperGenerator(generators.WrapperGeneratorBase, FixWxPrefix):
|
||||
if not parameters[i].ignored:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
for idx, param in enumerate(parameters):
|
||||
if param.ignored:
|
||||
continue
|
||||
@@ -374,25 +374,25 @@ class PiWrapperGenerator(generators.WrapperGeneratorBase, FixWxPrefix):
|
||||
stream.write('=%s' % param.default)
|
||||
if not _lastParameter(idx):
|
||||
stream.write(', ')
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
def generateClass(self, klass, stream, indent=''):
|
||||
assert isinstance(klass, extractors.ClassDef)
|
||||
if klass.ignored:
|
||||
return
|
||||
|
||||
|
||||
# check if there is a pi-customized version of the base class names
|
||||
if hasattr(klass, 'piBases'):
|
||||
bases = klass.piBases
|
||||
|
||||
|
||||
else:
|
||||
# check if it's a template with the template parameter as the base class
|
||||
bases = klass.bases[:]
|
||||
for tp in klass.templateParams:
|
||||
if tp in bases:
|
||||
bases.remove(tp)
|
||||
|
||||
|
||||
# write class declaration
|
||||
klassName = klass.pyName or klass.name
|
||||
stream.write('\n%sclass %s' % (indent, klassName))
|
||||
@@ -405,24 +405,24 @@ class PiWrapperGenerator(generators.WrapperGeneratorBase, FixWxPrefix):
|
||||
stream.write('(object)')
|
||||
stream.write(':\n')
|
||||
indent2 = indent + ' '*4
|
||||
|
||||
|
||||
# docstring
|
||||
stream.write('%s"""\n' % indent2)
|
||||
stream.write(nci(klass.pyDocstring, len(indent2)))
|
||||
stream.write('%s"""\n' % indent2)
|
||||
|
||||
|
||||
# generate nested classes
|
||||
for item in klass.innerclasses:
|
||||
self.generateClass(item, stream, indent2)
|
||||
|
||||
|
||||
# Split the items into public and protected groups
|
||||
enums = [i for i in klass if
|
||||
isinstance(i, extractors.EnumDef) and
|
||||
enums = [i for i in klass if
|
||||
isinstance(i, extractors.EnumDef) and
|
||||
i.protection == 'public']
|
||||
ctors = [i for i in klass if
|
||||
isinstance(i, extractors.MethodDef) and
|
||||
ctors = [i for i in klass if
|
||||
isinstance(i, extractors.MethodDef) and
|
||||
i.protection == 'public' and (i.isCtor or i.isDtor)]
|
||||
public = [i for i in klass if i.protection == 'public' and
|
||||
public = [i for i in klass if i.protection == 'public' and
|
||||
i not in ctors and i not in enums]
|
||||
protected = [i for i in klass if i.protection == 'protected']
|
||||
|
||||
@@ -444,25 +444,25 @@ class PiWrapperGenerator(generators.WrapperGeneratorBase, FixWxPrefix):
|
||||
item.klass = klass
|
||||
self.generateEnum(item, stream, indent2)
|
||||
|
||||
for item in ctors:
|
||||
for item in ctors:
|
||||
if item.isCtor:
|
||||
item.klass = klass
|
||||
self.generateMethod(item, stream, indent2,
|
||||
self.generateMethod(item, stream, indent2,
|
||||
name='__init__', docstring=klass.pyDocstring)
|
||||
|
||||
for item in public:
|
||||
item.klass = klass
|
||||
f = dispatch[item.__class__]
|
||||
f(item, stream, indent2)
|
||||
|
||||
|
||||
for item in protected:
|
||||
item.klass = klass
|
||||
f = dispatch[item.__class__]
|
||||
f(item, stream, indent2)
|
||||
|
||||
stream.write('%s# end of class %s\n\n' % (indent, klassName))
|
||||
|
||||
|
||||
|
||||
|
||||
def generateMemberVar(self, memberVar, stream, indent):
|
||||
assert isinstance(memberVar, extractors.MemberVarDef)
|
||||
if memberVar.ignored:
|
||||
@@ -494,7 +494,7 @@ class PiWrapperGenerator(generators.WrapperGeneratorBase, FixWxPrefix):
|
||||
return
|
||||
if method.isDtor:
|
||||
return
|
||||
|
||||
|
||||
name = name or method.pyName or method.name
|
||||
if name in magicMethods:
|
||||
name = magicMethods[name]
|
||||
@@ -527,7 +527,7 @@ class PiWrapperGenerator(generators.WrapperGeneratorBase, FixWxPrefix):
|
||||
stream.write(argsString)
|
||||
stream.write(':\n')
|
||||
indent2 = indent + ' '*4
|
||||
|
||||
|
||||
# docstring
|
||||
if not docstring:
|
||||
if hasattr(method, 'pyDocstring'):
|
||||
@@ -538,8 +538,8 @@ class PiWrapperGenerator(generators.WrapperGeneratorBase, FixWxPrefix):
|
||||
if docstring.strip():
|
||||
stream.write(nci(docstring, len(indent2)))
|
||||
stream.write('%s"""\n' % indent2)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def generateCppMethod(self, method, stream, indent=''):
|
||||
assert isinstance(method, extractors.CppMethodDef)
|
||||
@@ -549,7 +549,7 @@ class PiWrapperGenerator(generators.WrapperGeneratorBase, FixWxPrefix):
|
||||
def generateCppMethod_sip(self, method, stream, indent=''):
|
||||
assert isinstance(method, extractors.CppMethodDef_sip)
|
||||
self.generateMethod(method, stream, indent)
|
||||
|
||||
|
||||
|
||||
def generatePyMethod(self, pm, stream, indent):
|
||||
assert isinstance(pm, extractors.PyMethodDef)
|
||||
@@ -565,9 +565,9 @@ class PiWrapperGenerator(generators.WrapperGeneratorBase, FixWxPrefix):
|
||||
stream.write('%s"""\n' % indent2)
|
||||
stream.write(nci(pm.pyDocstring, len(indent2)))
|
||||
stream.write('%s"""\n' % indent2)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
@@ -32,27 +32,27 @@ class SipGeneratorError(RuntimeError):
|
||||
# This is a list of types that are used as return by value or by reference
|
||||
# function return types that we need to ensure are actually using pointer
|
||||
# types in their CppMethodDef or cppCode wrappers.
|
||||
forcePtrTypes = [ 'wxString',
|
||||
forcePtrTypes = [ 'wxString',
|
||||
]
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
class SipWrapperGenerator(generators.WrapperGeneratorBase):
|
||||
|
||||
|
||||
def generate(self, module, destFile=None):
|
||||
stream = Utf8EncodingStream()
|
||||
|
||||
|
||||
# generate SIP code from the module and its objects
|
||||
self.generateModule(module, stream)
|
||||
|
||||
|
||||
# Write the contents of the stream to the destination file
|
||||
if not destFile:
|
||||
destFile = os.path.join(phoenixRoot, 'sip/gen', module.name + '.sip')
|
||||
f = textfile_open(destFile, 'wt')
|
||||
f.write(stream.getvalue())
|
||||
f.close()
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
def generateModule(self, module, stream):
|
||||
assert isinstance(module, extractors.ModuleDef)
|
||||
@@ -60,15 +60,15 @@ class SipWrapperGenerator(generators.WrapperGeneratorBase):
|
||||
# write the file header
|
||||
stream.write(divider + """\
|
||||
// This file is generated by wxPython's SIP generator. Do not edit by hand.
|
||||
//
|
||||
//
|
||||
// Copyright: (c) 2011-2016 by Total Control Software
|
||||
// License: wxWindows License
|
||||
""")
|
||||
if module.name == module.module:
|
||||
stream.write("""
|
||||
%%Module( name=%s.%s,
|
||||
%%Module( name=%s.%s,
|
||||
keyword_arguments="All",
|
||||
use_argument_names=True,
|
||||
use_argument_names=True,
|
||||
all_raise_py_exception=True,
|
||||
language="C++")
|
||||
{
|
||||
@@ -91,7 +91,7 @@ class SipWrapperGenerator(generators.WrapperGeneratorBase):
|
||||
stream.write("""\
|
||||
%%Extract(id=pycode%s, order=5)
|
||||
# This file is generated by wxPython's SIP generator. Do not edit by hand.
|
||||
#
|
||||
#
|
||||
# Copyright: (c) 2011-2016 by Total Control Software
|
||||
# License: wxWindows License
|
||||
%s
|
||||
@@ -100,20 +100,20 @@ from .%s import *
|
||||
%%End
|
||||
|
||||
""" % ( module.name, doc, module.name))
|
||||
|
||||
|
||||
else:
|
||||
stream.write("//\n// This file will be included by %s.sip\n//\n" % module.module)
|
||||
|
||||
|
||||
stream.write(divider)
|
||||
|
||||
self.module_name = module.module
|
||||
# C++ code to be written to the module's header
|
||||
# C++ code to be written to the module's header
|
||||
if module.headerCode:
|
||||
stream.write("\n%ModuleHeaderCode\n")
|
||||
for c in module.headerCode:
|
||||
stream.write('%s\n' % c)
|
||||
stream.write("%End\n\n")
|
||||
|
||||
|
||||
# %Imports and %Includes
|
||||
if module.imports:
|
||||
for i in module.imports:
|
||||
@@ -123,7 +123,7 @@ from .%s import *
|
||||
for i in module.includes:
|
||||
stream.write("%%Include %s.sip\n" % i)
|
||||
stream.write("\n")
|
||||
|
||||
|
||||
# C++ code to be written out to the generated module
|
||||
if module.cppCode:
|
||||
stream.write("%ModuleCode\n")
|
||||
@@ -132,31 +132,31 @@ from .%s import *
|
||||
stream.write("%End\n")
|
||||
|
||||
stream.write('\n%s\n' % divider)
|
||||
|
||||
|
||||
# Now generate each of the items in the module
|
||||
self.generateModuleItems(module, stream)
|
||||
|
||||
|
||||
# Add code for the module initialization sections.
|
||||
if module.preInitializerCode:
|
||||
stream.write('\n%s\n\n%%PreInitialisationCode\n' % divider)
|
||||
for i in module.preInitializerCode:
|
||||
stream.write('%s\n' % i)
|
||||
stream.write('%End\n')
|
||||
stream.write('%End\n')
|
||||
if module.initializerCode:
|
||||
stream.write('\n%s\n\n%%InitialisationCode\n' % divider)
|
||||
for i in module.initializerCode:
|
||||
stream.write('%s\n' % i)
|
||||
stream.write('%End\n')
|
||||
stream.write('%End\n')
|
||||
if module.postInitializerCode:
|
||||
stream.write('\n%s\n\n%%PostInitialisationCode\n' % divider)
|
||||
for i in module.postInitializerCode:
|
||||
stream.write('%s\n' % i)
|
||||
stream.write('%End\n')
|
||||
|
||||
stream.write('%End\n')
|
||||
|
||||
stream.write('\n%s\n' % divider)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def generateModuleItems(self, module, stream):
|
||||
methodMap = {
|
||||
extractors.ClassDef : self.generateClass,
|
||||
@@ -172,14 +172,14 @@ from .%s import *
|
||||
extractors.CppMethodDef : self.generateCppMethod,
|
||||
extractors.CppMethodDef_sip : self.generateCppMethod_sip,
|
||||
}
|
||||
|
||||
|
||||
for item in module:
|
||||
if item.ignored:
|
||||
continue
|
||||
function = methodMap[item.__class__]
|
||||
function(item, stream)
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
def generateFunction(self, function, stream, _needDocstring=True):
|
||||
assert isinstance(function, extractors.FunctionDef)
|
||||
@@ -206,9 +206,9 @@ from .%s import *
|
||||
raise NotImplementedError() # TODO: See generateMethod for an example, refactor to share code...
|
||||
for f in function.overloads:
|
||||
self.generateFunction(f, stream, _needDocstring)
|
||||
stream.write('\n')
|
||||
stream.write('\n')
|
||||
|
||||
|
||||
|
||||
def generateParameters(self, parameters, stream, indent):
|
||||
def _lastParameter(idx):
|
||||
if idx == len(parameters)-1:
|
||||
@@ -217,7 +217,7 @@ from .%s import *
|
||||
if not parameters[i].ignored:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
for idx, param in enumerate(parameters):
|
||||
if param.ignored:
|
||||
continue
|
||||
@@ -229,8 +229,8 @@ from .%s import *
|
||||
if not _lastParameter(idx):
|
||||
stream.write(',')
|
||||
stream.write('\n')
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
def generateEnum(self, enum, stream, indent=''):
|
||||
assert isinstance(enum, extractors.EnumDef)
|
||||
@@ -247,8 +247,8 @@ from .%s import *
|
||||
values.append("%s %s%s" % (indent, v.name, self.annotate(v)))
|
||||
stream.write(',\n'.join(values))
|
||||
stream.write('%s\n%s};\n\n' % (indent, indent))
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
def generateGlobalVar(self, globalVar, stream):
|
||||
assert isinstance(globalVar, extractors.GlobalVarDef)
|
||||
@@ -257,14 +257,14 @@ from .%s import *
|
||||
|
||||
stream.write('%s %s' % (globalVar.type, globalVar.name))
|
||||
stream.write('%s;\n\n' % self.annotate(globalVar))
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
def generateDefine(self, define, stream):
|
||||
assert isinstance(define, extractors.DefineDef)
|
||||
if define.ignored:
|
||||
return
|
||||
# We're assuming that the #define is either an integer or a string value,
|
||||
# We're assuming that the #define is either an integer or a string value,
|
||||
# so tell sip that's what it is.
|
||||
if '"' in define.value:
|
||||
stream.write('const char* %s;\n' % define.name)
|
||||
@@ -274,14 +274,14 @@ from .%s import *
|
||||
stream.write('%PostInitialisationCode\n')
|
||||
#stream.write('printf("**** %s: %%d\\n", %s);\n' % (define.name, define.name))
|
||||
stream.write((' PyDict_SetItemString(sipModuleDict, "%s", '
|
||||
'wxPyInt_FromLong(static_cast<int>(%s)));\n') %
|
||||
'wxPyInt_FromLong(static_cast<int>(%s)));\n') %
|
||||
(define.pyName, define.name))
|
||||
stream.write('%End\n')
|
||||
stream.write('%End\n')
|
||||
|
||||
else:
|
||||
stream.write('const int %s;\n' % define.name)
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
def generateTypedef(self, typedef, stream, indent=''):
|
||||
assert isinstance(typedef, extractors.TypedefDef)
|
||||
@@ -289,15 +289,15 @@ from .%s import *
|
||||
return
|
||||
stream.write('%stypedef %s %s' % (indent, typedef.type, typedef.name))
|
||||
stream.write('%s;\n\n' % self.annotate(typedef))
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
def generateWigCode(self, wig, stream, indent=''):
|
||||
assert isinstance(wig, extractors.WigCode)
|
||||
stream.write(nci(wig.code, len(indent), False))
|
||||
stream.write('\n\n')
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
def generatePyCode(self, pc, stream, indent=''):
|
||||
assert isinstance(pc, extractors.PyCodeDef)
|
||||
@@ -314,7 +314,7 @@ from .%s import *
|
||||
|
||||
if len(indent) == 0:
|
||||
stream.write('\n%End\n\n')
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
def generatePyProperty(self, prop, stream, indent=''):
|
||||
assert isinstance(prop, extractors.PyPropertyDef)
|
||||
@@ -338,7 +338,7 @@ from .%s import *
|
||||
setter = prop.setter
|
||||
else:
|
||||
setter = '%s.%s' % (klassName, prop.setter)
|
||||
|
||||
|
||||
stream.write("%%Extract(id=pycode%s)\n" % self.module_name)
|
||||
stream.write("%s.%s = property(%s" % (klassName, prop.name, getter))
|
||||
if prop.setter:
|
||||
@@ -372,8 +372,8 @@ from .%s import *
|
||||
if len(indent) == 0:
|
||||
stream.write('\n%End\n')
|
||||
stream.write('\n')
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
def generatePyClass(self, pc, stream, indent=''):
|
||||
assert isinstance(pc, extractors.PyClassDef)
|
||||
@@ -411,18 +411,18 @@ from .%s import *
|
||||
item.klass = pc
|
||||
f = dispatch[item.__class__]
|
||||
f(item, stream, indent2)
|
||||
|
||||
|
||||
if len(indent) == 0:
|
||||
stream.write('\n%End\n')
|
||||
stream.write('\n')
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
def generateClass(self, klass, stream, indent=''):
|
||||
assert isinstance(klass, extractors.ClassDef)
|
||||
if klass.ignored:
|
||||
return
|
||||
|
||||
|
||||
# write the class header
|
||||
if klass.templateParams:
|
||||
stream.write('%stemplate<%s>\n' % (indent, ', '.join(klass.templateParams)))
|
||||
@@ -443,20 +443,20 @@ from .%s import *
|
||||
stream.write('%s #include <%s>\n' % (indent2, inc))
|
||||
stream.write('%s%%End\n\n' % indent2)
|
||||
|
||||
# C++ code to be written to the Type's header
|
||||
# C++ code to be written to the Type's header
|
||||
if klass.headerCode:
|
||||
stream.write("%s%%TypeHeaderCode\n" % indent2)
|
||||
for c in klass.headerCode:
|
||||
stream.write(nci(c, len(indent2)+4))
|
||||
stream.write("%s%%End\n" % indent2)
|
||||
|
||||
|
||||
# C++ code to be written out to the this Type's wrapper code module
|
||||
if klass.cppCode:
|
||||
stream.write("%s%%TypeCode\n" % indent2)
|
||||
for c in klass.cppCode:
|
||||
stream.write(nci(c, len(indent2)+4))
|
||||
stream.write("%s%%End\n" % indent2)
|
||||
|
||||
|
||||
# C++ code to create a new instance of this class
|
||||
if klass.instanceCode:
|
||||
stream.write("%s%%InstanceCode\n" % indent2)
|
||||
@@ -464,19 +464,19 @@ from .%s import *
|
||||
stream.write("%s%%End\n" % indent2)
|
||||
|
||||
# is the generator currently inside the class or after it?
|
||||
klass.generatingInClass = True
|
||||
klass.generatingInClass = True
|
||||
|
||||
# Split the items into public and protected groups
|
||||
ctors = [i for i in klass if
|
||||
isinstance(i, extractors.MethodDef) and
|
||||
ctors = [i for i in klass if
|
||||
isinstance(i, extractors.MethodDef) and
|
||||
i.protection == 'public' and (i.isCtor or i.isDtor)]
|
||||
enums = [i for i in klass if
|
||||
isinstance(i, extractors.EnumDef) and
|
||||
enums = [i for i in klass if
|
||||
isinstance(i, extractors.EnumDef) and
|
||||
i.protection == 'public']
|
||||
public = [i for i in klass if i.protection == 'public' and i not in ctors+enums]
|
||||
protected = [i for i in klass if i.protection == 'protected']
|
||||
private = [i for i in klass if i.protection == 'private']
|
||||
|
||||
|
||||
if klass.kind == 'class':
|
||||
stream.write('%spublic:\n' % indent)
|
||||
|
||||
@@ -484,18 +484,18 @@ from .%s import *
|
||||
# methods or in nested classes
|
||||
for item in enums:
|
||||
self.dispatchClassItem(klass, item, stream, indent2)
|
||||
|
||||
|
||||
# Next do inner classes
|
||||
for item in klass.innerclasses:
|
||||
if klass.kind == 'class':
|
||||
stream.write('%s%s:\n' % (indent, item.protection))
|
||||
item.klass = klass
|
||||
self.generateClass(item, stream, indent2)
|
||||
|
||||
|
||||
# and then the ctors and the rest of the items in the class
|
||||
for item in ctors:
|
||||
self.dispatchClassItem(klass, item, stream, indent2)
|
||||
|
||||
|
||||
for item in public:
|
||||
self.dispatchClassItem(klass, item, stream, indent2)
|
||||
|
||||
@@ -518,16 +518,16 @@ from .%s import *
|
||||
self.generateConvertCode('%ConvertFromTypeCode',
|
||||
klass.convertToPyObject,
|
||||
stream, indent + ' '*4)
|
||||
|
||||
|
||||
stream.write('%s}; // end of class %s\n\n\n' % (indent, klass.name))
|
||||
|
||||
|
||||
# Now generate anything that was deferred until after the class is finished
|
||||
klass.generatingInClass = False
|
||||
for item in klass.generateAfterClass:
|
||||
self.dispatchClassItem(klass, item, stream, indent)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def dispatchClassItem(self, klass, item, stream, indent):
|
||||
dispatch = {
|
||||
extractors.TypedefDef : self.generateTypedef,
|
||||
@@ -551,8 +551,8 @@ from .%s import *
|
||||
stream.write('%s%s\n' % (indent, kind))
|
||||
stream.write(nci(code, len(indent)+4))
|
||||
stream.write('%s%%End\n' % indent)
|
||||
|
||||
|
||||
|
||||
|
||||
def generateMemberVar(self, memberVar, stream, indent):
|
||||
assert isinstance(memberVar, extractors.MemberVarDef)
|
||||
if memberVar.ignored:
|
||||
@@ -560,7 +560,7 @@ from .%s import *
|
||||
stream.write('%s%s %s' % (indent, memberVar.type, memberVar.name))
|
||||
stream.write('%s;\n\n' % self.annotate(memberVar))
|
||||
|
||||
|
||||
|
||||
def generateProperty(self, prop, stream, indent):
|
||||
assert isinstance(prop, extractors.PropertyDef)
|
||||
if prop.ignored:
|
||||
@@ -572,18 +572,18 @@ from .%s import *
|
||||
if prop.briefDoc:
|
||||
stream.write(' // %s' % prop.briefDoc)
|
||||
stream.write('\n')
|
||||
|
||||
|
||||
|
||||
|
||||
def generateDocstring(self, item, stream, indent):
|
||||
item.pyDocstring = ""
|
||||
|
||||
|
||||
if item.name.startswith('operator'):
|
||||
return # Apparently sip doesn't like operators to have docstrings...
|
||||
|
||||
|
||||
# get the docstring text
|
||||
text = nci(extractors.flattenNode(item.briefDoc, False))
|
||||
text = wrapText(text)
|
||||
|
||||
text = wrapText(text)
|
||||
|
||||
|
||||
#if isinstance(item, extractors.ClassDef):
|
||||
# # append the function signatures for the class constructors (if any) to the class' docstring
|
||||
@@ -596,12 +596,12 @@ from .%s import *
|
||||
# pass
|
||||
#else:
|
||||
# # Prepend function signature string(s) for functions and methods
|
||||
# sigs = item.collectPySignatures()
|
||||
# sigs = item.collectPySignatures()
|
||||
# if sigs:
|
||||
# if text:
|
||||
# text = '\n\n' + text
|
||||
# text = '\n'.join(sigs) + text
|
||||
|
||||
|
||||
sigs = None
|
||||
if isinstance(item, extractors.ClassDef):
|
||||
try:
|
||||
@@ -610,12 +610,12 @@ from .%s import *
|
||||
except extractors.ExtractorError:
|
||||
pass
|
||||
else:
|
||||
sigs = item.collectPySignatures()
|
||||
sigs = item.collectPySignatures()
|
||||
if sigs:
|
||||
if text:
|
||||
text = '\n\n' + text
|
||||
text = '\n'.join(sigs) + text
|
||||
|
||||
|
||||
# write the docstring directive and the text
|
||||
stream.write('%s%%Docstring\n' % indent)
|
||||
stream.write(nci(text, len(indent)+4))
|
||||
@@ -625,7 +625,7 @@ from .%s import *
|
||||
# generators later on
|
||||
item.pyDocstring = nci(text)
|
||||
|
||||
|
||||
|
||||
def generateMethod(self, method, stream, indent):
|
||||
assert isinstance(method, extractors.MethodDef)
|
||||
_needDocstring = getattr(method, '_needDocstring', True)
|
||||
@@ -648,17 +648,17 @@ from .%s import *
|
||||
stream.write(' const')
|
||||
if method.isPureVirtual:
|
||||
stream.write(' = 0')
|
||||
cppSig = " [ %s ]" % method.cppSignature if method.cppSignature else ""
|
||||
cppSig = " [ %s ]" % method.cppSignature if method.cppSignature else ""
|
||||
if cppSig:
|
||||
stream.write(cppSig)
|
||||
stream.write('%s;\n' % self.annotate(method))
|
||||
|
||||
|
||||
if _needDocstring and not (method.isCtor or method.isDtor):
|
||||
self.generateDocstring(method, stream, indent)
|
||||
# We only write a docstring for the first overload, otherwise
|
||||
# SIP appends them all together.
|
||||
_needDocstring = False
|
||||
|
||||
|
||||
if method.cppCode:
|
||||
#checkOverloads = False ## SIP now allows overloads to have %MethodCode
|
||||
code, codeType = method.cppCode
|
||||
@@ -674,25 +674,25 @@ from .%s import *
|
||||
# and virtual catcher code, so we can just return from
|
||||
# here.
|
||||
return
|
||||
|
||||
|
||||
if method.virtualCatcherCode:
|
||||
stream.write('%s%%VirtualCatcherCode\n' % indent)
|
||||
stream.write(nci(method.virtualCatcherCode, len(indent)+4))
|
||||
stream.write('%s%%End\n' % indent)
|
||||
|
||||
|
||||
stream.write('\n')
|
||||
|
||||
|
||||
if checkOverloads and method.overloads:
|
||||
for m in method.overloads:
|
||||
m._needDocstring = _needDocstring
|
||||
self.dispatchClassItem(method.klass, m, stream, indent)
|
||||
|
||||
|
||||
|
||||
def generateCppMethod(self, method, stream, indent='', skipDeclaration=False):
|
||||
# Add a new C++ method to a class. This one adds the code as a
|
||||
# separate function and then adds a call to that function in the
|
||||
# MethodCode directive.
|
||||
|
||||
|
||||
def _removeIgnoredParams(argsString, paramList):
|
||||
# if there are ignored parameters adjust the argsString to match
|
||||
lastP = argsString.rfind(')')
|
||||
@@ -702,7 +702,7 @@ from .%s import *
|
||||
args[idx] = ''
|
||||
args = [a for a in args if a != '']
|
||||
return '(' + ', '.join(args) + ')'
|
||||
|
||||
|
||||
assert isinstance(method, extractors.CppMethodDef)
|
||||
if method.ignored:
|
||||
return
|
||||
@@ -713,40 +713,40 @@ from .%s import *
|
||||
pnames = argsString[:lastP].strip('()').split(',')
|
||||
for idx, pn in enumerate(pnames):
|
||||
# take only the part before the =, if there is one
|
||||
name = pn.split('=')[0].strip()
|
||||
name = pn.split('=')[0].strip()
|
||||
# remove annotations
|
||||
name = re.sub('/[A-Za-z]*/', '', name)
|
||||
name = re.sub('/[A-Za-z]*/', '', name)
|
||||
name = name.strip()
|
||||
# now get just the part after any space, * or &, which should be
|
||||
# the parameter name
|
||||
name = re.split(r'[ \*\&]+', name)[-1]
|
||||
name = re.split(r'[ \*\&]+', name)[-1]
|
||||
pnames[idx] = name
|
||||
pnames = ', '.join(pnames)
|
||||
typ = method.type
|
||||
|
||||
if not skipDeclaration:
|
||||
cppSig = " [ %s ]" % method.cppSignature if method.cppSignature else ""
|
||||
cppSig = " [ %s ]" % method.cppSignature if method.cppSignature else ""
|
||||
# First insert the method declaration
|
||||
if method.isCtor or method.isDtor:
|
||||
virtual = 'virtual ' if method.isVirtual else ''
|
||||
stream.write('%s%s%s%s%s%s;\n' %
|
||||
stream.write('%s%s%s%s%s%s;\n' %
|
||||
(indent, virtual, method.name, argsString, self.annotate(method), cppSig))
|
||||
else:
|
||||
constMod = " const" if method.isConst else ""
|
||||
static = "static " if method.isStatic else ""
|
||||
virtual = "virtual " if method.isVirtual else ""
|
||||
virtual = "virtual " if method.isVirtual else ""
|
||||
pure = " = 0" if method.isPureVirtual else ""
|
||||
stream.write('%s%s%s%s %s%s%s%s%s%s;\n' %
|
||||
(indent, static, virtual, typ,
|
||||
stream.write('%s%s%s%s %s%s%s%s%s%s;\n' %
|
||||
(indent, static, virtual, typ,
|
||||
method.name, argsString, constMod, pure, self.annotate(method), cppSig))
|
||||
|
||||
|
||||
# write the docstring
|
||||
if _needDocstring and not (method.isCtor or method.isDtor):
|
||||
self.generateDocstring(method, stream, indent)
|
||||
# We only write a docstring for the first overload, otherwise
|
||||
# SIP appends them all together.
|
||||
_needDocstring = False
|
||||
|
||||
|
||||
klass = method.klass
|
||||
if klass:
|
||||
assert isinstance(klass, extractors.ClassDef)
|
||||
@@ -757,7 +757,7 @@ from .%s import *
|
||||
fargs = argsString[:lastP].strip('()').split(',')
|
||||
for idx, arg in enumerate(fargs):
|
||||
# take only the part before the =, if there is one
|
||||
arg = arg.split('=')[0].strip()
|
||||
arg = arg.split('=')[0].strip()
|
||||
arg = arg.replace('&', '*') # SIP will always want to use pointers for parameters
|
||||
arg = re.sub('/[A-Za-z]*/', '', arg) # remove annotations
|
||||
fargs[idx] = arg
|
||||
@@ -774,7 +774,7 @@ from .%s import *
|
||||
fstream.write(nci(method.body, len(indent)+4))
|
||||
fstream.write('%s}\n' % indent)
|
||||
fstream.write('%s%%End\n' % indent)
|
||||
|
||||
|
||||
elif method.isDtor:
|
||||
fname = '_%s_dtor' % klass.name
|
||||
fargs = '(%s* self)' % klass.name
|
||||
@@ -783,7 +783,7 @@ from .%s import *
|
||||
fstream.write(nci(method.body, len(indent)+4))
|
||||
fstream.write('%s}\n' % indent)
|
||||
fstream.write('%s%%End\n' % indent)
|
||||
|
||||
|
||||
else:
|
||||
if klass:
|
||||
fname = '_%s_%s' % (klass.name, method.name)
|
||||
@@ -803,7 +803,7 @@ from .%s import *
|
||||
fname = '_%s_function' % method.name
|
||||
fargs = '(%s)' % fargs
|
||||
fstream.write('%s%%ModuleCode\n' % indent)
|
||||
|
||||
|
||||
# If the return type is in the forcePtrTypes list then make sure
|
||||
# that it is a pointer, not a return by value or reference, since
|
||||
# SIP almost always deals with pointers to newly allocated
|
||||
@@ -814,7 +814,7 @@ from .%s import *
|
||||
typPtr.replace('&', '*')
|
||||
elif '*' not in typPtr:
|
||||
typPtr += '*'
|
||||
|
||||
|
||||
fstream.write('%s%s %s%s\n%s{\n' % (indent, typPtr, fname, fargs, indent))
|
||||
fstream.write(nci(method.body, len(indent)+4))
|
||||
fstream.write('%s}\n' % indent)
|
||||
@@ -827,14 +827,14 @@ from .%s import *
|
||||
# _THREAD macros are intentionally not used in this case
|
||||
stream.write('PyErr_Clear();\n')
|
||||
stream.write('%ssipCpp = %s(%s);\n' % (indent+' '*4, fname, pnames))
|
||||
|
||||
|
||||
elif method.isDtor:
|
||||
stream.write('PyErr_Clear();\n')
|
||||
stream.write('%sPy_BEGIN_ALLOW_THREADS\n' % (indent+' '*4))
|
||||
stream.write(indent+' '*4)
|
||||
stream.write('%s(sipCpp);\n' % fname)
|
||||
stream.write('%sPy_END_ALLOW_THREADS\n' % (indent+' '*4))
|
||||
|
||||
stream.write('%sPy_END_ALLOW_THREADS\n' % (indent+' '*4))
|
||||
|
||||
else:
|
||||
stream.write('PyErr_Clear();\n')
|
||||
stream.write('%sPy_BEGIN_ALLOW_THREADS\n' % (indent+' '*4))
|
||||
@@ -852,7 +852,7 @@ from .%s import *
|
||||
stream.write('%s(sipCpp%s);\n' % (fname, pnames))
|
||||
else:
|
||||
stream.write('%s(%s);\n' % (fname, pnames))
|
||||
stream.write('%sPy_END_ALLOW_THREADS\n' % (indent+' '*4))
|
||||
stream.write('%sPy_END_ALLOW_THREADS\n' % (indent+' '*4))
|
||||
stream.write('%sif (PyErr_Occurred()) sipIsErr = 1;\n' % (indent+' '*4))
|
||||
stream.write('%s%%End\n' % indent)
|
||||
|
||||
@@ -860,7 +860,7 @@ from .%s import *
|
||||
stream.write('%s%%VirtualCatcherCode\n' % indent)
|
||||
stream.write(nci(method.virtualCatcherCode, len(indent)+4))
|
||||
stream.write('%s%%End\n' % indent)
|
||||
|
||||
|
||||
# and finally, add the new function itself
|
||||
stream.write(fstream.getvalue())
|
||||
stream.write('\n')
|
||||
@@ -869,29 +869,29 @@ from .%s import *
|
||||
for m in method.overloads:
|
||||
m._needDocstring = _needDocstring
|
||||
self.dispatchClassItem(method.klass, m, stream, indent)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def generateCppMethod_sip(self, method, stream, indent=''):
|
||||
# Add a new C++ method to a class without the extra generated
|
||||
# function, so SIP specific stuff can be done in the function body.
|
||||
assert isinstance(method, extractors.CppMethodDef_sip)
|
||||
if method.ignored:
|
||||
return
|
||||
cppSig = " [ %s ]" % method.cppSignature if method.cppSignature else ""
|
||||
cppSig = " [ %s ]" % method.cppSignature if method.cppSignature else ""
|
||||
if method.isCtor:
|
||||
stream.write('%s%s%s%s%s;\n' %
|
||||
stream.write('%s%s%s%s%s;\n' %
|
||||
(indent, method.name, method.argsString, self.annotate(method), cppSig))
|
||||
else:
|
||||
stream.write('%s%s %s%s%s%s;\n' %
|
||||
(indent, method.type, method.name, method.argsString,
|
||||
stream.write('%s%s %s%s%s%s;\n' %
|
||||
(indent, method.type, method.name, method.argsString,
|
||||
self.annotate(method), cppSig))
|
||||
stream.write('%s%%MethodCode\n' % indent)
|
||||
stream.write(nci(method.body, len(indent)+4))
|
||||
stream.write('%s%%End\n\n' % indent)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def generatePyMethod(self, pm, stream, indent):
|
||||
assert isinstance(pm, extractors.PyMethodDef)
|
||||
if pm.ignored:
|
||||
@@ -943,7 +943,7 @@ from .%s import *
|
||||
annotations.append('ArraySize')
|
||||
if item.keepReference:
|
||||
annotations.append('KeepReference')
|
||||
|
||||
|
||||
if isinstance(item, (extractors.ParamDef, extractors.FunctionDef)):
|
||||
if item.transfer:
|
||||
annotations.append('Transfer')
|
||||
@@ -953,7 +953,7 @@ from .%s import *
|
||||
annotations.append('TransferThis')
|
||||
if item.pyInt:
|
||||
annotations.append('PyInt')
|
||||
|
||||
|
||||
if isinstance(item, extractors.VariableDef):
|
||||
if item.pyInt:
|
||||
annotations.append('PyInt')
|
||||
@@ -967,21 +967,21 @@ from .%s import *
|
||||
annotations.append('Deprecated')
|
||||
if item.factory:
|
||||
annotations.append('Factory')
|
||||
if item.pyReleaseGIL:
|
||||
if item.pyReleaseGIL:
|
||||
annotations.append('ReleaseGIL')
|
||||
if item.pyHoldGIL:
|
||||
if item.pyHoldGIL:
|
||||
annotations.append('HoldGIL')
|
||||
if item.noCopy:
|
||||
annotations.append('NoCopy')
|
||||
if item.noArgParser:
|
||||
annotations.append('NoArgParser')
|
||||
|
||||
|
||||
if isinstance(item, extractors.MethodDef):
|
||||
if item.defaultCtor:
|
||||
annotations.append('Default')
|
||||
if item.noDerivedCtor:
|
||||
annotations.append('NoDerived')
|
||||
|
||||
|
||||
if isinstance(item, extractors.ClassDef):
|
||||
if item.abstract:
|
||||
annotations.append('Abstract')
|
||||
@@ -995,7 +995,7 @@ from .%s import *
|
||||
annotations.append('NoDefaultCtors')
|
||||
if item.singlton:
|
||||
annotations.append('DelayDtor')
|
||||
|
||||
|
||||
if annotations:
|
||||
return ' /%s/' % ', '.join(annotations)
|
||||
else:
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -54,7 +54,7 @@ def removeWxPrefixes(node):
|
||||
if item.name.startswith('wxEVT_') and 'CATEGORY' not in item.name:
|
||||
# give these their actual name so the auto-renamer won't touch them
|
||||
item.pyName = item.name
|
||||
|
||||
|
||||
|
||||
def removeWxPrefix(name):
|
||||
"""
|
||||
@@ -62,13 +62,13 @@ def removeWxPrefix(name):
|
||||
"""
|
||||
if name.startswith('wx.') or name.startswith('``wx.'):
|
||||
return name
|
||||
|
||||
|
||||
if name.startswith('wx') and not name.startswith('wxEVT_'):
|
||||
name = name[2:]
|
||||
|
||||
|
||||
if name.startswith('``wx') and not name.startswith('``wxEVT_'):
|
||||
name = name[0:2] + name[4:]
|
||||
|
||||
|
||||
return name
|
||||
|
||||
|
||||
@@ -78,25 +78,25 @@ class FixWxPrefix(object):
|
||||
A mixin class that can help with removing the wx prefix, or changing it
|
||||
in to a "wx.Name" depending on where it is being used from.
|
||||
"""
|
||||
|
||||
|
||||
_coreTopLevelNames = None
|
||||
|
||||
|
||||
def fixWxPrefix(self, name, checkIsCore=False):
|
||||
# By default remove the wx prefix like normal
|
||||
name = removeWxPrefix(name)
|
||||
if not checkIsCore or self.isCore:
|
||||
return name
|
||||
|
||||
|
||||
# Otherwise, if we're not processing the core module currently then check
|
||||
# if the name is local or if it resides in core. If it does then return
|
||||
# the name as 'wx.Name'
|
||||
if FixWxPrefix._coreTopLevelNames is None:
|
||||
self._getCoreTopLevelNames()
|
||||
|
||||
|
||||
testName = name
|
||||
if '(' in name:
|
||||
testName = name[:name.find('(')]
|
||||
|
||||
|
||||
if testName in FixWxPrefix._coreTopLevelNames:
|
||||
return 'wx.'+name
|
||||
else:
|
||||
@@ -119,7 +119,7 @@ class FixWxPrefix(object):
|
||||
names.append(item.name)
|
||||
elif isinstance(item, ast.FunctionDef):
|
||||
names.append(item.name)
|
||||
|
||||
|
||||
names = list()
|
||||
filename = 'wx/core.pi'
|
||||
if PY3:
|
||||
@@ -133,8 +133,8 @@ class FixWxPrefix(object):
|
||||
_processItem(item, names)
|
||||
|
||||
FixWxPrefix._coreTopLevelNames = names
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def ignoreAssignmentOperators(node):
|
||||
@@ -145,7 +145,7 @@ def ignoreAssignmentOperators(node):
|
||||
if isinstance(item, extractors.MethodDef) and item.name == 'operator=':
|
||||
item.ignore()
|
||||
|
||||
|
||||
|
||||
def ignoreAllOperators(node):
|
||||
"""
|
||||
Set the ignored flag for all class methods that are any kind of operator
|
||||
@@ -170,7 +170,7 @@ def ignoreConstOverloads(node):
|
||||
item2 = overloads[j]
|
||||
if item1.ignored or item2.ignored:
|
||||
continue
|
||||
if (item1.argsString.replace(' const', '').strip() ==
|
||||
if (item1.argsString.replace(' const', '').strip() ==
|
||||
item2.argsString.replace(' const', '').strip()):
|
||||
if item1.isConst:
|
||||
item1.ignore()
|
||||
@@ -178,13 +178,13 @@ def ignoreConstOverloads(node):
|
||||
elif item2.isConst:
|
||||
item2.ignore()
|
||||
return
|
||||
|
||||
|
||||
for item in node.items:
|
||||
if isinstance(item, extractors.MethodDef) and item.overloads:
|
||||
_checkOverloads(item)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def addAutoProperties(node):
|
||||
"""
|
||||
Call klass.addAutoProperties for all classes in node with
|
||||
@@ -199,7 +199,7 @@ def addAutoProperties(node):
|
||||
continue
|
||||
item.addAutoProperties()
|
||||
|
||||
|
||||
|
||||
def fixEventClass(klass, ignoreProtected=True):
|
||||
"""
|
||||
Add the extra stuff that an event class needs that are lacking from the
|
||||
@@ -223,9 +223,9 @@ def fixEventClass(klass, ignoreProtected=True):
|
||||
for item in klass.allItems():
|
||||
if isinstance(item, extractors.MethodDef) and item.protection == 'protected':
|
||||
item.ignore(False)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def fixWindowClass(klass, hideVirtuals=True, ignoreProtected=True):
|
||||
"""
|
||||
Do common tweaks for a window class.
|
||||
@@ -267,7 +267,7 @@ def fixWindowClass(klass, hideVirtuals=True, ignoreProtected=True):
|
||||
|
||||
def fixTopLevelWindowClass(klass, hideVirtuals=True, ignoreProtected=True):
|
||||
"""
|
||||
Tweaks for TLWs
|
||||
Tweaks for TLWs
|
||||
"""
|
||||
# TLW tweaks are a little different. We use the function annotation for
|
||||
# TransferThis instead of the argument annotation.
|
||||
@@ -306,17 +306,17 @@ def fixSizerClass(klass):
|
||||
removeVirtuals(klass)
|
||||
klass.find('CalcMin').isVirtual = True
|
||||
klass.find('RecalcSizes').isVirtual = True
|
||||
|
||||
|
||||
# in the wxSizer class they are pure-virtual
|
||||
if klass.name == 'wxSizer':
|
||||
klass.find('CalcMin').isPureVirtual = True
|
||||
klass.find('RecalcSizes').isPureVirtual = True
|
||||
|
||||
|
||||
|
||||
|
||||
def fixBookctrlClass(klass, treeBook=False):
|
||||
"""
|
||||
Add declarations of the pure virtual methods from the base class.
|
||||
"""
|
||||
"""
|
||||
klass.addItem(extractors.WigCode("""\
|
||||
virtual int GetPageImage(size_t nPage) const;
|
||||
virtual bool SetPageImage(size_t page, int image);
|
||||
@@ -332,7 +332,7 @@ def fixBookctrlClass(klass, treeBook=False):
|
||||
bool select = false, int imageId = NO_IMAGE);
|
||||
"""))
|
||||
|
||||
|
||||
|
||||
def fixHtmlSetFonts(klass):
|
||||
# Use wxArrayInt instead of a C array of ints.
|
||||
m = klass.find('SetFonts')
|
||||
@@ -373,13 +373,13 @@ def removeVirtuals(klass):
|
||||
if isinstance(item, extractors.MethodDef):
|
||||
item.isVirtual = item.isPureVirtual = False
|
||||
|
||||
|
||||
|
||||
def addWindowVirtuals(klass):
|
||||
"""
|
||||
Either turn the virtual flag back on or add a declaration for the subset of
|
||||
the C++ virtuals in wxWindow classes that we will be supporting.
|
||||
"""
|
||||
publicWindowVirtuals = [
|
||||
publicWindowVirtuals = [
|
||||
('GetClientAreaOrigin', 'wxPoint GetClientAreaOrigin() const'),
|
||||
('Validate', 'bool Validate()'),
|
||||
('TransferDataToWindow', 'bool TransferDataToWindow()'),
|
||||
@@ -393,19 +393,19 @@ def addWindowVirtuals(klass):
|
||||
('InheritAttributes', 'void InheritAttributes()'),
|
||||
('ShouldInheritColours', 'bool ShouldInheritColours() const'),
|
||||
('OnInternalIdle', 'void OnInternalIdle()'),
|
||||
('GetMainWindowOfCompositeControl',
|
||||
('GetMainWindowOfCompositeControl',
|
||||
'wxWindow *GetMainWindowOfCompositeControl()'),
|
||||
('InformFirstDirection', 'bool InformFirstDirection(int direction, int size, int availableOtherDir)'),
|
||||
('SetCanFocus', 'void SetCanFocus(bool canFocus)'),
|
||||
('Destroy', 'bool Destroy()'),
|
||||
|
||||
## What about these?
|
||||
#bool HasMultiplePages() const
|
||||
#bool HasMultiplePages() const
|
||||
#void UpdateWindowUI(long flags = wxUPDATE_UI_NONE);
|
||||
#void DoUpdateWindowUI(wxUpdateUIEvent& event) ;
|
||||
]
|
||||
|
||||
protectedWindowVirtuals = [
|
||||
|
||||
protectedWindowVirtuals = [
|
||||
('ProcessEvent', 'bool ProcessEvent(wxEvent & event)'),
|
||||
('DoEnable', 'void DoEnable(bool enable)'),
|
||||
('DoGetPosition', 'void DoGetPosition(int *x, int *y) const'),
|
||||
@@ -432,7 +432,7 @@ def addWindowVirtuals(klass):
|
||||
#('DoSetVirtualSize', 'void DoSetVirtualSize( int x, int y )'),
|
||||
#('DoGetVirtualSize', 'wxSize DoGetVirtualSize() const'),
|
||||
]
|
||||
|
||||
|
||||
def _processItems(klass, prot, virtuals):
|
||||
txt = ''
|
||||
for name, decl in virtuals:
|
||||
@@ -445,14 +445,14 @@ def addWindowVirtuals(klass):
|
||||
if txt:
|
||||
txt = prot + txt
|
||||
return txt
|
||||
|
||||
|
||||
txt = _processItems(klass, 'public:\n', publicWindowVirtuals)
|
||||
klass.addItem(extractors.WigCode(txt))
|
||||
txt = _processItems(klass, 'protected:\n', protectedWindowVirtuals)
|
||||
klass.addItem(extractors.WigCode(txt))
|
||||
klass.addPublic()
|
||||
|
||||
|
||||
|
||||
|
||||
def addSipConvertToSubClassCode(klass):
|
||||
"""
|
||||
Teach SIP how to convert to specific subclass types
|
||||
@@ -467,14 +467,14 @@ def addSipConvertToSubClassCode(klass):
|
||||
name = info->GetClassName();
|
||||
exists = sipFindType(name) != NULL;
|
||||
}
|
||||
if (info)
|
||||
if (info)
|
||||
sipType = sipFindType(name);
|
||||
else
|
||||
sipType = NULL;
|
||||
%End
|
||||
"""))
|
||||
|
||||
|
||||
|
||||
|
||||
def getEtgFiles(names):
|
||||
"""
|
||||
Create a list of the files from the basenames in the names list that
|
||||
@@ -490,7 +490,7 @@ def getNonEtgFiles(names, template='src/%s.sip'):
|
||||
"""
|
||||
return getMatchingFiles(names, template)
|
||||
|
||||
|
||||
|
||||
def getMatchingFiles(names, template):
|
||||
"""
|
||||
Create a list of files from the basenames in names that match the template
|
||||
@@ -502,9 +502,9 @@ def getMatchingFiles(names, template):
|
||||
if os.path.exists(name):
|
||||
files.append(name)
|
||||
return files
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def doCommonTweaks(module):
|
||||
"""
|
||||
A collection of tweaks that should probably be done to all modules.
|
||||
@@ -512,8 +512,8 @@ def doCommonTweaks(module):
|
||||
ignoreAssignmentOperators(module)
|
||||
removeWxPrefixes(module)
|
||||
addAutoProperties(module)
|
||||
|
||||
|
||||
|
||||
|
||||
def changeTypeNames(module, oldName, newName, skipTypedef=False):
|
||||
"""
|
||||
Changes the matching type names for functions and parameters to a new
|
||||
@@ -559,13 +559,13 @@ def getWrapperGenerator():
|
||||
else:
|
||||
# The default is sip
|
||||
from etgtools import sip_generator
|
||||
gClass = sip_generator.SipWrapperGenerator
|
||||
gClass = sip_generator.SipWrapperGenerator
|
||||
return gClass()
|
||||
|
||||
|
||||
def getDocsGenerator():
|
||||
if '--nodoc' in sys.argv:
|
||||
from etgtools import generators
|
||||
from etgtools import generators
|
||||
return generators.StubbedDocsGenerator()
|
||||
elif '--sphinx' in sys.argv:
|
||||
from etgtools import sphinx_generator
|
||||
@@ -574,20 +574,20 @@ def getDocsGenerator():
|
||||
# the current default is sphinx
|
||||
from etgtools import sphinx_generator
|
||||
return sphinx_generator.SphinxGenerator()
|
||||
|
||||
|
||||
|
||||
|
||||
def runGenerators(module):
|
||||
checkForUnitTestModule(module)
|
||||
|
||||
generators = list()
|
||||
|
||||
|
||||
# Create the code generator selected from command line args
|
||||
generators.append(getWrapperGenerator())
|
||||
|
||||
|
||||
# Toss in the PI generator too
|
||||
from etgtools import pi_generator
|
||||
generators.append(pi_generator.PiWrapperGenerator())
|
||||
generators.append(pi_generator.PiWrapperGenerator())
|
||||
|
||||
# Now the item map generator
|
||||
from etgtools import map_generator
|
||||
@@ -599,7 +599,7 @@ def runGenerators(module):
|
||||
# run the generators
|
||||
for g in generators:
|
||||
g.generate(module)
|
||||
|
||||
|
||||
|
||||
|
||||
def checkForUnitTestModule(module):
|
||||
@@ -625,15 +625,15 @@ def convertTwoIntegersTemplate(CLASS):
|
||||
int rval = 1;
|
||||
PyObject* o1 = PySequence_ITEM(sipPy, 0);
|
||||
PyObject* o2 = PySequence_ITEM(sipPy, 1);
|
||||
if (!PyNumber_Check(o1) || !PyNumber_Check(o2))
|
||||
if (!PyNumber_Check(o1) || !PyNumber_Check(o2))
|
||||
rval = 0;
|
||||
Py_DECREF(o1);
|
||||
Py_DECREF(o2);
|
||||
return rval;
|
||||
}}
|
||||
return 0;
|
||||
}}
|
||||
|
||||
}}
|
||||
|
||||
// otherwise do the conversion
|
||||
if (sipCanConvertToType(sipPy, sipType_{CLASS}, SIP_NO_CONVERTORS)) {{
|
||||
// Just fetch the existing instance
|
||||
@@ -641,7 +641,7 @@ def convertTwoIntegersTemplate(CLASS):
|
||||
sipPy, sipType_{CLASS}, sipTransferObj, SIP_NO_CONVERTORS, 0, sipIsErr));
|
||||
return 0; // not a new instance
|
||||
}}
|
||||
|
||||
|
||||
// or create a new instance
|
||||
PyObject* o1 = PySequence_ITEM(sipPy, 0);
|
||||
PyObject* o2 = PySequence_ITEM(sipPy, 1);
|
||||
@@ -660,14 +660,14 @@ def convertFourIntegersTemplate(CLASS):
|
||||
// is it already an instance of {CLASS}?
|
||||
if (sipCanConvertToType(sipPy, sipType_{CLASS}, SIP_NO_CONVERTORS))
|
||||
return 1;
|
||||
|
||||
|
||||
if (PySequence_Check(sipPy) && PySequence_Size(sipPy) == 4) {{
|
||||
int rval = 1;
|
||||
PyObject* o1 = PySequence_ITEM(sipPy, 0);
|
||||
PyObject* o2 = PySequence_ITEM(sipPy, 1);
|
||||
PyObject* o3 = PySequence_ITEM(sipPy, 2);
|
||||
PyObject* o4 = PySequence_ITEM(sipPy, 3);
|
||||
if (!PyNumber_Check(o1) || !PyNumber_Check(o2) || !PyNumber_Check(o3) || !PyNumber_Check(o4))
|
||||
if (!PyNumber_Check(o1) || !PyNumber_Check(o2) || !PyNumber_Check(o3) || !PyNumber_Check(o4))
|
||||
rval = 0;
|
||||
Py_DECREF(o1);
|
||||
Py_DECREF(o2);
|
||||
@@ -676,8 +676,8 @@ def convertFourIntegersTemplate(CLASS):
|
||||
return rval;
|
||||
}}
|
||||
return 0;
|
||||
}}
|
||||
|
||||
}}
|
||||
|
||||
// otherwise do the conversion
|
||||
if (sipCanConvertToType(sipPy, sipType_{CLASS}, SIP_NO_CONVERTORS)) {{
|
||||
// Just fetch the existing instance
|
||||
@@ -689,7 +689,7 @@ def convertFourIntegersTemplate(CLASS):
|
||||
PyObject* o1 = PySequence_ITEM(sipPy, 0);
|
||||
PyObject* o2 = PySequence_ITEM(sipPy, 1);
|
||||
PyObject* o3 = PySequence_ITEM(sipPy, 2);
|
||||
PyObject* o4 = PySequence_ITEM(sipPy, 3);
|
||||
PyObject* o4 = PySequence_ITEM(sipPy, 3);
|
||||
*sipCppPtr = new {CLASS}(wxPyInt_AsLong(o1), wxPyInt_AsLong(o2),
|
||||
wxPyInt_AsLong(o3), wxPyInt_AsLong(o4));
|
||||
Py_DECREF(o1);
|
||||
@@ -707,20 +707,20 @@ def convertTwoDoublesTemplate(CLASS):
|
||||
// is it already an instance of {CLASS}?
|
||||
if (sipCanConvertToType(sipPy, sipType_{CLASS}, SIP_NO_CONVERTORS))
|
||||
return 1;
|
||||
|
||||
|
||||
if (PySequence_Check(sipPy) && PySequence_Size(sipPy) == 2) {{
|
||||
int rval = 1;
|
||||
PyObject* o1 = PySequence_ITEM(sipPy, 0);
|
||||
PyObject* o2 = PySequence_ITEM(sipPy, 1);
|
||||
if (!PyNumber_Check(o1) || !PyNumber_Check(o2))
|
||||
if (!PyNumber_Check(o1) || !PyNumber_Check(o2))
|
||||
rval = 0;
|
||||
Py_DECREF(o1);
|
||||
Py_DECREF(o2);
|
||||
return rval;
|
||||
}}
|
||||
return 0;
|
||||
}}
|
||||
|
||||
}}
|
||||
|
||||
// otherwise do the conversion
|
||||
if (sipCanConvertToType(sipPy, sipType_{CLASS}, SIP_NO_CONVERTORS)) {{
|
||||
// Just fetch the existing instance
|
||||
@@ -728,7 +728,7 @@ def convertTwoDoublesTemplate(CLASS):
|
||||
sipPy, sipType_{CLASS}, sipTransferObj, SIP_NO_CONVERTORS, 0, sipIsErr));
|
||||
return 0; // not a new instance
|
||||
}}
|
||||
|
||||
|
||||
// or create a new instance
|
||||
PyObject* o1 = PySequence_ITEM(sipPy, 0);
|
||||
PyObject* o2 = PySequence_ITEM(sipPy, 1);
|
||||
@@ -747,14 +747,14 @@ def convertFourDoublesTemplate(CLASS):
|
||||
// is it already an instance of {CLASS}?
|
||||
if (sipCanConvertToType(sipPy, sipType_{CLASS}, SIP_NO_CONVERTORS))
|
||||
return 1;
|
||||
|
||||
|
||||
if (PySequence_Check(sipPy) && PySequence_Size(sipPy) == 4) {{
|
||||
int rval = 1;
|
||||
PyObject* o1 = PySequence_ITEM(sipPy, 0);
|
||||
PyObject* o2 = PySequence_ITEM(sipPy, 1);
|
||||
PyObject* o3 = PySequence_ITEM(sipPy, 2);
|
||||
PyObject* o4 = PySequence_ITEM(sipPy, 3);
|
||||
if (!PyNumber_Check(o1) || !PyNumber_Check(o2) || !PyNumber_Check(o3) || !PyNumber_Check(o4))
|
||||
if (!PyNumber_Check(o1) || !PyNumber_Check(o2) || !PyNumber_Check(o3) || !PyNumber_Check(o4))
|
||||
rval = 0;
|
||||
Py_DECREF(o1);
|
||||
Py_DECREF(o2);
|
||||
@@ -763,8 +763,8 @@ def convertFourDoublesTemplate(CLASS):
|
||||
return rval;
|
||||
}}
|
||||
return 0;
|
||||
}}
|
||||
|
||||
}}
|
||||
|
||||
// otherwise do the conversion
|
||||
if (sipCanConvertToType(sipPy, sipType_{CLASS}, SIP_NO_CONVERTORS)) {{
|
||||
// Just fetch the existing instance
|
||||
@@ -772,12 +772,12 @@ def convertFourDoublesTemplate(CLASS):
|
||||
sipPy, sipType_{CLASS}, sipTransferObj, SIP_NO_CONVERTORS, 0, sipIsErr));
|
||||
return 0; // not a new instance
|
||||
}}
|
||||
|
||||
|
||||
// or create a new instance
|
||||
PyObject* o1 = PySequence_ITEM(sipPy, 0);
|
||||
PyObject* o2 = PySequence_ITEM(sipPy, 1);
|
||||
PyObject* o3 = PySequence_ITEM(sipPy, 2);
|
||||
PyObject* o4 = PySequence_ITEM(sipPy, 3);
|
||||
PyObject* o4 = PySequence_ITEM(sipPy, 3);
|
||||
*sipCppPtr = new {CLASS}(PyFloat_AsDouble(o1), PyFloat_AsDouble(o2),
|
||||
PyFloat_AsDouble(o3), PyFloat_AsDouble(o4));
|
||||
Py_DECREF(o1);
|
||||
@@ -791,26 +791,26 @@ def convertFourDoublesTemplate(CLASS):
|
||||
# Templates for creating wrappers for type-specific wxList and wxArray classes
|
||||
|
||||
|
||||
def wxListWrapperTemplate(ListClass, ItemClass, module, RealItemClass=None,
|
||||
def wxListWrapperTemplate(ListClass, ItemClass, module, RealItemClass=None,
|
||||
includeConvertToType=False, fakeListClassName=None):
|
||||
if RealItemClass is None:
|
||||
RealItemClass = ItemClass
|
||||
RealItemClass = ItemClass
|
||||
|
||||
if fakeListClassName:
|
||||
TypeDef = "typedef %s %s;" % (ListClass, fakeListClassName)
|
||||
ListClass = fakeListClassName
|
||||
else:
|
||||
TypeDef = ""
|
||||
|
||||
moduleName = module.module
|
||||
|
||||
moduleName = module.module
|
||||
ListClass_pyName = removeWxPrefix(ListClass)
|
||||
|
||||
|
||||
# *** TODO: This can probably be done in a way that is not SIP-specfic.
|
||||
# Try creating extractor objects from scratch and attach cppMethods to
|
||||
# them as needed, etc..
|
||||
|
||||
|
||||
klassCode = '''\
|
||||
class {ListClass}_iterator /Abstract/
|
||||
class {ListClass}_iterator /Abstract/
|
||||
{{
|
||||
// the C++ implementation of this class
|
||||
%TypeHeaderCode
|
||||
@@ -819,7 +819,7 @@ class {ListClass}_iterator /Abstract/
|
||||
public:
|
||||
{ListClass}_iterator({ListClass}::compatibility_iterator start)
|
||||
: m_node(start) {{}}
|
||||
|
||||
|
||||
{ItemClass}* __next__() {{
|
||||
{RealItemClass}* obj = NULL;
|
||||
if (m_node) {{
|
||||
@@ -842,13 +842,13 @@ public:
|
||||
if (PyErr_Occurred())
|
||||
return NULL;
|
||||
%End
|
||||
}};
|
||||
}};
|
||||
|
||||
class {ListClass}
|
||||
class {ListClass}
|
||||
{{
|
||||
%TypeHeaderCode
|
||||
{TypeDef}
|
||||
%End
|
||||
%End
|
||||
public:
|
||||
SIP_SSIZE_T __len__();
|
||||
%MethodCode
|
||||
@@ -859,7 +859,7 @@ public:
|
||||
%MethodCode
|
||||
if (index < sipCpp->size()) {{
|
||||
{ListClass}::compatibility_iterator node = sipCpp->Item(index);
|
||||
if (node)
|
||||
if (node)
|
||||
sipRes = ({ItemClass}*)node->GetData();
|
||||
}}
|
||||
else {{
|
||||
@@ -891,7 +891,7 @@ public:
|
||||
}}
|
||||
sipRes = idx;
|
||||
%End
|
||||
|
||||
|
||||
@ConvertToTypeCode@
|
||||
}};
|
||||
|
||||
@@ -912,7 +912,7 @@ del _{ListClass_pyName}___repr__
|
||||
if (sipCanConvertToType(sipPy, sipType_{ListClass}, SIP_NO_CONVERTORS))
|
||||
return success;
|
||||
// otherwise ensure that it is a sequence
|
||||
if (! PySequence_Check(sipPy))
|
||||
if (! PySequence_Check(sipPy))
|
||||
success = FALSE;
|
||||
// ensure it is not a string or unicode object (they are sequences too)
|
||||
else if (PyBytes_Check(sipPy) || PyUnicode_Check(sipPy))
|
||||
@@ -928,9 +928,9 @@ del _{ListClass_pyName}___repr__
|
||||
break;
|
||||
}}
|
||||
Py_DECREF(item);
|
||||
}}
|
||||
}}
|
||||
}}
|
||||
if (!success)
|
||||
if (!success)
|
||||
PyErr_SetString(PyExc_TypeError, "Sequence of {ItemClass} compatible objects expected.");
|
||||
return success;
|
||||
}}
|
||||
@@ -938,11 +938,11 @@ del _{ListClass_pyName}___repr__
|
||||
// Is it already a {ListClass}? Return the exiting instance if so
|
||||
if (sipCanConvertToType(sipPy, sipType_{ListClass}, SIP_NO_CONVERTORS)) {{
|
||||
*sipCppPtr = reinterpret_cast<{ListClass}*>(
|
||||
sipConvertToType(sipPy, sipType_{ListClass}, NULL,
|
||||
sipConvertToType(sipPy, sipType_{ListClass}, NULL,
|
||||
SIP_NO_CONVERTORS, 0, sipIsErr));
|
||||
return 0;
|
||||
}}
|
||||
|
||||
|
||||
// Create a new {ListClass} and convert compatible PyObjects from the sequence
|
||||
{ListClass} *list = new {ListClass};
|
||||
list->DeleteContents(true); // tell the list to take ownership of the items
|
||||
@@ -951,7 +951,7 @@ del _{ListClass_pyName}___repr__
|
||||
int state;
|
||||
PyObject* pyItem = PySequence_ITEM(sipPy, i);
|
||||
{ItemClass}* cItem = reinterpret_cast<{ItemClass}*>(
|
||||
sipConvertToType(pyItem, sipType_{ItemClass},
|
||||
sipConvertToType(pyItem, sipType_{ItemClass},
|
||||
NULL, 0, &state, sipIsErr));
|
||||
if (!state) // a temporary was not created for us, make one now
|
||||
cItem = new {ItemClass}(*cItem);
|
||||
@@ -971,7 +971,7 @@ del _{ListClass_pyName}___repr__
|
||||
|
||||
|
||||
def wxArrayWrapperTemplate(ArrayClass, ItemClass, module, itemIsPtr=False):
|
||||
moduleName = module.module
|
||||
moduleName = module.module
|
||||
ArrayClass_pyName = removeWxPrefix(ArrayClass)
|
||||
itemRef = '*' if itemIsPtr else '&'
|
||||
itemDeref = '' if itemIsPtr else '*'
|
||||
@@ -980,9 +980,9 @@ def wxArrayWrapperTemplate(ArrayClass, ItemClass, module, itemIsPtr=False):
|
||||
# *** TODO: This can probably be done in a way that is not SIP-specfic.
|
||||
# Try creating extractor objects from scratch and attach cppMethods to
|
||||
# them as needed, etc..
|
||||
|
||||
|
||||
return extractors.WigCode('''\
|
||||
class {ArrayClass}
|
||||
class {ArrayClass}
|
||||
{{
|
||||
public:
|
||||
SIP_SSIZE_T __len__();
|
||||
@@ -1037,15 +1037,15 @@ del _{ArrayClass_pyName}___repr__
|
||||
|
||||
# Same as the above, but for use with WX_DEFINE_ARRAY_PTR
|
||||
def wxArrayPtrWrapperTemplate(ArrayClass, ItemClass, module):
|
||||
moduleName = module.module
|
||||
moduleName = module.module
|
||||
ArrayClass_pyName = removeWxPrefix(ArrayClass)
|
||||
|
||||
|
||||
# *** TODO: This can probably be done in a way that is not SIP-specfic.
|
||||
# Try creating extractor objects from scratch and attach cppMethods to
|
||||
# them as needed, etc..
|
||||
|
||||
|
||||
return extractors.WigCode('''\
|
||||
class {ArrayClass}
|
||||
class {ArrayClass}
|
||||
{{
|
||||
public:
|
||||
SIP_SSIZE_T __len__();
|
||||
@@ -1104,8 +1104,8 @@ def ObjArrayHelperTemplate(objType, sipType, errmsg):
|
||||
Generates a helper function that can convert from a Python sequence of
|
||||
objects (or items that can be converted to the target type) into a C
|
||||
array of values. Copies are made of the items so the object types should
|
||||
support implicit or explicit copies and the copy should be cheap.
|
||||
|
||||
support implicit or explicit copies and the copy should be cheap.
|
||||
|
||||
This kind of helper is useful for situations where the C/C++ API takes a
|
||||
simple pointer and a count, and there is no higher level container object
|
||||
(like a wxList or wxArray) being used. If there is an overloaded method
|
||||
@@ -1113,9 +1113,9 @@ def ObjArrayHelperTemplate(objType, sipType, errmsg):
|
||||
ignored. But for those cases where the C array is the only option then this
|
||||
helper can be used to make the array from a sequence.
|
||||
"""
|
||||
|
||||
|
||||
cppCode = """\
|
||||
// Convert a Python sequence of {objType} objects, or items that can be converted
|
||||
// Convert a Python sequence of {objType} objects, or items that can be converted
|
||||
// to {objType} into a C array of {objType} instances.
|
||||
static
|
||||
{objType}* {objType}_array_helper(PyObject* source, size_t *count)
|
||||
@@ -1123,9 +1123,9 @@ static
|
||||
{objType}* array;
|
||||
Py_ssize_t idx, len;
|
||||
wxPyThreadBlocker blocker;
|
||||
|
||||
|
||||
// ensure that it is a sequence
|
||||
if (! PySequence_Check(source))
|
||||
if (! PySequence_Check(source))
|
||||
goto error0;
|
||||
// ensure it is not a string or unicode object (they are sequences too)
|
||||
else if (PyBytes_Check(source) || PyUnicode_Check(source))
|
||||
@@ -1142,7 +1142,7 @@ static
|
||||
Py_DECREF(item);
|
||||
}}
|
||||
}}
|
||||
|
||||
|
||||
// The length of the sequence is returned in count.
|
||||
*count = len;
|
||||
array = new {objType}[*count];
|
||||
|
||||
Reference in New Issue
Block a user