From a262b236816cce16866243b1bffeede67cb5ebe9 Mon Sep 17 00:00:00 2001 From: Jean-Philippe ARGAUD Date: Fri, 26 Aug 2016 14:56:13 +0200 Subject: [PATCH] Switching from QT4 to QT4+QT5 support (keeping compatibility with EFICAS) --- bin/module_version.py | 2 +- src/daEficas/configuration_ADAO.py | 6 ++++- .../daEficasWrapper/adaoEficasWrapper.py | 18 ++++++++++--- src/daSalome/daGUI/daGuiImpl/ADAOGUI_impl.py | 16 +++++++----- src/daSalome/daGUI/daGuiImpl/adaoGuiHelper.py | 6 ++++- .../daGUI/daGuiImpl/adaoGuiManager.py | 19 ++++++++++---- .../daGUI/daGuiImpl/adaoModuleHelper.py | 6 ++++- src/daSalome/daGUI/daUtils/Makefile.am | 1 + src/daSalome/daGUI/daUtils/qtversion.py | 26 +++++++++++++++++++ 9 files changed, 81 insertions(+), 19 deletions(-) create mode 100644 src/daSalome/daGUI/daUtils/qtversion.py diff --git a/bin/module_version.py b/bin/module_version.py index 3e6a584..d4202d3 100644 --- a/bin/module_version.py +++ b/bin/module_version.py @@ -23,6 +23,6 @@ # Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D name = "ADAO" -version = "V7_8_0" # Version pour catalogue, avec des "_" entre les numeros +version = "V8_1_0" # Version pour catalogue, avec des "_" entre les numeros date = "" year = "2016" # Annee de copyright diff --git a/src/daEficas/configuration_ADAO.py b/src/daEficas/configuration_ADAO.py index 026263c..fee72b5 100644 --- a/src/daEficas/configuration_ADAO.py +++ b/src/daEficas/configuration_ADAO.py @@ -29,7 +29,11 @@ # print "passage dans la surcharge de configuration pour Adao" import os, sys, string, types, re import traceback -from PyQt4.QtGui import * +from daUtils.qtversion import useQT5 +if useQT5: + from PyQt5.QtGui import * +else: + from PyQt4.QtGui import * # Modules Eficas from Editeur import utils diff --git a/src/daSalome/daGUI/daEficasWrapper/adaoEficasWrapper.py b/src/daSalome/daGUI/daEficasWrapper/adaoEficasWrapper.py index bc7063e..8e2116e 100644 --- a/src/daSalome/daGUI/daEficasWrapper/adaoEficasWrapper.py +++ b/src/daSalome/daGUI/daEficasWrapper/adaoEficasWrapper.py @@ -25,9 +25,14 @@ import os import eficasSalome # Import from EFICAS_SRC from InterfaceQT4 import qtEficas # Import from Eficas -from PyQt4.QtGui import * # Import from PyQT -from PyQt4.QtCore import * # Import from PyQT -# from PyQt4.QtAssistant import * # Import from PyQT +from daUtils.qtversion import useQT5 +if useQT5: + from PyQt5.QtGui import * # Import from PyQT + from PyQt5.QtCore import * # Import from PyQT +else: + from PyQt4.QtGui import * # Import from PyQT + from PyQt4.QtCore import * # Import from PyQT + # from PyQt5.QtAssistant import * # Import from PyQT from daUtils.adaoEficasEvent import * from daUtils.adaoLogger import * @@ -51,9 +56,14 @@ class AdaoEficasWrapper(eficasSalome.MyEficas): def init_gui(self): eficasSalome.MyEficas.__init__(self, self.__parent, code="ADAO", module="ADAO") - self.connect(self.viewmanager.myQtab, SIGNAL('currentChanged(int)'), self.tabChanged) + if useQT5: + self.viewmanager.myQtab.currentChanged.connect(self.tabChanged) + else: + self.connect(self.viewmanager.myQtab, SIGNAL('currentChanged(int)'), self.tabChanged) self.menubar.hide() self.toolBar.hide() + if useQT5: + self.frameEntete.close() def addJdcInSalome(self, jdcPath): debug("addJdcInSalome is called " + str(jdcPath)) diff --git a/src/daSalome/daGUI/daGuiImpl/ADAOGUI_impl.py b/src/daSalome/daGUI/daGuiImpl/ADAOGUI_impl.py index 3b53654..cad3c40 100644 --- a/src/daSalome/daGUI/daGuiImpl/ADAOGUI_impl.py +++ b/src/daSalome/daGUI/daGuiImpl/ADAOGUI_impl.py @@ -22,8 +22,14 @@ __author__="aribes/gboulant" -from PyQt4.QtGui import * -from PyQt4.QtCore import * +from daUtils.qtversion import useQT5 +if useQT5: + from PyQt5.QtGui import * + from PyQt5.QtCore import * + from PyQt5.QtWidgets import QApplication +else: + from PyQt4.QtGui import * + from PyQt4.QtCore import * import SalomePyQt sgPyQt = SalomePyQt.SalomePyQt() @@ -49,6 +55,7 @@ __study2context__ = {} __current_context__ = None def _setContext( studyID ): global __study2context__, __current_context__ + QApplication.processEvents() if not __study2context__.has_key(studyID): __study2context__[studyID] = GUIcontext() pass @@ -98,13 +105,11 @@ def activate(): def deactivate(): ctx = _setContext( sgPyQt.getStudyId() ) ctx.adaoCaseManager.deactivate() - pass # called when active study is changed # active study ID is passed as parameter def activeStudyChanged( studyID ): ctx = _setContext( sgPyQt.getStudyId() ) - pass # called when popup menu is invoked # popup menu and menu context are passed as parameters @@ -121,7 +126,6 @@ def OnGUIEvent(actionId) : Called when an event is raised from a graphic item (click on menu item or toolbar button). The actionId value is the ID associated to the item. """ - pass ctx = _setContext( sgPyQt.getStudyId() ) ctx.adaoCaseManager.processGUIEvent(actionId) @@ -133,7 +137,7 @@ def preferenceChanged( section, setting ): # called when active view is changed # view ID is passed as parameter def activeViewChanged( viewID ): - pass + pass # called when active view is cloned # cloned view ID is passed as parameter diff --git a/src/daSalome/daGUI/daGuiImpl/adaoGuiHelper.py b/src/daSalome/daGUI/daGuiImpl/adaoGuiHelper.py index 0006bb6..2071ff5 100644 --- a/src/daSalome/daGUI/daGuiImpl/adaoGuiHelper.py +++ b/src/daSalome/daGUI/daGuiImpl/adaoGuiHelper.py @@ -28,7 +28,11 @@ import SalomePyQt __sgPyQt = SalomePyQt.SalomePyQt() import adaoModuleHelper -from PyQt4 import QtGui,QtCore +from daUtils.qtversion import useQT5 +if useQT5: + from PyQt5 import QtGui,QtCore +else: + from PyQt4 import QtGui,QtCore def waitCursor(): QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.WaitCursor)) diff --git a/src/daSalome/daGUI/daGuiImpl/adaoGuiManager.py b/src/daSalome/daGUI/daGuiImpl/adaoGuiManager.py index 7466a9c..481406a 100644 --- a/src/daSalome/daGUI/daGuiImpl/adaoGuiManager.py +++ b/src/daSalome/daGUI/daGuiImpl/adaoGuiManager.py @@ -28,9 +28,15 @@ in the GUI part of the module. __author__ = "aribes/gboulant" import traceback -from PyQt4.QtCore import QObject -from PyQt4.QtCore import * # Import from PyQT -from PyQt4 import QtGui,QtCore +from daUtils.qtversion import useQT5 +if useQT5: + from PyQt5.QtCore import QObject + from PyQt5.QtWidgets import QScrollArea +else: + from PyQt4.QtCore import QObject + from PyQt4.QtCore import * # Import from PyQT + from PyQt4 import QtCore + from PyQt4.QtGui import QScrollArea import SalomePyQt sgPyQt = SalomePyQt.SalomePyQt() @@ -97,7 +103,7 @@ class AdaoCaseManager(EficasObserver): # Creation du viewer QT # Scroll Widget (pour les petites resolutions) - area = QtGui.QScrollArea(SalomePyQt.SalomePyQt().getDesktop()); + area = QScrollArea(SalomePyQt.SalomePyQt().getDesktop()); area.setWidget(self.eficas_manager) area.setWidgetResizable(1) wmType = "ADAO View" @@ -109,7 +115,10 @@ class AdaoCaseManager(EficasObserver): # On s'abonne au gestionnaire de selection self.selection_manager = sgPyQt.getSelection() - QtCore.QObject.connect(self.selection_manager, QtCore.SIGNAL('currentSelectionChanged()'), self.currentSelectionChanged) + if useQT5: + self.selection_manager.currentSelectionChanged.connect(self.currentSelectionChanged) + else: + QtCore.QObject.connect(self.selection_manager, QtCore.SIGNAL('currentSelectionChanged()'), self.currentSelectionChanged) ###### # diff --git a/src/daSalome/daGUI/daGuiImpl/adaoModuleHelper.py b/src/daSalome/daGUI/daGuiImpl/adaoModuleHelper.py index 508902f..54a6dbf 100644 --- a/src/daSalome/daGUI/daGuiImpl/adaoModuleHelper.py +++ b/src/daSalome/daGUI/daGuiImpl/adaoModuleHelper.py @@ -79,7 +79,11 @@ def componentName(): # _MEM_ we use here the tr() translation methode to manage constant parameters # in the application. We could have specified instead constant values directly # in the code below. It's a matter of convenience. -from PyQt4.QtCore import QObject +from daUtils.qtversion import useQT5 +if useQT5: + from PyQt5.QtCore import QObject +else: + from PyQt4.QtCore import QObject QObjectTR=QObject() def componentUserName(): diff --git a/src/daSalome/daGUI/daUtils/Makefile.am b/src/daSalome/daGUI/daUtils/Makefile.am index dc09ea9..f3d0672 100644 --- a/src/daSalome/daGUI/daUtils/Makefile.am +++ b/src/daSalome/daGUI/daUtils/Makefile.am @@ -27,5 +27,6 @@ mypkgpython_PYTHON = \ __init__.py \ adaoEficasEvent.py \ adaoLogger.py \ + qtversion.py \ enumerate.py diff --git a/src/daSalome/daGUI/daUtils/qtversion.py b/src/daSalome/daGUI/daUtils/qtversion.py new file mode 100644 index 0000000..3a657da --- /dev/null +++ b/src/daSalome/daGUI/daUtils/qtversion.py @@ -0,0 +1,26 @@ +#-*-coding:iso-8859-1-*- +# +# Copyright (C) 2008-2016 EDF R&D +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# +# Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D + +import eficasSalome # Import from EFICAS_SRC +from InterfaceQT4.determine import monEnvQT5 + +useQT5 = bool(monEnvQT5) -- 2.39.2