]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
Added the possibility to edit an existing Variables object
authorbarate <barate>
Thu, 17 Feb 2011 14:58:29 +0000 (14:58 +0000)
committerbarate <barate>
Thu, 17 Feb 2011 14:58:29 +0000 (14:58 +0000)
src/GUI_PY/SelectVarsDialog.ui
src/GUI_PY/selectvars.py

index 6327787b1633305770eb96446b93752ebd930514..d32b38e43e61ff062b4400934d2967c6e8ac6ef5 100644 (file)
@@ -32,7 +32,7 @@
      <item>
       <widget class="QLabel" name="label">
        <property name="text">
-        <string>Variables List</string>
+        <string>Potential Variables List</string>
        </property>
       </widget>
      </item>
index 6756268882a5f9d8c77c703313ec3b576fb968fa..5dfe731e42e7426941aeebea32c596a8be875340 100644 (file)
@@ -25,6 +25,7 @@ from PyQt4.QtCore import Qt
 
 import salome
 from salome.kernel.studyedit import getStudyEditor
+from salome.kernel import varlist
 
 # ---------------------------------- #
 # Dialog box for variables selection #
@@ -40,35 +41,48 @@ class MySelectVarsDialog(Ui_SelectVarsDialog, QtGui.QDialog):
         self.setupUi(self)
         self.connect(self.cancelButton, QtCore.SIGNAL("clicked()"), self.close)
         self.connect(self.OKButton, QtCore.SIGNAL("clicked()"), self.accept)
-        self.connect(self.selectButton, QtCore.SIGNAL("clicked()"), self.initSelectedVarList)
+        self.connect(self.selectButton, QtCore.SIGNAL("clicked()"), self.initPotentialVariablesFromSelection)
         self.connect(self.addInputVarButton, QtCore.SIGNAL("clicked()"), self.addSelectedInputVar)
         self.connect(self.removeInputVarButton, QtCore.SIGNAL("clicked()"), self.removeSelectedInputVar)
         self.connect(self.newInputVarButton, QtCore.SIGNAL("clicked()"), self.newInputVar)
         self.connect(self.addOutputVarButton, QtCore.SIGNAL("clicked()"), self.addSelectedOutputVar)
         self.connect(self.removeOutputVarButton, QtCore.SIGNAL("clicked()"), self.removeSelectedOutputVar)
         self.connect(self.newOutputVarButton, QtCore.SIGNAL("clicked()"), self.newOutputVar)
+        self.refEntry = None
 
-    def initSelectedVarList(self):
+    def setExchangeVariables(self, exchangeVariables):
+        if exchangeVariables.refEntry is not None:
+            self._initPotentialVariables(exchangeVariables.refEntry)
+        self.selectedInputVarListWidget.addItems([x.name for x in exchangeVariables.inputVarList])
+        self.selectedOutputVarListWidget.addItems([x.name for x in exchangeVariables.outputVarList])
+
+    def initPotentialVariablesFromSelection(self):
         entries = salome.sg.getAllSelected()
         if len(entries) != 1 :
             QtGui.QMessageBox.warning(self, self.tr("Error"),
                                       self.tr("One item must be selected in the object browser"))
             return
         selectedEntry = entries[0]
-        sobj = getStudyEditor().study.FindObjectID(selectedEntry)
-        from salome.kernel import varlist
-        (inputVarList, outputVarList) = varlist.getVarList(sobj)
-        if inputVarList is None and outputVarList is None:
+        self._initPotentialVariables(selectedEntry)
+
+    def _initPotentialVariables(self, entry):
+        sobj = getStudyEditor().study.FindObjectID(entry)
+        if sobj is None:
+            QtGui.QMessageBox.warning(self, self.tr("Error"),
+                                      self.tr('No item at entry %s' % entry))
+            return
+        exchangeVariables = varlist.getExchangeVariablesFromSObject(sobj)
+        if exchangeVariables is None:
             QtGui.QMessageBox.warning(self, self.tr("Error"),
-                                      self.tr('Selected item is not a valid "Variable List" object'))
+                                      self.tr('Item at entry %s is not a valid '
+                                              '"Variable List" object' % entry))
             return
+        self.refEntry = entry
         self.varListObjLineEdit.setText(sobj.GetName())
         self.allInputVarListWidget.clear()
         self.allOutputVarListWidget.clear()
-        if inputVarList is not None:
-            self.allInputVarListWidget.addItems(inputVarList)
-        if outputVarList is not None:
-            self.allOutputVarListWidget.addItems(outputVarList)
+        self.allInputVarListWidget.addItems([x.name for x in exchangeVariables.inputVarList])
+        self.allOutputVarListWidget.addItems([x.name for x in exchangeVariables.outputVarList])
 
     def addSelectedInputVar(self):
         for item in self.allInputVarListWidget.selectedItems():
@@ -96,11 +110,11 @@ class MySelectVarsDialog(Ui_SelectVarsDialog, QtGui.QDialog):
         newItem.setFlags(Qt.ItemIsSelectable|Qt.ItemIsEditable|Qt.ItemIsUserCheckable|Qt.ItemIsEnabled)
         self.selectedOutputVarListWidget.addItem(newItem);
 
-    def getSelectedVarLists(self):
+    def getSelectedExchangeVariables(self):
         inputVarList = []
         outputVarList = []
         for row in range(self.selectedInputVarListWidget.count()):
-            inputVarList.append(str(self.selectedInputVarListWidget.item(row).text()))
+            inputVarList.append(varlist.Variable(str(self.selectedInputVarListWidget.item(row).text())))
         for row in range(self.selectedOutputVarListWidget.count()):
-            outputVarList.append(str(self.selectedOutputVarListWidget.item(row).text()))
-        return (inputVarList, outputVarList)
+            outputVarList.append(varlist.Variable(str(self.selectedOutputVarListWidget.item(row).text())))
+        return varlist.ExchangeVariables(inputVarList, outputVarList, self.refEntry)