From: Renaud Barate Date: Thu, 29 Nov 2012 16:50:37 +0000 (+0100) Subject: Allow the definition of a Pyscript in the GUI (not generated in schema yet). X-Git-Tag: V6_6_0~5 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=10a1136e3831857fa5ddd383e462c9b5c277fa5d;p=modules%2Fparametric.git Allow the definition of a Pyscript in the GUI (not generated in schema yet). Python package tree simplification. --- diff --git a/src/PARAMETRIC/PARAMETRIC.py b/src/PARAMETRIC/PARAMETRIC.py index 831ef4d..7ad2c81 100644 --- a/src/PARAMETRIC/PARAMETRIC.py +++ b/src/PARAMETRIC/PARAMETRIC.py @@ -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): diff --git a/src/PARAMETRICGUI/PARAMETRICGUI.py b/src/PARAMETRICGUI/PARAMETRICGUI.py index 1501ab0..e78753a 100644 --- a/src/PARAMETRICGUI/PARAMETRICGUI.py +++ b/src/PARAMETRICGUI/PARAMETRICGUI.py @@ -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 . -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 diff --git a/src/salome/parametric/__init__.py b/src/salome/parametric/__init__.py index e69de29..18ce3ba 100644 --- a/src/salome/parametric/__init__.py +++ b/src/salome/parametric/__init__.py @@ -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 . + +import study + +ParametricStudy = study.ParametricStudy +ParametricVariable = study.ParametricVariable +ParametricStudyEditor = study.ParametricStudyEditor diff --git a/src/salome/parametric/gui/__init__.py b/src/salome/parametric/gui/__init__.py index e69de29..882fff9 100644 --- a/src/salome/parametric/gui/__init__.py +++ b/src/salome/parametric/gui/__init__.py @@ -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 . + +import mainpanel + +MainPanel = mainpanel.MainPanel diff --git a/src/salome/parametric/gui/definevalues.py b/src/salome/parametric/gui/definevalues.py index 5bd7bf1..4d9ee27 100644 --- a/src/salome/parametric/gui/definevalues.py +++ b/src/salome/parametric/gui/definevalues.py @@ -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 diff --git a/src/salome/parametric/gui/execparams.py b/src/salome/parametric/gui/execparams.py index 84a8b55..70c26c8 100644 --- a/src/salome/parametric/gui/execparams.py +++ b/src/salome/parametric/gui/execparams.py @@ -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 += " " + var + "" + text += "." + output_var_names = [var.name for var in exchange_vars.outputVarList] + if len(output_var_names) > 0: + text += "
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 += " " + var + "" + 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 diff --git a/src/salome/parametric/gui/execparams.ui b/src/salome/parametric/gui/execparams.ui index 2270933..4a47bcc 100644 --- a/src/salome/parametric/gui/execparams.ui +++ b/src/salome/parametric/gui/execparams.ui @@ -19,7 +19,7 @@ Solver Code - + @@ -119,9 +119,6 @@ - - false - Python Script @@ -143,17 +140,26 @@ 25 - 10 + 13 - - - false - - + + + + + + true + + + + + + + + diff --git a/src/salome/parametric/gui/selectvars.py b/src/salome/parametric/gui/selectvars.py index 274aa22..6f4f04b 100644 --- a/src/salome/parametric/gui/selectvars.py +++ b/src/salome/parametric/gui/selectvars.py @@ -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 diff --git a/src/salome/parametric/gui/wizard.py b/src/salome/parametric/gui/wizard.py index 0dfffb0..6f6e47c 100644 --- a/src/salome/parametric/gui/wizard.py +++ b/src/salome/parametric/gui/wizard.py @@ -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]