]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
Add load / save functions to selectvars widget
authorbarate <barate>
Fri, 6 Jan 2012 15:24:20 +0000 (15:24 +0000)
committerbarate <barate>
Fri, 6 Jan 2012 15:24:20 +0000 (15:24 +0000)
src/GUI_PY/SelectVarsDialog.ui
src/GUI_PY/selectvars.py

index d32b38e43e61ff062b4400934d2967c6e8ac6ef5..3dd9334217fec5f8be18b248b6240a4b197643bf 100644 (file)
@@ -6,8 +6,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>503</width>
-    <height>676</height>
+    <width>611</width>
+    <height>743</height>
    </rect>
   </property>
   <property name="windowTitle">
   </property>
   <layout class="QVBoxLayout" name="verticalLayout">
    <item>
-    <layout class="QHBoxLayout" name="horizontalLayout_2">
-     <item>
-      <spacer name="horizontalSpacer_4">
-       <property name="orientation">
-        <enum>Qt::Horizontal</enum>
-       </property>
-       <property name="sizeHint" stdset="0">
-        <size>
-         <width>40</width>
-         <height>20</height>
-        </size>
-       </property>
-      </spacer>
-     </item>
-     <item>
+    <layout class="QGridLayout" name="gridLayout">
+     <item row="0" column="0">
       <widget class="QLabel" name="label">
        <property name="text">
         <string>Potential Variables List</string>
        </property>
-      </widget>
-     </item>
-     <item>
-      <widget class="QLineEdit" name="varListObjLineEdit">
-       <property name="readOnly">
-        <bool>true</bool>
+       <property name="alignment">
+        <set>Qt::AlignCenter</set>
        </property>
       </widget>
      </item>
-     <item>
-      <widget class="QPushButton" name="selectButton">
+     <item row="0" column="2">
+      <widget class="QLabel" name="label_6">
        <property name="text">
-        <string>Select</string>
+        <string>Selected Variables List</string>
        </property>
-      </widget>
-     </item>
-     <item>
-      <spacer name="horizontalSpacer_3">
-       <property name="orientation">
-        <enum>Qt::Horizontal</enum>
+       <property name="alignment">
+        <set>Qt::AlignCenter</set>
        </property>
-       <property name="sizeHint" stdset="0">
-        <size>
-         <width>40</width>
-         <height>20</height>
-        </size>
-       </property>
-      </spacer>
+      </widget>
      </item>
-    </layout>
-   </item>
-   <item>
-    <layout class="QHBoxLayout" name="horizontalLayout_4">
-     <item>
-      <layout class="QVBoxLayout" name="verticalLayout_5">
+     <item row="1" column="2">
+      <layout class="QHBoxLayout" name="horizontalLayout_2">
        <item>
-        <widget class="QLabel" name="label_4">
-         <property name="text">
-          <string>All Input Variables</string>
+        <spacer name="horizontalSpacer_6">
+         <property name="orientation">
+          <enum>Qt::Horizontal</enum>
          </property>
-         <property name="alignment">
-          <set>Qt::AlignCenter</set>
+         <property name="sizeHint" stdset="0">
+          <size>
+           <width>40</width>
+           <height>20</height>
+          </size>
+         </property>
+        </spacer>
+       </item>
+       <item>
+        <widget class="QPushButton" name="loadVarsButton">
+         <property name="text">
+          <string>Import...</string>
          </property>
         </widget>
        </item>
        <item>
-        <widget class="QListWidget" name="allInputVarListWidget">
-         <property name="selectionMode">
-          <enum>QAbstractItemView::MultiSelection</enum>
+        <widget class="QPushButton" name="saveVarsButton">
+         <property name="text">
+          <string>Export...</string>
          </property>
         </widget>
        </item>
+       <item>
+        <spacer name="horizontalSpacer_5">
+         <property name="orientation">
+          <enum>Qt::Horizontal</enum>
+         </property>
+         <property name="sizeHint" stdset="0">
+          <size>
+           <width>40</width>
+           <height>20</height>
+          </size>
+         </property>
+        </spacer>
+       </item>
       </layout>
      </item>
