Salome HOME
Allow the definition of a Pyscript in the GUI (not generated in schema yet).
authorRenaud Barate <renaud.barate@edf.fr>
Thu, 29 Nov 2012 16:50:37 +0000 (17:50 +0100)
committerRenaud Barate <renaud.barate@edf.fr>
Thu, 29 Nov 2012 16:50:37 +0000 (17:50 +0100)
Python package tree simplification.

src/PARAMETRIC/PARAMETRIC.py
src/PARAMETRICGUI/PARAMETRICGUI.py
src/salome/parametric/__init__.py
src/salome/parametric/gui/__init__.py
src/salome/parametric/gui/definevalues.py
src/salome/parametric/gui/execparams.py
src/salome/parametric/gui/execparams.ui
src/salome/parametric/gui/selectvars.py
src/salome/parametric/gui/wizard.py

index 831ef4d00eceb370becc7c641bdc898e30be3196..7ad2c812c1ed3ba7f41de49659d3dcc5ec899f3c 100644 (file)
@@ -37,7 +37,7 @@ from salome.kernel import termcolor
 logger = Logger("PARAMETRIC", color = termcolor.BLUE)
 logger.setLevel(logging.DEBUG)
 
-from salome.parametric.study import ParametricStudyEditor
+from salome.parametric import ParametricStudyEditor
 
 class PARAMETRIC(PARAMETRIC_ORB__POA.PARAMETRIC_Gen, SALOME_ComponentPy_i, SALOME_DriverPy_i):
 
index 1501ab067678a07842f971927daa1984d01e96c5..e78753a3ede0ad038c29f3890b75ec2c34498821 100644 (file)
@@ -15,7 +15,6 @@
 # You should have received a copy of the GNU Lesser General Public License
 # along with SALOME PARAMETRIC module.  If not, see <http://www.gnu.org/licenses/>.
 
-import os
 import logging
 
 from PyQt4 import QtGui, QtCore
@@ -33,11 +32,10 @@ from salome.kernel.logger import Logger
 from salome.kernel import termcolor
 logger = Logger("PARAMETRICGUI", color = termcolor.GREEN_FG)
 #logger.setLevel(logging.ERROR)
-from salome.kernel.parametric import study_exchange_vars
 
 import PARAMETRIC
-from salome.parametric.gui.mainpanel import MainPanel
-from salome.parametric.study import ParametricStudyEditor
+from salome.parametric.gui import MainPanel
+from salome.parametric import ParametricStudyEditor
 
 ################################################
 # GUI context class
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..18ce3bab202756fb6f7c37faec9754a61d25a0d7 100644 (file)
@@ -0,0 +1,22 @@
+# Copyright (C) 2012 EDF
+#
+# This file is part of SALOME PARAMETRIC module.
+#
+# SALOME PARAMETRIC module is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# SALOME PARAMETRIC module is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with SALOME PARAMETRIC module.  If not, see <http://www.gnu.org/licenses/>.
+
+import study
+
+ParametricStudy = study.ParametricStudy
+ParametricVariable = study.ParametricVariable
+ParametricStudyEditor = study.ParametricStudyEditor
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..882fff927c57fd472ccdf5bcb62a7b73850f1eaf 100644 (file)
@@ -0,0 +1,20 @@
+# Copyright (C) 2012 EDF
+#
+# This file is part of SALOME PARAMETRIC module.
+#
+# SALOME PARAMETRIC module is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# SALOME PARAMETRIC module is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with SALOME PARAMETRIC module.  If not, see <http://www.gnu.org/licenses/>.
+
+import mainpanel
+
+MainPanel = mainpanel.MainPanel
index 5bd7bf14acfb091ca19a739c23162820fb0d31bc..4d9ee27c30f6bd57deb1babf1e292f7b44690f65 100644 (file)
@@ -61,3 +61,6 @@ class DefineValuesFrame(QtGui.QWidget):
       varrange.stepSpinBox.setValue(var.step)
       self.varwidgets[var.name] = varrange
       self.layout().insertWidget(self.layout().count()-1, varrange)
+
+  def check_values(self):
+    return True
index 84a8b5526ddf4292c2dcf7ead6c89ca5aec1a18b..70c26c8b2df67045277c15cb168dda96a14eeff0 100644 (file)
@@ -20,7 +20,7 @@ from PyQt4 import QtGui, QtCore
 import salome
 from salome.kernel.studyedit import getStudyEditor
 
-from salome.parametric.study import ParametricStudy
+from salome.parametric import ParametricStudy
 from execparams_ui import Ui_ExecParams
 
 
@@ -32,6 +32,33 @@ class ExecParamsFrame(QtGui.QWidget, Ui_ExecParams):
     self.connect(self.selectFromSalomeButton, QtCore.SIGNAL("clicked()"), self.select_from_salome)
     self.case_entry = None
   
+  def set_pyscript_label_from_vars(self, exchange_vars):
+    text = ""
+    input_var_names = [var.name for var in exchange_vars.inputVarList]
+    text += "This script can use variable"
+    if len(input_var_names) > 1:
+      text += "s"
+    for i, var in enumerate(input_var_names):
+      if len(input_var_names) > 1 and i == len(input_var_names) - 1:
+        text += " and"
+      elif i != 0:
+        text += ","
+      text += " <b>" + var + "</b>"
+    text += "."
+    output_var_names = [var.name for var in exchange_vars.outputVarList]
+    if len(output_var_names) > 0:
+      text += "<br>It must create variable"
+      if len(output_var_names) > 1:
+        text += "s"
+      for i, var in enumerate(output_var_names):
+        if len(output_var_names) > 1 and i == len(output_var_names) - 1:
+          text += " and"
+        elif i != 0:
+          text += ","
+        text += " <b>" + var + "</b>"
+      text += "."
+    self.pyscriptLabel.setText(text)
+  
   def select_from_salome(self):
     nb_entries = salome.sg.SelectedCount()
     if nb_entries < 1:
