From b79f2ee8477e4668124e638f987498fbb6c4389b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bernard=20S=C3=A9cher=C3=83?= Date: Tue, 19 Jan 2021 14:13:27 +0100 Subject: [PATCH] update CoreFlows GUI from pyqt4 to pyqt5 --- CMakeLists.txt | 1 - CoreFlows/CMakeLists.txt | 7 ++-- CoreFlows/examples/Python/CMakeLists.txt | 23 +++++----- CoreFlows/gui/CMakeLists.txt | 19 ++++++--- CoreFlows/gui/src/CFDesktop.py | 4 +- CoreFlows/gui/src/CoreFlows_Standalone.py | 9 ++-- CoreFlows/gui/src/SalomePyQt_MockUp.py.in | 14 ++++--- CoreFlows/gui/src/ui/MainCFWidget.py | 51 ++++++++++++----------- 8 files changed, 70 insertions(+), 58 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5c85481..ff02f66 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -497,7 +497,6 @@ IF ( NOT HDF5_ROOT_DIR ) ENDIF( ENV{HDF5_ROOT_DIR} ) ENDIF( NOT HDF5_ROOT_DIR ) - #Paraview library paths set (PV_LIB_DIR /usr/lib/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}/dist-packages/paraview/:/usr/lib64/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}/site-packages/vtk/:${MATPLOTLIB_ROOT_DIR}/lib/:${PARAVIEW_LIBRARIES_DIR}) set (PV_PYTHON_DIR /usr/lib/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}/dist-packages/paraview/:/usr/lib64/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}/site-packages/vtk/:/usr/lib64/paraview/site-packages/:/usr/lib64/paraview/site-packages/paraview/:/usr/lib64/paraview/site-packages/vtk/:/usr/lib64/paraview/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}/site-packages/:/usr/lib64/paraview/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}/site-packages/paraview/:/usr/lib64/paraview/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}/site-packages/vtkmodules:/usr/lib/paraview/site-packages/paraview:/usr/lib/paraview/site-packages/paraview/vtk:${PARAVIEW_ROOT_DIR}/lib/:${PARAVIEW_ROOT_DIR}/lib/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}/site-packages/:${PARAVIEW_ROOT_DIR}/lib/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}/site-packages/vtkmodules/:${MATPLOTLIB_ROOT_DIR}/lib/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}/site-packages:${PYQT5_ROOT_DIR}:${PYQT5_ROOT_DIR}/lib/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}/site-packages) diff --git a/CoreFlows/CMakeLists.txt b/CoreFlows/CMakeLists.txt index cfe07a7..7d8aed3 100755 --- a/CoreFlows/CMakeLists.txt +++ b/CoreFlows/CMakeLists.txt @@ -73,10 +73,9 @@ endif () # Graphic interface-----------------------------------------------------------------------------------------# # -if (COREFLOWS_WITH_GUI) # - set (CoreFlows_GUI_DIR ${CoreFlows_SOURCE_DIR}/gui) # - add_subdirectory(${CoreFlows_GUI_DIR}) - +if (COREFLOWS_WITH_GUI) # + set (CoreFlows_GUI_DIR ${CoreFlows_SOURCE_DIR}/gui) # + add_subdirectory(${CoreFlows_GUI_DIR}) endif () # # # ------------- --------------------------------------------------------------------------------------------# diff --git a/CoreFlows/examples/Python/CMakeLists.txt b/CoreFlows/examples/Python/CMakeLists.txt index 3411857..9d085be 100755 --- a/CoreFlows/examples/Python/CMakeLists.txt +++ b/CoreFlows/examples/Python/CMakeLists.txt @@ -1,14 +1,19 @@ # Graphic interface---------------------------------------------------------------------------------------------# # -if (COREFLOWS_WITH_GUI) +if (COREFLOWS_WITH_GUI) + + SET(CONFIGURATION_ROOT_DIR $ENV{CONFIGURATION_ROOT_DIR} CACHE PATH "Path to the Salome CMake configuration files") + IF(EXISTS ${CONFIGURATION_ROOT_DIR}) + LIST(APPEND CMAKE_MODULE_PATH "${CONFIGURATION_ROOT_DIR}/cmake") + INCLUDE(SalomeMacros NO_POLICY_SCOPE) + ELSE() + MESSAGE(FATAL_ERROR "We absolutely need the Salome CMake configuration files, please define CONFIGURATION_ROOT_DIR !") + ENDIF() # # Find KERNEL # ============== SET(KERNEL_ROOT_DIR $ENV{KERNEL_ROOT_DIR} CACHE PATH "Path to the Salome KERNEL") IF( EXISTS ${KERNEL_ROOT_DIR} ) - LIST(APPEND CMAKE_MODULE_PATH "${KERNEL_ROOT_DIR}/salome_adm/cmake_files") - LIST(APPEND CMAKE_PREFIX_PATH "${KERNEL_ROOT_DIR}/salome_adm/cmake_files") - INCLUDE(SalomeMacros) FIND_PACKAGE(SalomeKERNEL REQUIRED) ELSE( EXISTS ${KERNEL_ROOT_DIR} ) MESSAGE(FATAL_ERROR "We absolutely need a Salome KERNEL, please define KERNEL_ROOT_DIR!") @@ -18,8 +23,6 @@ if (COREFLOWS_WITH_GUI) # ============== SET(GUI_ROOT_DIR $ENV{GUI_ROOT_DIR} CACHE PATH "Path to the Salome GUI") IF(EXISTS ${GUI_ROOT_DIR}) - LIST(APPEND CMAKE_MODULE_PATH "${GUI_ROOT_DIR}/adm_local/cmake_files") - LIST(APPEND CMAKE_PREFIX_PATH "${GUI_ROOT_DIR}/adm_local/cmake_files") FIND_PACKAGE(SalomeGUI) ELSE(EXISTS ${GUI_ROOT_DIR}) MESSAGE(FATAL_ERROR "We absolutely need a Salome GUI, please define GUI_ROOT_DIR!") @@ -33,12 +36,8 @@ if (COREFLOWS_WITH_GUI) # ============= # Mandatory products - IF( $ENV{PARAVIEW_VERSION} STRLESS "5") - FIND_PACKAGE(SalomePython REQUIRED) - ELSE() - FIND_PACKAGE(SalomePythonInterp REQUIRED) - FIND_PACKAGE(SalomePythonLibs REQUIRED) - ENDIF() +# FIND_PACKAGE(SalomePythonInterp REQUIRED) +# FIND_PACKAGE(SalomePythonLibs REQUIRED) SET(_all_SCRIPTS main_tests.py diff --git a/CoreFlows/gui/CMakeLists.txt b/CoreFlows/gui/CMakeLists.txt index 9fb0d38..1009e35 100755 --- a/CoreFlows/gui/CMakeLists.txt +++ b/CoreFlows/gui/CMakeLists.txt @@ -16,6 +16,9 @@ # # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # +cmake_minimum_required (VERSION 3.1) +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED ON) INCLUDE(CMakeDependentOption) # Versioning @@ -35,13 +38,20 @@ SET(${PROJECT_NAME_UC}_VERSION_DEV 1) OPTION(SALOME_BUILD_DOC "Generate SALOME CoreFlows documentation" ON) OPTION(SALOME_BUILD_TESTS "Generate SALOME CoreFlows tests" ON) +# Common CMake macros +# =================== +SET(CONFIGURATION_ROOT_DIR $ENV{CONFIGURATION_ROOT_DIR} CACHE PATH "Path to the Salome CMake configuration files") +IF(EXISTS ${CONFIGURATION_ROOT_DIR}) + LIST(APPEND CMAKE_MODULE_PATH "${CONFIGURATION_ROOT_DIR}/cmake") + INCLUDE(SalomeMacros NO_POLICY_SCOPE) +ELSE() + MESSAGE(FATAL_ERROR "We absolutely need the Salome CMake configuration files, please define CONFIGURATION_ROOT_DIR !") +ENDIF() # Find KERNEL # ============== SET(KERNEL_ROOT_DIR $ENV{KERNEL_ROOT_DIR} CACHE PATH "Path to the Salome KERNEL") IF( EXISTS ${KERNEL_ROOT_DIR} ) - LIST(APPEND CMAKE_MODULE_PATH "${KERNEL_ROOT_DIR}/salome_adm/cmake_files") - INCLUDE(SalomeMacros) FIND_PACKAGE(SalomeKERNEL REQUIRED) ELSE( EXISTS ${KERNEL_ROOT_DIR} ) MESSAGE(FATAL_ERROR "We absolutely need a Salome KERNEL, please define KERNEL_ROOT_DIR!") @@ -51,7 +61,6 @@ ENDIF( EXISTS ${KERNEL_ROOT_DIR} ) # ============== SET(GUI_ROOT_DIR $ENV{GUI_ROOT_DIR} CACHE PATH "Path to the Salome GUI") IF(EXISTS ${GUI_ROOT_DIR}) - LIST(APPEND CMAKE_MODULE_PATH "${GUI_ROOT_DIR}/adm_local/cmake_files") FIND_PACKAGE(SalomeGUI) ELSE(EXISTS ${GUI_ROOT_DIR}) MESSAGE(FATAL_ERROR "We absolutely need a Salome GUI, please define GUI_ROOT_DIR!") @@ -73,8 +82,8 @@ ELSE() ENDIF() MESSAGE(STATUS "SalomeKERNEL_VERSION is ${SalomeKERNEL_VERSION}") -# Qt4 -FIND_PACKAGE(SalomeQt4 REQUIRED COMPONENTS QtCore QtGui) +# Qt5 +FIND_PACKAGE(SalomeQt5 REQUIRED COMPONENTS QtCore QtGui) IF(SALOME_BUILD_DOC) # FIND_PACKAGE(SalomeDoxygen) diff --git a/CoreFlows/gui/src/CFDesktop.py b/CoreFlows/gui/src/CFDesktop.py index e70c4d9..df83296 100755 --- a/CoreFlows/gui/src/CFDesktop.py +++ b/CoreFlows/gui/src/CFDesktop.py @@ -23,8 +23,8 @@ # Author : A. Bruneton # -from PyQt4.QtCore import Qt -from PyQt4.QtGui import QMainWindow,QMenu, QDockWidget +from PyQt5.QtCore import Qt +from PyQt5.QtWidgets import QMainWindow,QMenu, QDockWidget from MainCFWidget import MainCFWidget class CFDesktop(QMainWindow): diff --git a/CoreFlows/gui/src/CoreFlows_Standalone.py b/CoreFlows/gui/src/CoreFlows_Standalone.py index ca9f9f5..37db116 100755 --- a/CoreFlows/gui/src/CoreFlows_Standalone.py +++ b/CoreFlows/gui/src/CoreFlows_Standalone.py @@ -23,12 +23,12 @@ # Author : A. Bruneton # import sys, os -from PyQt4.QtGui import QApplication -from PyQt4.QtCore import SIGNAL, SLOT +from PyQt5.QtWidgets import QApplication +#from PyQt5.QtCore import SIGNAL, SLOT from CFDesktop import CFDesktop import SalomePyQt_MockUp -from PyQt4.QtCore import QTimer, QTranslator, Qt +from PyQt5.QtCore import QTimer, QTranslator, Qt desktop = None @@ -52,7 +52,8 @@ def main(args) : # - app.connect(app,SIGNAL("lastWindowClosed()"),app,SLOT("quit()")) +# app.connect(app,SIGNAL("lastWindowClosed()"),app,SLOT("quit()")) + app.lastWindowClosed.connect(quit) app.exec_() if __name__ == "__main__" : diff --git a/CoreFlows/gui/src/SalomePyQt_MockUp.py.in b/CoreFlows/gui/src/SalomePyQt_MockUp.py.in index a09d5de..f0b8af1 100755 --- a/CoreFlows/gui/src/SalomePyQt_MockUp.py.in +++ b/CoreFlows/gui/src/SalomePyQt_MockUp.py.in @@ -22,9 +22,11 @@ # Author : A. Bruneton # -from PyQt4.QtGui import QApplication, QTabWidget -from PyQt4.QtGui import QAction, QMenu, QIcon, QPixmap, QDesktopWidget, QFileDialog -from PyQt4.QtCore import SIGNAL, SLOT, QObject, pyqtSlot, pyqtSignal +from PyQt5.QtWidgets import QApplication, QTabWidget +from PyQt5.QtWidgets import QAction, QMenu, QDesktopWidget, QFileDialog +from PyQt5.QtGui import QIcon, QPixmap +#from PyQt5.QtCore import SIGNAL, SLOT, QObject, pyqtSlot, pyqtSignal +from PyQt5.QtCore import QObject, pyqtSlot, pyqtSignal RESOURCE_DIR = "@SGPYQT_RES_DIR@" @@ -47,7 +49,8 @@ class SalomePyQt(QObject): if self._mainWindow: self._menuBar = self._mainWindow.menuBar() self._mainWindow.setCentralWidget(self._tabWidget) - self.connect(self._tabWidget, SIGNAL("currentChanged(int)"), self, SLOT("onTabChanged(int)")) +# self.connect(self._tabWidget, SIGNAL("currentChanged(int)"), self, SLOT("onTabChanged(int)")) + self._tabWidget.currentChanged.connect(self.onTabChanged) self._blockSignal = False def getDesktop(self): @@ -63,7 +66,8 @@ class SalomePyQt(QObject): if self._blockSignal: return invDict = dict([(v, k) for k,v in self._viewIDs.items()]) - if invDict.has_key(index): + if index in invDict: +# if invDict.has_key(index): self._blockSignal = True self.currentTabChanged.emit(invDict[index]) self._blockSignal = False diff --git a/CoreFlows/gui/src/ui/MainCFWidget.py b/CoreFlows/gui/src/ui/MainCFWidget.py index 9aaeabd..60e6fe2 100755 --- a/CoreFlows/gui/src/ui/MainCFWidget.py +++ b/CoreFlows/gui/src/ui/MainCFWidget.py @@ -1,27 +1,28 @@ -from PyQt4 import QtGui, QtCore -from PyQt4.uic import loadUi +# -*- coding: utf-8 -*- +from PyQt5 import QtWidgets, QtCore +from PyQt5.uic import loadUi from utils import completeResPath import CoreFlows as cf import cdmath as cm -class MainCFWidget(QtGui.QTabWidget): +class MainCFWidget(QtWidgets.QTabWidget): def __init__(self): - QtGui.QTabWidget.__init__(self) + QtWidgets.QTabWidget.__init__(self) loadUi(completeResPath("MainCFWidget.ui"), self) self._python_dump = [] def scanWidgets(self): - print self.tabModel + print(self.tabModel) dictCF={} for k in self.__dict__: att = self.__dict__[k] - if isinstance(att, QtGui.QWidget): + if isinstance(att, QtWidgets.QWidget): name = str(att.objectName()) if name != "": # print(name) if name.endswith("RadioButton"): - assert(isinstance(att, QtGui.QRadioButton)) + assert(isinstance(att, QtWidgets.QRadioButton)) if att.isChecked() : # parse name name=name[:len(name)-len("_RadioButton")]#On retire le suffixe _Radiobutton @@ -34,7 +35,7 @@ class MainCFWidget(QtGui.QTabWidget): elif name=="MeshCreation" : dictCF["MeshCreation"]=True elif name.endswith("spinBox") : - assert(isinstance(att, QtGui.QSpinBox)) + assert(isinstance(att, QtWidgets.QSpinBox)) val = att.value() # parse name name=name[:len(name)-len("_spinBox")]#On retire le suffixe _SpinBox @@ -49,7 +50,7 @@ class MainCFWidget(QtGui.QTabWidget): elif name=="NO_FreqSave" : dictCF["FreqSave"]=val elif name.endswith("doubleSpinBox"): - assert(isinstance(att, QtGui.QDoubleSpinBox)) + assert(isinstance(att, QtWidgets.QDoubleSpinBox)) val = att.value() # parse name name=name[:len(name)-len("_doubleSpinBox")]#On retire le suffixe _doubleSpinBox @@ -113,7 +114,7 @@ class MainCFWidget(QtGui.QTabWidget): name=name[3:len(name)-len("_BC")]#On retire le préfixe SP_ ou DM_ au début et le suffixe _BC à la fin dictCF[name]=val elif name.endswith('comboBox'): - assert(isinstance(att, QtGui.QComboBox)) + assert(isinstance(att, QtWidgets.QComboBox)) val = att.currentText() # parse name name=name[:len(name)-len("_comboBox")]#On retire le suffixe _comboBox @@ -135,7 +136,7 @@ class MainCFWidget(QtGui.QTabWidget): elif name=="NO_Preconditioner" : dictCF["Preconditioner"]=val elif name.endswith('lineEdit'): - assert(isinstance(att, QtGui.QLineEdit)) + assert(isinstance(att, QtWidgets.QLineEdit)) val = str(att.text()) # parse name name=name[:len(name)-len("_lineEdit")]#On retire le suffixe _comboBox @@ -148,13 +149,13 @@ class MainCFWidget(QtGui.QTabWidget): return dictCF def onLaunchSimu(self): - print "Reading widgets" + print("Reading widgets") dictCF = self.scanWidgets() - print "Setting Model and VV_Constant" + print("Setting Model and VV_Constant") ######## Setting Model and VV_Constant ######################### if dictCF["ModelName"]=="SinglePhase" : - exec "myProblem = cf.%s(cf.%s,cf.%s,%s)" % (dictCF["ModelName"],dictCF["fluidType"],dictCF["pressureEstimate"],dictCF["spaceDim"]) + exec("myProblem = cf.%s(cf.%s,cf.%s,%s)" % (dictCF["ModelName"],dictCF["fluidType"],dictCF["pressureEstimate"],dictCF["spaceDim"])) nVar = myProblem.getNumberOfVariables() VV_Constant =[0]*nVar VV_Constant[0] = dictCF["InitialPressure"] @@ -165,7 +166,7 @@ class MainCFWidget(QtGui.QTabWidget): VV_Constant[3] = dictCF["InitialVelocity_3d"] VV_Constant[nVar-1] = dictCF["InitialTemperature"] elif dictCF["ModelName"]=="DriftModel" : - exec "myProblem = cf.%s(cf.%s,%s)" % (dictCF["ModelName"],dictCF["pressureEstimate"],dictCF["spaceDim"]) + exec("myProblem = cf.%s(cf.%s,%s)" % (dictCF["ModelName"],dictCF["pressureEstimate"],dictCF["spaceDim"])) nVar = myProblem.getNumberOfVariables() VV_Constant =[0]*nVar VV_Constant[0] = dictCF["InitialConcentration"] @@ -177,18 +178,18 @@ class MainCFWidget(QtGui.QTabWidget): VV_Constant[4] = dictCF["InitialVelocity_3d"] VV_Constant[nVar-1] = dictCF["InitialTemperature"] else : - raise NameError('Model not yet handled', dictCF["ModelName"]) + raise NameError('Model not yet handled', dictCF["ModelName"]) - print "Setting initial data" + print("Setting initial data") ############ setting initial data ################################ if dictCF["spaceDim"] ==1 : - print "spaceDim= ", dictCF["spaceDim"] - print "VV_Constant= ", VV_Constant - print "Xinf= ", dictCF["Xinf"] - print "Xsup= ", dictCF["Xsup"] - print "Nx= ", dictCF["Nx"] + print("spaceDim= ", dictCF["spaceDim"]) + print("VV_Constant= ", VV_Constant) + print("Xinf= ", dictCF["Xinf"]) + print("Xsup= ", dictCF["Xsup"]) + print("Nx= ", dictCF["Nx"]) myProblem.setInitialFieldConstant( dictCF["spaceDim"], VV_Constant, dictCF["Xinf"], dictCF["Xsup"], dictCF["Nx"],"Left","Right"); - print "Initial field set" + print("Initial field set") elif dictCF["spaceDim"] ==2 : myProblem.setInitialFieldConstant( dictCF["spaceDim"], VV_Constant, dictCF["Xinf"], dictCF["Xsup"], dictCF["Nx"],"Left","Right", dictCF["Yinf"], dictCF["Ysup"], dictCF["Ny"],"Bottom","Top"); elif dictCF["spaceDim"] ==3 : @@ -198,7 +199,7 @@ class MainCFWidget(QtGui.QTabWidget): # for k, v in dictCF.items(): # line = "cf.set%s(%s)" % (k, v) -# #exec line +# #exec(line) # self._python_dump.append(line) ######## 1D for the moment ###################### @@ -220,7 +221,7 @@ class MainCFWidget(QtGui.QTabWidget): myProblem.setGravity(gravite) ########## Numerical options ############### - exec "myProblem.setNumericalScheme(cf.%s, cf.%s)" % (dictCF["Scheme"],dictCF["Method"]) + exec("myProblem.setNumericalScheme(cf.%s, cf.%s)" % (dictCF["Scheme"],dictCF["Method"])) myProblem.setWellBalancedCorrection(True); myProblem.setCFL(dictCF["CFL"]); -- 2.39.2