diff --git a/pybindgen/cppclass.py b/pybindgen/cppclass.py index 72f1a52..32098e2 100644 --- a/pybindgen/cppclass.py +++ b/pybindgen/cppclass.py @@ -73,7 +73,7 @@ class CppClass(object): ) def __init__(self, name, parent=None, incref_method=None, decref_method=None, - automatic_type_narrowing=None): + automatic_type_narrowing=None, allow_subclassing=None): """Constructor name -- class name parent -- optional parent class wrapper @@ -90,6 +90,8 @@ class CppClass(object): of this class and its descendents when returned by pointer from a function or method. + allow_subclassing -- if True, generated class wrappers will + allow subclassing in Python. """ self.name = name self.methods = {} # name => OverloadedMethod @@ -123,6 +125,14 @@ class CppClass(object): else: self.automatic_type_narrowing = automatic_type_narrowing + if allow_subclassing is None: + if parent is None: + self.allow_subclassing = settings.allow_subclassing + else: + self.allow_subclassing = parent.allow_subclassing + else: + self.allow_subclassing = allow_subclassing + self.typeid_map = None self.typeid_map_name = None # name of C++ variable if self.automatic_type_narrowing: diff --git a/pybindgen/settings.py b/pybindgen/settings.py index 94ecbf1..6a3ffc0 100644 --- a/pybindgen/settings.py +++ b/pybindgen/settings.py @@ -16,3 +16,8 @@ automatic_type_narrowing = False """ Default value for the automatic_type_narrowing parameter of C++ classes. """ + +allow_subclassing = False +""" +Allow generated classes to be subclassed by default. +"""