Salome HOME
Debug of GUI when handling local python nodes.
authorAnthony Geay <anthony.geay@edf.fr>
Wed, 13 Aug 2014 13:19:49 +0000 (15:19 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Wed, 13 Aug 2014 13:19:49 +0000 (15:19 +0200)
src/genericgui/FormContainerDecorator.cxx
src/genericgui/FormContainerDecorator.hxx
src/runtime/PythonNode.cxx

index 996f0c9b56e6be01bbd1dc1c14d8b9e858740362..f6d2405c9a71e39ad72497cb0bd8f734a1321d7b 100644 (file)
@@ -33,13 +33,13 @@ bool FormContainerDecorator::CHECKED = false;
 
 FormContainerDecorator::FormContainerDecorator(YACS::ENGINE::Container *cont, QWidget *parent):QWidget(parent),_typ(0)
 {
-  if(!cont)
-    throw YACS::Exception("FormContainerDecorator constrctor : container is empty !");
   setupUi(this);
   _icon.addFile("icons:icon_down.png");
   _icon.addFile("icons:icon_up.png",QSize(), QIcon::Normal, QIcon::On);
   tb_container->setIcon(_icon);
   connect(this,SIGNAL(typeOfContainerIsKnown(const QString&)),label,SLOT(setText(const QString &)));
+  if(!cont)
+    return ;
   HomogeneousPoolContainer *hpc(dynamic_cast<HomogeneousPoolContainer *>(cont));
   if(!hpc)
     _typ=new FormContainer(this);
@@ -60,33 +60,34 @@ FormContainerDecorator::~FormContainerDecorator()
 
 void FormContainerDecorator::FillPanel(YACS::ENGINE::Container *container)
 {
-  checkOK();
   checkAndRepareTypeIfNecessary(container);
   _typ->FillPanel(container);
 }
 
 QWidget *FormContainerDecorator::getWidget()
 {
-  checkOK();
   return _typ;
 }
 
 bool FormContainerDecorator::onApply()
 {
-  checkOK();
+  if(!checkOK())
+    return false;
   return _typ->onApply();
 }
 
 void FormContainerDecorator::onCancel()
 {
-  checkOK();
+  if(!checkOK())
+    return ;
   _typ->onCancel();
 }
 
 void FormContainerDecorator::show()
 {
   QWidget::show();
-  checkOK();
+  if(!checkOK())
+    return ;
   _typ->show();
   tb_container->setChecked(CHECKED);
   on_tb_container_toggled(CHECKED);
@@ -95,7 +96,8 @@ void FormContainerDecorator::show()
 void FormContainerDecorator::hide()
 {
   QWidget::hide();
-  checkOK();
+  if(!checkOK())
+    return ;
   _typ->hide();
 }
 
@@ -115,19 +117,20 @@ void FormContainerDecorator::on_tb_container_toggled(bool checked)
 
 void FormContainerDecorator::synchronizeCheckContainer()
 {
-  checkOK();
   tb_container->setChecked(CHECKED);
 }
 
 std::string FormContainerDecorator::getHostName(int index) const
 {
-  checkOK();
+  if(!checkOK())
+    return std::string();
   return _typ->cb_resource->itemText(index).toStdString();
 }
 
 void FormContainerDecorator::setName(const std::string& name)
 {
-  checkOK();
+  if(!checkOK())
+    return ;
   _typ->le_name->setText(name.c_str());
 }
 
@@ -146,27 +149,27 @@ void FormContainerDecorator::onContToggled(bool v)
   emit(containerToggled(v));
 }
 
-void FormContainerDecorator::checkOK() const
+bool FormContainerDecorator::checkOK() const
 {
-  if(!_typ)
-    throw YACS::Exception("Null Widget Container !!!!");
+  return _typ;
 }
 
 void FormContainerDecorator::checkAndRepareTypeIfNecessary(YACS::ENGINE::Container *container)
 {
-  checkOK();
   if(!container)
-    throw YACS::Exception("Null Container !!!!");
-  YACS::ENGINE::HomogeneousPoolContainer *cont1(dynamic_cast<YACS::ENGINE::HomogeneousPoolContainer *>(container));
-  bool isTyp1(dynamic_cast<FormHPContainer *>(_typ)!=0);
-  if((!cont1 && !isTyp1) || (cont1 && isTyp1))
     return ;
-  QWidget *parent(_typ->parentWidget());
-  delete _typ; _typ=0;
+  YACS::ENGINE::HomogeneousPoolContainer *cont1(dynamic_cast<YACS::ENGINE::HomogeneousPoolContainer *>(container));
+  if(_typ)
+    {
+      bool isTyp1(dynamic_cast<FormHPContainer *>(_typ)!=0);
+      if((!cont1 && !isTyp1) || (cont1 && isTyp1))
+        return ;
+      delete _typ; _typ=0;
+    }
   if(!cont1)
-    _typ=new FormContainer(parent);
+    _typ=new FormContainer(this);
   else
-    _typ=new FormHPContainer(parent);
+    _typ=new FormHPContainer(this);
   gridLayout_1->addWidget(_typ);
   emit typeOfContainerIsKnown(_typ->getTypeStr());
   connectForTyp();
index a50e5535f5a69f88ecd5f33e3beb47812667ef30..4dc8f06a1d75a94b19e2dcc5de2a11d2eabe3a88 100644 (file)
@@ -65,7 +65,7 @@ signals:
   void resourceActivated(int);
   void containerToggled(bool);//connect(_wContainer->tb_container, SIGNAL(toggled(bool)), this, SLOT(fillContainerPanel())); // --- to update display of current selection
 private:
-  void checkOK() const;
+  bool checkOK() const;
   void checkAndRepareTypeIfNecessary(YACS::ENGINE::Container *container);
   void connectForTyp();
 private:
index 7973b2cf810f8a6134ff0a5eebe6c30821915d21..db29917d389bc2d27d8e7c821f034992bd1de6c9 100644 (file)
@@ -176,7 +176,7 @@ void PythonNode::loadRemote()
   bool isInitializeRequested(false);
   try
     {
-      if(containerCast0 || !isContAlreadyStarted)
+      if(containerCast0)
         {
           _pynode = objContainer->createPyScriptNode(getName().c_str(),getScript().c_str());
         }
@@ -715,10 +715,10 @@ void PyFuncNode::loadRemote()
     throw Exception("Unrecognized type of container ! Salome one is expected ! In PythonNode !");
   if(CORBA::is_nil(objContainer))
     throw Exception("Container corba pointer is NULL ! In PythonNode !");
-
+  bool isInitializeRequested(false);
   try
     {
-      if(containerCast0 || !isContAlreadyStarted)
+      if(containerCast0)
         {
           _pynode = objContainer->createPyNode(getName().c_str(),getScript().c_str());
         }
@@ -726,7 +726,10 @@ void PyFuncNode::loadRemote()
         {
           Engines::PyNode_var dftPyScript(objContainer->getDefaultPyNode());
           if(CORBA::is_nil(dftPyScript))
-            _pynode = objContainer->createPyNode(getName().c_str(),getScript().c_str());
+            {
+              isInitializeRequested=true;
+              _pynode = objContainer->createPyNode(getName().c_str(),getScript().c_str());
+            }
           else
             _pynode = dftPyScript;
         }
@@ -787,6 +790,23 @@ void PyFuncNode::loadRemote()
         Py_DECREF(new_stderr);
         throw Exception("Error during load");
       }
+    if(isInitializeRequested)
+      {//This one is called only once at initialization in the container if an init-script is specified.
+        try
+          {
+            std::string zeInitScriptKey(_container->getProperty(HomogeneousPoolContainer::INITIALIZE_SCRIPT_KEY));
+            if(!zeInitScriptKey.empty())
+              _pynode->executeAnotherPieceOfCode(zeInitScriptKey.c_str());
+          }
+        catch( const SALOME::SALOME_Exception& ex )
+          {
+            std::string msg="Exception on PythonNode::loadRemote python invocation of initializisation py script !";
+            msg += '\n';
+            msg += ex.details.text.in();
+            _errorDetails=msg;
+            throw Exception(msg);
+          }
+      }
     DEBTRACE( "---------------End PyfuncNode::loadRemote function---------------" );
   }
 }