-     <item>
+     <item row="2" column="0">
+      <widget class="QLabel" name="label_4">
+       <property name="text">
+        <string>All Input Variables</string>
+       </property>
+       <property name="alignment">
+        <set>Qt::AlignCenter</set>
+       </property>
+      </widget>
+     </item>
+     <item row="2" column="2">
+      <widget class="QLabel" name="label_5">
+       <property name="text">
+        <string>Selected Input Variables</string>
+       </property>
+       <property name="alignment">
+        <set>Qt::AlignCenter</set>
+       </property>
+      </widget>
+     </item>
+     <item row="3" column="0">
+      <widget class="QListWidget" name="allInputVarListWidget">
+       <property name="selectionMode">
+        <enum>QAbstractItemView::MultiSelection</enum>
+       </property>
+      </widget>
+     </item>
+     <item row="3" column="1">
       <layout class="QVBoxLayout" name="verticalLayout_6">
        <item>
         <spacer name="verticalSpacer_3">
        </item>
       </layout>
      </item>
-     <item>
-      <layout class="QVBoxLayout" name="verticalLayout_7">
-       <item>
-        <widget class="QLabel" name="label_5">
-         <property name="text">
-          <string>Selected Input Variables</string>
-         </property>
-         <property name="alignment">
-          <set>Qt::AlignCenter</set>
-         </property>
-        </widget>
-       </item>
-       <item>
-        <widget class="QListWidget" name="selectedInputVarListWidget">
-         <property name="selectionMode">
-          <enum>QAbstractItemView::MultiSelection</enum>
-         </property>
-        </widget>
-       </item>
-      </layout>
+     <item row="3" column="2">
+      <widget class="QListWidget" name="selectedInputVarListWidget">
+       <property name="selectionMode">
+        <enum>QAbstractItemView::MultiSelection</enum>
+       </property>
+      </widget>
      </item>
-    </layout>
-   </item>
-   <item>
-    <layout class="QHBoxLayout" name="horizontalLayout_3">
-     <item>
-      <layout class="QVBoxLayout" name="verticalLayout_3">
-       <item>
-        <widget class="QLabel" name="label_2">
-         <property name="text">
-          <string>All Output Variables</string>
-         </property>
-         <property name="alignment">
-          <set>Qt::AlignCenter</set>
-         </property>
-        </widget>
-       </item>
-       <item>
-        <widget class="QListWidget" name="allOutputVarListWidget">
-         <property name="selectionMode">
-          <enum>QAbstractItemView::MultiSelection</enum>
-         </property>
-        </widget>
-       </item>
-      </layout>
+     <item row="4" column="0">
+      <widget class="QLabel" name="label_2">
+       <property name="text">
+        <string>All Output Variables</string>
+       </property>
+       <property name="alignment">
+        <set>Qt::AlignCenter</set>
+       </property>
+      </widget>
      </item>
-     <item>
+     <item row="4" column="2">
+      <widget class="QLabel" name="label_3">
+       <property name="text">
+        <string>Selected Output Variables</string>
+       </property>
+       <property name="alignment">
+        <set>Qt::AlignCenter</set>
+       </property>
+      </widget>
+     </item>
+     <item row="5" column="0">
+      <widget class="QListWidget" name="allOutputVarListWidget">
+       <property name="selectionMode">
+        <enum>QAbstractItemView::MultiSelection</enum>
+       </property>
+      </widget>
+     </item>
+     <item row="5" column="1">
       <layout class="QVBoxLayout" name="verticalLayout_2">
        <item>
         <spacer name="verticalSpacer_2">
        </item>
       </layout>
      </item>
-     <item>
-      <layout class="QVBoxLayout" name="verticalLayout_4">
+     <item row="5" column="2">
+      <widget class="QListWidget" name="selectedOutputVarListWidget">
+       <property name="selectionMode">
+        <enum>QAbstractItemView::MultiSelection</enum>
+       </property>
+      </widget>
+     </item>
+     <item row="1" column="0">
+      <layout class="QHBoxLayout" name="horizontalLayout_5">
        <item>