@@ -54,7 +81,7 @@ class ExecParamsFrame(QtGui.QWidget, Ui_ExecParams):
       param_study.solver_case_entry = self.case_entry
     else:
       param_study.solver_code_type = ParametricStudy.PYTHON_SCRIPT
-      param_study.python_script = str(self.pythonScriptTE.text())
+      param_study.python_script = str(self.pythonScriptTE.toPlainText())
     param_study.name = str(self.studyNameLE.text())
     param_study.nb_parallel_computations = self.nbParallelSB.value()
 
@@ -68,3 +95,6 @@ class ExecParamsFrame(QtGui.QWidget, Ui_ExecParams):
       self.pythonScriptTE.setText(param_study.python_script)
     self.studyNameLE.setText(param_study.name)
     self.nbParallelSB.setValue(param_study.nb_parallel_computations)
+
+  def check_values(self):
+    return True
index 2270933194a2664b84193ad6c975001e28aa983e..4a47bcc77843fa3b2d9943acf0c94ff65177fc44 100644 (file)
@@ -19,7 +19,7 @@
      <property name="title">
       <string>Solver Code</string>
      </property>
-     <layout class="QVBoxLayout" name="verticalLayout_2">
+     <layout class="QVBoxLayout" name="verticalLayout_3">
       <item>
        <widget class="QRadioButton" name="salomeComponentRB">
         <property name="text">
       </item>
       <item>
        <widget class="QRadioButton" name="pythonScriptRB">
-        <property name="enabled">
-         <bool>false</bool>
-        </property>
         <property name="text">
          <string>Python Script</string>
         </property>
           <property name="sizeHint" stdset="0">
            <size>
             <width>25</width>
-            <height>10</height>
+            <height>13</height>
            </size>
           </property>
          </spacer>
         </item>
         <item>
-         <widget class="QTextEdit" name="pythonScriptTE">
-          <property name="enabled">
-           <bool>false</bool>
-          </property>
-         </widget>
+         <layout class="QVBoxLayout" name="verticalLayout_2">
+          <item>
+           <widget class="QLabel" name="pyscriptLabel">
+            <property name="font">
+             <font>
+              <italic>true</italic>
+             </font>
+            </property>
+           </widget>
+          </item>
+          <item>
+           <widget class="QTextEdit" name="pythonScriptTE"/>
+          </item>
+         </layout>
         </item>
        </layout>
       </item>
index 274aa228a43bcdc46b9b43aa0e82e378f1391508..6f4f04b34565c82f0dff6e2c8dd780879255e2f6 100644 (file)
@@ -32,3 +32,11 @@ class SelectVarsFrame(MySelectVarsDialog):
     output_var_list = [study_exchange_vars.Variable(varname) for varname in param_study.output_vars]
     exchange_vars = study_exchange_vars.ExchangeVariables(input_var_list, output_var_list)
     self.setExchangeVariables(exchange_vars)
+
+  def check_values(self):
+    if self.selectedInputVarListWidget.count() == 0:
+      QtGui.QMessageBox.critical(self, self.tr("Error"),
+                                 self.tr("There must be at least one selected input variable"))
+      return False
+    else:
+      return True
index 0dfffb02dbf022f1be5c432a9a750a1c33b8e67d..6f6e47c782a6333b91a929adeb4197e56cc05cf9 100644 (file)
@@ -25,7 +25,7 @@ from wizard_ui import Ui_Wizard
 from selectvars import SelectVarsFrame
 from definevalues import DefineValuesFrame
 from execparams import ExecParamsFrame
-from salome.parametric.study import ParametricVariable, ParametricStudy, ParametricStudyEditor
+from salome.parametric import ParametricVariable, ParametricStudy, ParametricStudyEditor
 
 
 class Wizard(QtGui.QWidget, Ui_Wizard):
@@ -55,12 +55,14 @@ class Wizard(QtGui.QWidget, Ui_Wizard):
     self.view_id = None
 
   def next_step(self):
-    self.curstep += 1
-    self.step()
+    if self.step_frames[self.curstep].check_values():
+      self.curstep += 1
+      self.step()
 
   def previous_step(self):
-    self.curstep -= 1
-    self.step()
+    if self.step_frames[self.curstep].check_values():
+      self.curstep -= 1
+      self.step()
 
   def step(self):
     for i in range(len(self.step_texts)):
@@ -87,7 +89,13 @@ class Wizard(QtGui.QWidget, Ui_Wizard):
     exchange_vars = self.select_vars_frame.getSelectedExchangeVariables()
     self.define_values_frame.set_variables(exchange_vars.inputVarList)
 
+  def set_pyscript_label(self):
+    exchange_vars = self.select_vars_frame.getSelectedExchangeVariables()
+    self.exec_params_frame.set_pyscript_label_from_vars(exchange_vars)
+
   def validate(self):
+    if not self.step_frames[self.curstep].check_values():
+      return
     param_study = ParametricStudy()
     # Input variables
     for (name, range_widget) in self.define_values_frame.varwidgets.iteritems():
@@ -129,4 +137,4 @@ class Wizard(QtGui.QWidget, Ui_Wizard):
 
   step_methods = [None,
                   define_values,
-                  None]
+                  set_pyscript_label]