I would like to override some functions of the ogl.wxLineShape with python code.
I have a derived class from ogl.wxLineShape:
MyClass(ogl.wxLineShape):
There I define several python member functions, like
OnMoveLink(self, dc, move_control_points):
...
Select(self, selected, dc):
...
as well as
MakeControlPoints(self):
...
DeleteControlPoints(self, dc):
...
.
Overriding the first two functions works fine, however the last two functions are never called.
My question is: Why can't the latter ones not be overridden and where do I have to look for information which functions can be overridden in python in which not?
Overriding the first two functions works fine, however the last two
functions are never called.
My question is: Why can't the latter ones not be overridden and where do I
have to look for information which functions can be overridden in python in
which not?
Allowing C++ class methods to be overridden in Python code is a fairly
expensive task and adds a lot of overhead to the wrapper code. Essentially
every time the method is called (whether from C++ or Python) we have to
aquire the Python Interpreter lock, check if there is a matching method in
the python object, create Python objects from the parameters (some of which
might need other wxPython shadow objects to be created,) call the method,
check for exceptions, convert the return value(s) back to what is expected
by the C++ code and then release the lock.
Not only is this expensive at runtime but also in the amount of code
required. As an example look at the size of wxc.pyd vs. oglc.pyd (or .so)
and you'll see that OGL, while much smaller in the number of classes and
etc., has almost the same amount of compiled code as the entire core of
wxPython because of the much larger number of overridable methods. (In my
current workspace they are oglc: 1081402 and wxc: 1876025)
To try and keep this overhead as low as possible my general policy has been
to only make those methods overridable which need to be so in order to meet
the needs of the class as it was designed. In other words, those methods
which I felt the original author planned on being overridden in derived
classes. For OGL I gave all the OnXxxx methods overridable support.
···
--
Robin Dunn
Software Craftsman
robin@AllDunn.com Java give you jitters? http://wxPython.org Relax with wxPython!