-        <widget class="QLabel" name="label_3">
-         <property name="text">
-          <string>Selected Output Variables</string>
+        <spacer name="horizontalSpacer_4">
+         <property name="orientation">
+          <enum>Qt::Horizontal</enum>
          </property>
-         <property name="alignment">
-          <set>Qt::AlignCenter</set>
+         <property name="sizeHint" stdset="0">
+          <size>
+           <width>40</width>
+           <height>20</height>
+          </size>
+         </property>
+        </spacer>
+       </item>
+       <item>
+        <widget class="QLineEdit" name="varListObjLineEdit">
+         <property name="readOnly">
+          <bool>true</bool>
          </property>
         </widget>
        </item>
        <item>
-        <widget class="QListWidget" name="selectedOutputVarListWidget">
-         <property name="selectionMode">
-          <enum>QAbstractItemView::MultiSelection</enum>
+        <widget class="QPushButton" name="selectButton">
+         <property name="text">
+          <string>Select</string>
          </property>
         </widget>
        </item>
+       <item>
+        <spacer name="horizontalSpacer_3">
+         <property name="orientation">
+          <enum>Qt::Horizontal</enum>
+         </property>
+         <property name="sizeHint" stdset="0">
+          <size>
+           <width>40</width>
+           <height>20</height>
+          </size>
+         </property>
+        </spacer>
+       </item>
       </layout>
      </item>
     </layout>
index e3a741402b5debc8f43bef6205b669e884a8e6b6..5a523a94878b93841ac02395f0b39b6ba3f0ce09 100644 (file)
@@ -20,6 +20,7 @@
 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 #
 
+import os
 from PyQt4 import QtGui, QtCore
 from PyQt4.QtCore import Qt
 
@@ -48,6 +49,8 @@ class MySelectVarsDialog(Ui_SelectVarsDialog, QtGui.QDialog):
         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.connect(self.loadVarsButton, QtCore.SIGNAL("clicked()"), self.loadVars)
+        self.connect(self.saveVarsButton, QtCore.SIGNAL("clicked()"), self.saveVars)
         self.refEntry = None
 
     def setExchangeVariables(self, exchangeVariables):
@@ -120,3 +123,31 @@ class MySelectVarsDialog(Ui_SelectVarsDialog, QtGui.QDialog):
             name = str(self.selectedOutputVarListWidget.item(row).text())
             outputVarList.append(study_exchange_vars.Variable(name))
         return study_exchange_vars.ExchangeVariables(inputVarList, outputVarList, self.refEntry)
+
+    def loadVars(self):
+        filename = QtGui.QFileDialog.getOpenFileName(self, self.tr("Import variables from file"),
+                                                     os.getenv("HOME"),
+                                                     self.tr("XML Files (*.xml)"))
+        if not filename:
+            return
+        try:
+            filename = str(filename)
+            exchange_variables = study_exchange_vars.loadExchangeVariablesFromXmlFile(filename)
+            self.setExchangeVariables(exchange_variables)
+        except Exception, e:
+            QtGui.QMessageBox.critical(self, self.tr("Error"),
+                                       self.tr("Cannot load file %s:\n%s" % (filename, e)))
+
+    def saveVars(self):
+        default = os.path.join(os.getenv("HOME"), "vars.xml")
+        filename = QtGui.QFileDialog.getSaveFileName(self, self.tr("Export variables to file"),
+                                                     default, self.tr("XML Files (*.xml)"))
+        if not filename:
+            return
+        try:
+            filename = str(filename)
+            exchange_variables = self.getSelectedExchangeVariables()
+            exchange_variables.saveToXmlFile(filename)
+        except Exception, e:
+            QtGui.QMessageBox.critical(self, self.tr("Error"),
+                                       self.tr("Cannot save file %s:\n%s" % (filename, e)))