From: abn Date: Mon, 3 Mar 2014 08:42:05 +0000 (+0100) Subject: SWIG: improve precedence mechanism: isinstance(obj, MEDCoupling.obj_class) and X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2Fabn%2Fcosmetic_py;p=tools%2Fmedcoupling.git SWIG: improve precedence mechanism: isinstance(obj, MEDCoupling.obj_class) and isinstance(obj, MEDLoader.obj_class) both return true. --- diff --git a/src/MEDCoupling_Swig/MEDCoupling.i b/src/MEDCoupling_Swig/MEDCoupling.i index a7080a02a..e9176473f 100644 --- a/src/MEDCoupling_Swig/MEDCoupling.i +++ b/src/MEDCoupling_Swig/MEDCoupling.i @@ -98,3 +98,16 @@ def ParaMEDMEMDataArrayIntTupleImod(self,*args): %} %include "MEDCouplingFinalize.i" + +%pythoncode %{ + +# Give precedence to MEDCoupling namespace: +import sys +# If MEDLoader was already loaded override its namespace with the one from MEDCoupling: +if sys.modules.has_key('MEDLoader'): + ml_mod = sys.modules['MEDLoader'] + for k, v in sys.modules['MEDCoupling'].__dict__.items(): + if (k.startswith("MED") or k.startswith("InterpKernel")) and type(v) is type(type): + exec("ml_mod.__dict__[k] = %s" % k) + +%} diff --git a/src/MEDCoupling_Swig/MEDCouplingFinalize.i b/src/MEDCoupling_Swig/MEDCouplingFinalize.i index e54cc904d..194cc4c70 100644 --- a/src/MEDCoupling_Swig/MEDCouplingFinalize.i +++ b/src/MEDCoupling_Swig/MEDCouplingFinalize.i @@ -71,4 +71,5 @@ del ParaMEDMEMDataArrayIntTupleIsub del ParaMEDMEMDataArrayIntTupleImul del ParaMEDMEMDataArrayIntTupleIdiv del ParaMEDMEMDataArrayIntTupleImod + %} diff --git a/src/MEDLoader/Swig/MEDLoader.i b/src/MEDLoader/Swig/MEDLoader.i index 24aa39736..5d4126234 100644 --- a/src/MEDLoader/Swig/MEDLoader.i +++ b/src/MEDLoader/Swig/MEDLoader.i @@ -99,3 +99,16 @@ def ParaMEDMEMDataArrayIntTupleImod(self,*args): %} %include "MEDCouplingFinalize.i" + +%pythoncode %{ + +# Give precedence to MEDCoupling namespace: +import sys +# If MEDLoader was already loaded override its namespace with the one from MEDCoupling: +if sys.modules.has_key('MEDCoupling'): + mc_mod = sys.modules['MEDCoupling'] + for k, v in mc_mod.__dict__.items(): + if (k.startswith("MED") or k.startswith("InterpKernel")) and type(v) is type(type): + exec("%s = v" % k) + +%}