From 04e2e3b26a5125a4484c45ae9fc9811eb90c7601 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Tue, 30 Jul 2019 14:01:19 +0200 Subject: [PATCH] Get access of variable in the context dict of PyScriptNode instance. --- idl/SALOME_PyNode.idl | 4 ++++ src/Container/SALOME_PyNode.py | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/idl/SALOME_PyNode.idl b/idl/SALOME_PyNode.idl index e3dfd3c84..6c8af4241 100644 --- a/idl/SALOME_PyNode.idl +++ b/idl/SALOME_PyNode.idl @@ -84,6 +84,10 @@ module Engines pickledArgs getValueOfVarInContext(in string varName) raises (SALOME::SALOME_Exception); + + void assignVarInContext(in string varName, in pickledArgs value) raises (SALOME::SALOME_Exception); + + pickledArgs callMethodOnVarInContext(in string varName, in string methodName, in pickledArgs args) raises (SALOME::SALOME_Exception); } ; }; diff --git a/src/Container/SALOME_PyNode.py b/src/Container/SALOME_PyNode.py index be34f21fc..48a839e8c 100644 --- a/src/Container/SALOME_PyNode.py +++ b/src/Container/SALOME_PyNode.py @@ -150,3 +150,22 @@ class PyScriptNode_i (Engines__POA.PyScriptNode,Generic): exc_typ,exc_val,exc_fr=sys.exc_info() l=traceback.format_exception(exc_typ,exc_val,exc_fr) raise SALOME.SALOME_Exception(SALOME.ExceptionStruct(SALOME.BAD_PARAM,"".join(l),"PyScriptNode: %s" %self.nodeName,0)) + pass + + def assignVarInContext(self, varName, value): + try: + self.context[varName][0] = pickle.loads(value) + except: + exc_typ,exc_val,exc_fr=sys.exc_info() + l=traceback.format_exception(exc_typ,exc_val,exc_fr) + raise SALOME.SALOME_Exception(SALOME.ExceptionStruct(SALOME.BAD_PARAM,"".join(l),"PyScriptNode: %s" %self.nodeName,0)) + pass + + def callMethodOnVarInContext(self, varName, methodName, args): + try: + return pickle.dumps( getattr(self.context[varName][0],methodName)(*pickle.loads(args)),-1 ) + except: + exc_typ,exc_val,exc_fr=sys.exc_info() + l=traceback.format_exception(exc_typ,exc_val,exc_fr) + raise SALOME.SALOME_Exception(SALOME.ExceptionStruct(SALOME.BAD_PARAM,"".join(l),"PyScriptNode: %s" %self.nodeName,0)) + pass -- 2.39.2