From: asl Date: Wed, 12 Oct 2016 12:56:08 +0000 (+0300) Subject: Lot 6: implementation of GUI X-Git-Tag: v1.6~14 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=3b5c3cefc3f222a02e27f10f5869a15686961ccc;p=modules%2Fhydrosolver.git Lot 6: implementation of GUI --- diff --git a/src/salome_hydro/interpolz_gui.py b/src/salome_hydro/interpolz_gui.py index 91e4adc..d90b4ce 100644 --- a/src/salome_hydro/interpolz_gui.py +++ b/src/salome_hydro/interpolz_gui.py @@ -1,6 +1,6 @@ import sys, os -sys.path.append(os.path.join(os.environ['MEDFILE_ROOT_DIR'], 'lib\python2.7\site-packages\med')) +sys.path.append(os.path.join(os.environ['MEDFILE_ROOT_DIR'], 'lib/python2.7/site-packages/med')) import salome salome.salome_init() @@ -8,15 +8,25 @@ salome.salome_init() import MEDLoader import HYDROPy -from PyQt4 import QtCore, QtGui -#from interpolzUI import Ui_InterpolZ +from PyQt4 import QtCore, QtGui, uic + +import SalomePyQt +import libSALOME_Swig +salome_gui = libSALOME_Swig.SALOMEGUI_Swig() def get_med_groups( file_path ): - meshes = MEDLoader.MEDLoader_GetMeshNames(file_path) + #print "get_med_groups", file_path + try: + meshes = MEDLoader.MEDLoader_GetMeshNames(file_path) + except: + return [] if len(meshes)==0: return [] mesh1 = meshes[0] - groups = list(MEDLoader.MEDLoader_GetMeshGroupsNames(file_path, mesh1)) + try: + groups = list(MEDLoader.MEDLoader_GetMeshGroupsNames(file_path, mesh1)) + except: + return [] return groups def get_hydro_regions( calc_case_name ): @@ -33,16 +43,63 @@ def get_hydro_regions( calc_case_name ): else: return [] +def get_selected_calc_case(): + ind = SalomePyQt.SalomePyQt.getObjectBrowser().selectionModel().selectedIndexes() + aStudyId = salome.myStudyId + doc = HYDROPy.HYDROData_Document.Document( aStudyId ) + for i in ind: + if i.column()==0: + name = i.data().toString() + case = doc.FindObjectByName( name ) + if isinstance(case, HYDROPy.HYDROData_CalculationCase): + return name + return None + class InterpolzDlg( QtGui.QDialog ): - def __init__(self, parent = None): QtGui.QDialog.__init__( self, parent ) + p = os.path.join(os.environ['HYDROSOLVER_ROOT_DIR'], 'lib', 'python2.7', 'site-packages', 'salome', 'salome', 'hydro') + uic.loadUi( p+'/interpolz.ui', self ) + self.setWindowTitle( 'Generate interpolz script' ) + self.connect( SalomePyQt.SalomePyQt.getObjectBrowser(), QtCore.SIGNAL("selectionChanged()"), self.onSelectionChanged ) + self.connect( self.btnOutputPath, QtCore.SIGNAL( "clicked()" ), self.onOutputFile ) + self.connect( self.btnMEDFile, QtCore.SIGNAL( "clicked()" ), self.onMEDFile ) + self.connect( self.CalcCase, QtCore.SIGNAL( "textChanged( const QString& )" ), self.onCalcCaseChanged ) + self.connect( self.MEDFile, QtCore.SIGNAL( "textChanged( const QString& )" ), self.onMEDChanged ) + + def onSelectionChanged( self ): + calc_case_name = get_selected_calc_case() + if calc_case_name is not None: + self.CalcCase.setText( calc_case_name ) + + def onOutputFile( self ): + caption = "Python file" + mask = "*.py" + f = QtGui.QFileDialog.getSaveFileName( self, caption, ".", mask ) + if f!=None and f!="": + self.OutputPath.setText( f ) + + def onMEDFile( self ): + caption = "MED file" + mask = "*.med" + f = QtGui.QFileDialog.getOpenFileName( self, caption, ".", mask ) + if f!=None and f!="": + self.MEDFile.setText( f ) + + def onCalcCaseChanged( self ): + self.regions = get_hydro_regions( str(self.CalcCase.text()) ) + print self.regions + + def onMEDChanged( self ): + self.med_groups = get_med_groups( str(self.MEDFile.text()) ) + print self.med_groups -#app = QtGui.QApplication( sys.argv ) -#dlg = InterpolzDlg() -#dlg.show() -#app.exec_() +dlg = InterpolzDlg() +dlg.show() +dlg.CalcCase.setText( 'Case_1' ) +dlg.OutputPath.setText( '/dn26/HYDRO/interp1.py' ) +dlg.MEDFile.setText( '/dn26/HYDRO/channel.med' ) #print get_med_groups( "/dn26/HYDRO/channel.med" ) -print get_hydro_regions( "Case_1" ) +#print get_hydro_regions( "Case_1" )