From ecf4d5070a51c219dc5e8e8f70406d76d62be6e1 Mon Sep 17 00:00:00 2001 From: barate Date: Fri, 6 Jan 2012 15:24:20 +0000 Subject: [PATCH] Add load / save functions to selectvars widget --- src/GUI_PY/SelectVarsDialog.ui | 255 +++++++++++++++++++-------------- src/GUI_PY/selectvars.py | 31 ++++ 2 files changed, 177 insertions(+), 109 deletions(-) diff --git a/src/GUI_PY/SelectVarsDialog.ui b/src/GUI_PY/SelectVarsDialog.ui index d32b38e43..3dd933421 100644 --- a/src/GUI_PY/SelectVarsDialog.ui +++ b/src/GUI_PY/SelectVarsDialog.ui @@ -6,8 +6,8 @@ 0 0 - 503 - 676 + 611 + 743 @@ -15,80 +15,99 @@ - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - + + Potential Variables List - - - - - - true + + Qt::AlignCenter - - + + - Select + Selected Variables List - - - - - - Qt::Horizontal + + Qt::AlignCenter - - - 40 - 20 - - - + - - - - - - + + - - - All Input Variables + + + Qt::Horizontal - - Qt::AlignCenter + + + 40 + 20 + + + + + + + + Import... - - - QAbstractItemView::MultiSelection + + + Export... + + + + Qt::Horizontal + + + + 40 + 20 + + + + - + + + + All Input Variables + + + Qt::AlignCenter + + + + + + + Selected Input Variables + + + Qt::AlignCenter + + + + + + + QAbstractItemView::MultiSelection + + + + @@ -139,53 +158,41 @@ - - - - - - Selected Input Variables - - - Qt::AlignCenter - - - - - - - QAbstractItemView::MultiSelection - - - - + + + + QAbstractItemView::MultiSelection + + - - - - - - - - - - All Output Variables - - - Qt::AlignCenter - - - - - - - QAbstractItemView::MultiSelection - - - - + + + + All Output Variables + + + Qt::AlignCenter + + - + + + + Selected Output Variables + + + Qt::AlignCenter + + + + + + + QAbstractItemView::MultiSelection + + + + @@ -236,25 +243,55 @@ - - + + + + QAbstractItemView::MultiSelection + + + + + - - - Selected Output Variables + + + Qt::Horizontal - - Qt::AlignCenter + + + 40 + 20 + + + + + + + + true - - - QAbstractItemView::MultiSelection + + + Select + + + + Qt::Horizontal + + + + 40 + 20 + + + + diff --git a/src/GUI_PY/selectvars.py b/src/GUI_PY/selectvars.py index e3a741402..5a523a948 100644 --- a/src/GUI_PY/selectvars.py +++ b/src/GUI_PY/selectvars.py @@ -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))) -- 2.39.2