From: rnv Date: Tue, 29 Nov 2016 11:32:24 +0000 (+0300) Subject: PySide: attempt number one. X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2Frnv%2Fpyside_exprm;p=modules%2Fgui.git PySide: attempt number one. --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 66873d457..837b7e2b7 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -76,6 +76,7 @@ OPTION(SALOME_USE_QXGRAPHVIEWER "Enable QX graph visualization (Mandatory in cla CMAKE_DEPENDENT_OPTION(SALOME_USE_SALOMEOBJECT "Enable Salome Object (Mandatory in classic configurations)" ON "SALOME_LIGHT_ONLY" ON) OPTION(SALOME_USE_SINGLE_DESKTOP "Enable multiple document interface" ON) +OPTION(SALOME_USE_PYSIDE "Use PySide + Shiboken to wrap GUI funtionality in the python module, otherwise PyQt + SIP is used" ON) MARK_AS_ADVANCED(SALOME_LIGHT_ONLY SALOME_USE_VTKVIEWER SALOME_USE_GRAPHICSVIEW) MARK_AS_ADVANCED(SALOME_USE_SALOMEOBJECT SALOME_USE_OCCVIEWER SALOME_USE_GLVIEWER SALOME_USE_PLOT2DVIEWER) @@ -123,8 +124,11 @@ ENDIF() ## ## GUI specifics ## - -FIND_PACKAGE(SalomeSIP REQUIRED) # should come after Python and before PyQt4 +IF(SALOME_USE_PYSIDE) + FIND_PACKAGE(SalomeShiboken REQUIRED) # should come after Python and before PySide +ELSE(SALOME_USE_PYSIDE) + FIND_PACKAGE(SalomeSIP REQUIRED) # should come after Python and before PyQt4 +ENDIF() # Build with GUI observers feature IF(SALOME_GUI_USE_OBSERVERS) @@ -145,7 +149,11 @@ ENDIF() FIND_PACKAGE(SalomeQt4 REQUIRED COMPONENTS QtCore QtGui QtXml QtWebKit QtOpenGL) INCLUDE(${QT_USE_FILE}) -FIND_PACKAGE(SalomePyQt4 REQUIRED) +IF(SALOME_USE_PYSIDE) + FIND_PACKAGE(SalomePySide REQUIRED) +ELSE(SALOME_USE_PYSIDE) + FIND_PACKAGE(SalomePyQt4 REQUIRED) +ENDIF(SALOME_USE_PYSIDE) # Optional prerequisites for GUI IF(SALOME_USE_GLVIEWER) @@ -352,9 +360,14 @@ EXPORT(TARGETS ${_${PROJECT_NAME}_exposed_targets} # Ensure the variables are always defined for the configure: SET(KERNEL_ROOT_DIR "${KERNEL_ROOT_DIR}") -SET(SIP_ROOT_DIR "${SIP_ROOT_DIR}") +IF(SALOME_USE_PYSIDE) + SET(SHIBOKEN_ROOT_DIR "${SHIBOKEN_ROOT_DIR}") + SET(PYSIDE_ROOT_DIR "${PYSIDE_ROOT_DIR}") +ELSE(SALOME_USE_PYSIDE) + SET(SIP_ROOT_DIR "${SIP_ROOT_DIR}") + SET(PYQT4_ROOT_DIR "${PYQT4_ROOT_DIR}") +ENDIF(SALOME_USE_PYSIDE) SET(QT4_ROOT_DIR "${QT4_ROOT_DIR}") -SET(PYQT4_ROOT_DIR "${PYQT4_ROOT_DIR}") SET(CAS_ROOT_DIR "${CAS_ROOT_DIR}") SET(OPENGL_ROOT_DIR "${OPENGL_ROOT_DIR}") SET(VTK_ROOT_DIR "${VTK_ROOT_DIR}") @@ -363,14 +376,23 @@ SET(QWT_ROOT_DIR "${QWT_ROOT_DIR}") SET(CONF_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/include" "${PROJECT_BINARY_DIR}/include") # Build variables that will be expanded when configuring SalomeConfig.cmake: -SALOME_CONFIGURE_PREPARE(CAS OpenGL PyQt4 Qt4 Qwt SIP VTK) - -CONFIGURE_PACKAGE_CONFIG_FILE(${PROJECT_NAME}Config.cmake.in - ${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake - INSTALL_DESTINATION "${SALOME_INSTALL_CMAKE_LOCAL}" - PATH_VARS CONF_INCLUDE_DIRS SALOME_INSTALL_CMAKE_LOCAL CMAKE_INSTALL_PREFIX - KERNEL_ROOT_DIR SIP_ROOT_DIR QT4_ROOT_DIR PYQT4_ROOT_DIR CAS_ROOT_DIR - OPENGL_ROOT_DIR VTK_ROOT_DIR QWT_ROOT_DIR) +IF(SALOME_USE_PYSIDE) + SALOME_CONFIGURE_PREPARE(CAS OpenGL PySide Qt4 Qwt Shiboken VTK) + CONFIGURE_PACKAGE_CONFIG_FILE(${PROJECT_NAME}Config.cmake.in + ${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake + INSTALL_DESTINATION "${SALOME_INSTALL_CMAKE_LOCAL}" + PATH_VARS CONF_INCLUDE_DIRS SALOME_INSTALL_CMAKE_LOCAL CMAKE_INSTALL_PREFIX + KERNEL_ROOT_DIR SHIBOKEN_ROOT_DIR QT4_ROOT_DIR PYSIDE_ROOT_DIR CAS_ROOT_DIR + OPENGL_ROOT_DIR VTK_ROOT_DIR QWT_ROOT_DIR) +ELSE(SALOME_USE_PYSIDE) + SALOME_CONFIGURE_PREPARE(CAS OpenGL PyQt4 Qt4 Qwt SIP VTK) + CONFIGURE_PACKAGE_CONFIG_FILE(${PROJECT_NAME}Config.cmake.in + ${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake + INSTALL_DESTINATION "${SALOME_INSTALL_CMAKE_LOCAL}" + PATH_VARS CONF_INCLUDE_DIRS SALOME_INSTALL_CMAKE_LOCAL CMAKE_INSTALL_PREFIX + KERNEL_ROOT_DIR SIP_ROOT_DIR QT4_ROOT_DIR PYQT4_ROOT_DIR CAS_ROOT_DIR + OPENGL_ROOT_DIR VTK_ROOT_DIR QWT_ROOT_DIR) +ENDIF(SALOME_USE_PYSIDE) # - in the install tree (VSR 16/08/2013: TEMPORARILY COMMENT THIS - TO REMOVE?): # Get the relative path of the include directory so diff --git a/SalomeGUIConfig.cmake.in b/SalomeGUIConfig.cmake.in index a2807ff0d..f986faca7 100644 --- a/SalomeGUIConfig.cmake.in +++ b/SalomeGUIConfig.cmake.in @@ -61,6 +61,7 @@ SET(SALOME_USE_QXGRAPHVIEWER @SALOME_USE_QXGRAPHVIEWER@) SET(SALOME_USE_PYCONSOLE @SALOME_USE_PYCONSOLE@) SET(SALOME_USE_SALOMEOBJECT @SALOME_USE_SALOMEOBJECT@) SET(SALOME_USE_SINGLE_DESKTOP @SALOME_USE_SINGLE_DESKTOP@) +SET(SALOME_USE_PYSIDE @SALOME_USE_PYSIDE@) SET(SALOME_GUI_USE_OBSERVERS @SALOME_GUI_USE_OBSERVERS@) IF(SALOME_GUI_LIGHT_ONLY) @@ -97,12 +98,23 @@ ENDIF() IF(NOT SALOME_USE_SALOMEOBJECT) LIST(APPEND GUI_DEFINITIONS "-DDISABLE_SALOMEOBJECT") ENDIF() +IF(SALOME_USE_PYSIDE) + LIST(APPEND GUI_DEFINITIONS "-DWITH_PYSIDE") +ELSE(SALOME_USE_PYSIDE) + LIST(APPEND GUI_DEFINITIONS "--DWITH_PYQT4") +ENDIF(SALOME_USE_PYSIDE) # Level 1 prerequisites: SET_AND_CHECK(KERNEL_ROOT_DIR_EXP "@PACKAGE_KERNEL_ROOT_DIR@") -SET_AND_CHECK(SIP_ROOT_DIR_EXP "@PACKAGE_SIP_ROOT_DIR@") +IF(SALOME_USE_PYSIDE) + SET_AND_CHECK(SHIBOKEN_ROOT_DIR_EXP "@PACKAGE_SHIBOKEN_ROOT_DIR@") + SET_AND_CHECK(PYSIDE_ROOT_DIR_EXP "@PACKAGE_PYSIDE_ROOT_DIR@") +ELSE(SALOME_USE_PYSIDE) + SET_AND_CHECK(SIP_ROOT_DIR_EXP "@PACKAGE_SIP_ROOT_DIR@") + SET_AND_CHECK(PYQT4_ROOT_DIR_EXP "@PACKAGE_PYQT4_ROOT_DIR@") +ENDIF(SALOME_USE_PYSIDE) + SET_AND_CHECK(QT4_ROOT_DIR_EXP "@PACKAGE_QT4_ROOT_DIR@") -SET_AND_CHECK(PYQT4_ROOT_DIR_EXP "@PACKAGE_PYQT4_ROOT_DIR@") SET_AND_CHECK(CAS_ROOT_DIR_EXP "@PACKAGE_CAS_ROOT_DIR@") # Optional level 1 prerequisites: diff --git a/adm_local/cmake_files/CMakeLists.txt b/adm_local/cmake_files/CMakeLists.txt index 0525b99f2..59e352f76 100755 --- a/adm_local/cmake_files/CMakeLists.txt +++ b/adm_local/cmake_files/CMakeLists.txt @@ -30,12 +30,17 @@ SET(_adm_data FindSIP.cmake FindPyQt4.cmake FindSalomePyQt4.cmake + FindSalomePySide.cmake FindSalomeQt4.cmake FindSalomeQwt.cmake FindSalomeSIP.cmake + FindSalomeShiboken.cmake FindSalomeGUI.cmake FindSalomeOpenGL.cmake UsePyQt4.cmake + UsePySide.cmake + UsePySide.cmake UseQt4Ext.cmake + CommonTools.cmake ) INSTALL(FILES ${_adm_data} DESTINATION ${SALOME_INSTALL_CMAKE_LOCAL}) diff --git a/adm_local/cmake_files/CommonTools.cmake b/adm_local/cmake_files/CommonTools.cmake new file mode 100644 index 000000000..36c5bbdc4 --- /dev/null +++ b/adm_local/cmake_files/CommonTools.cmake @@ -0,0 +1,44 @@ +# Copyright (C) 2012-2014 CEA/DEN, EDF R&D, OPEN CASCADE +# +# 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, or (at your option) any later version. +# +# 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: Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com) + +#################################################################### +# +# _GET_UNIQUE_TARGET_NAME: internal function +# +# Used to generate unique custom target name for usage in +# PYQT4_WRAP_UIC macro. +# +# USAGE: _PYQT4_WRAP_GET_UNIQUE_TARGET_NAME(prefix unique_name) +# +# ARGUMENTS: +# prefix [in] prefix for the name +# unique_name [out] unique name generated by function +# +#################################################################### +FUNCTION(_GET_UNIQUE_TARGET_NAME name unique_name) + SET(_propertyName "_PYQT4_WRAP_UNIQUE_COUNTER_${name}") + GET_PROPERTY(_currentCounter GLOBAL PROPERTY "${_propertyName}") + IF(NOT _currentCounter) + SET(_currentCounter 1) + ENDIF() + SET(${unique_name} "${name}_${_currentCounter}" PARENT_SCOPE) + MATH(EXPR _currentCounter "${_currentCounter} + 1") + SET_PROPERTY(GLOBAL PROPERTY ${_propertyName} ${_currentCounter} ) +ENDFUNCTION() diff --git a/adm_local/cmake_files/FindPyTools.cmake b/adm_local/cmake_files/FindPyTools.cmake new file mode 100644 index 000000000..152378bda --- /dev/null +++ b/adm_local/cmake_files/FindPyTools.cmake @@ -0,0 +1,52 @@ +# Copyright (C) 2013-2014 CEA/DEN, EDF R&D, OPEN CASCADE +# +# 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, or (at your option) any later version. +# +# 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 +# + +# - Find PySide installation +# Sets the following variables: +# PYSIDE_PYUIC_EXECUTABLE - path to the pyside-uic executable +# PYSIDE_PYRCC_EXECUTABLE - path to the pyside-rcc executable +# PYSIDE_PYUIC_PATH - command to launch pyuic with the correct PYTHONPATH +# PYSIDE_PYRCC_PATH - command to launch pyrcc with the correct PYTHONPATH +# +# The executables +# pyside-uic and pyside-rcc are searched. + +IF(NOT PyTools_FIND_QUIETLY) + MESSAGE(STATUS "Looking for PyTools ...") +ENDIF() + +FIND_PROGRAM(PYSIDE_PYUIC_EXECUTABLE NAMES pyside-uic) +FIND_PROGRAM(PYSIDE_PYRCC_EXECUTABLE NAMES pyside-rcc) + +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(PyTools REQUIRED_VARS PYSIDE_PYUIC_EXECUTABLE) + +# Wrap the final executables so that they always use the proper environment (PYTHONPATH): +# The results are put to variables: +# PYSIDE_PYUIC_PATH - command to launch pyuic with the correct PYTHONPATH +# PYSIDE_PYRCC_PATH - command to launch pyrcc with the correct PYTHONPATH +# TODO: should be done like Sphinx in KERNEL (i.e. generating a shell script)? + +IF(WIN32) + SET(PYSIDE_PYUIC_PATH set PYTHONPATH=${PYSIDE_PYTHONPATH};${SHIBOKEN_PYTHONPATH};%PYTHONPATH% && ${PYSIDE_PYUIC_EXECUTABLE}) + SET(PYSIDE_PYRCC_PATH set PYTHONPATH=${PYSIDE_PYTHONPATH};${SHIBOKEN_PYTHONPATH};%PYTHONPATH% && ${PYSIDE_PYRCC_EXECUTABLE}) +ELSE() + SET(PYSIDE_PYUIC_PATH /usr/bin/env PYTHONPATH="${PYSIDE_PYTHONPATH}:${SHIBOKEN_PYTHONPATH}:$$PYTHONPATH" ${PYSIDE_PYUIC_EXECUTABLE}) + SET(PYSIDE_PYRCC_PATH /usr/bin/env PYTHONPATH="${PYSIDE_PYTHONPATH}:${SHIBOKEN_PYTHONPATH}:$$PYTHONPATH" ${PYSIDE_PYRCC_EXECUTABLE}) +ENDIF() diff --git a/adm_local/cmake_files/FindSalomePyQt4.cmake b/adm_local/cmake_files/FindSalomePyQt4.cmake index 856ad84a7..2d9715034 100644 --- a/adm_local/cmake_files/FindSalomePyQt4.cmake +++ b/adm_local/cmake_files/FindSalomePyQt4.cmake @@ -31,6 +31,7 @@ SALOME_FIND_PACKAGE_AND_DETECT_CONFLICTS(PyQt4 PYQT_PYUIC_EXECUTABLE 2) MARK_AS_ADVANCED(PYQT_PYUIC_EXECUTABLE PYQT_PYRCC_EXECUTABLE PYQT_SIPS_DIR PYQT_PYUIC_PATH PYQT_PYRCC_PATH) IF(PYQT4_FOUND) + SET(PYQT4_DEFINITIONS "-DWITH_PYQT4") SALOME_ACCUMULATE_ENVIRONMENT(PATH ${PYQT_PYUIC_EXECUTABLE}) SALOME_ACCUMULATE_ENVIRONMENT(LD_LIBRARY_PATH ${PYQT_PYTHONPATH}) SALOME_ACCUMULATE_ENVIRONMENT(PYTHONPATH ${PYQT_PYTHONPATH}) diff --git a/adm_local/cmake_files/FindSalomePySide.cmake b/adm_local/cmake_files/FindSalomePySide.cmake new file mode 100644 index 000000000..9eb31b03b --- /dev/null +++ b/adm_local/cmake_files/FindSalomePySide.cmake @@ -0,0 +1,54 @@ +# Copyright (C) 2013-2014 CEA/DEN, EDF R&D, OPEN CASCADE +# +# 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, or (at your option) any later version. +# +# 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: Roman NIKOLAEV +# + +# PySide detection for Salome +# +# !! Please read the generic detection procedure in SalomeMacros.cmake !! +# + +# PySide needs shiboken, call it automatically +FIND_PACKAGE(SalomeShiboken REQUIRED) + +# Find the PySide +SALOME_FIND_PACKAGE_AND_DETECT_CONFLICTS(PySide PYSIDE_INCLUDE_DIR 2) + +# Find the pyside-uic and pyside-rcc executables +SALOME_FIND_PACKAGE_AND_DETECT_CONFLICTS(PyTools PYSIDE_PYUIC_EXECUTABLE 2) +MARK_AS_ADVANCED(PYSIDE_PYUIC_EXECUTABLE PYSIDE_PYRCC_EXECUTABLE PYSIDE_PYUIC_PATH PYSIDE_PYRCC_PATH) + +# TODO : RNV : Check difference between Pakage_FOUND and PACKAGE_FOUND (in upper case and "as is") !!! +IF(PySide_FOUND AND PYTOOLS_FOUND) + SALOME_ACCUMULATE_ENVIRONMENT(PATH ${PYSIDE_PYUIC_EXECUTABLE}) + SALOME_ACCUMULATE_ENVIRONMENT(LD_LIBRARY_PATH ${PYSIDE_PYTHONPATH}) + SALOME_ACCUMULATE_ENVIRONMENT(PYTHONPATH ${PYSIDE_PYTHONPATH}) + + # Define shiboken generator options + SET(SIHBOKEN_GENERATOR_EXTRA_FLAGS --generator-set=shiboken --enable-parent-ctor-heuristic --enable-pyside-extensions --enable-return-value-heuristic --use-isnull-as-nb_nonzero) + + # Define C++ preprocessor options + SET(PYSIDE_DEFINITIONS -DWITH_PYSIDE -DAVOID_PROTECTED_HACK) + + # Costomize include directories + SET(PYSIDE_INCLUDE_DIRS ${PYSIDE_INCLUDE_DIR} + PYSIDE_INCLUDE_DIRS ${PYSIDE_INCLUDE_DIR}/QtCore + PYSIDE_INCLUDE_DIRS ${PYSIDE_INCLUDE_DIR}/QtGui + PYSIDE_INCLUDE_DIRS ${PYSIDE_INCLUDE_DIR}/QtXml) +ENDIF() diff --git a/adm_local/cmake_files/FindSalomeShiboken.cmake b/adm_local/cmake_files/FindSalomeShiboken.cmake new file mode 100644 index 000000000..b782e8b10 --- /dev/null +++ b/adm_local/cmake_files/FindSalomeShiboken.cmake @@ -0,0 +1,34 @@ +# Copyright (C) 2013-2014 CEA/DEN, EDF R&D, OPEN CASCADE +# +# 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, or (at your option) any later version. +# +# 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: Roman NIKOLAEV +# + +# Shiboken detection for Salome +# +# !! Please read the generic detection procedure in SalomeMacros.cmake !! +# +SALOME_FIND_PACKAGE_AND_DETECT_CONFLICTS(Shiboken SHIBOKEN_BINARY 2) +MARK_AS_ADVANCED(SHIBOKEN_BINARY SHIBOKEN_INCLUDE_DIR SHIBOKEN_LIBRARY) + +IF(SHIBOKEN_FOUND) + SALOME_ACCUMULATE_ENVIRONMENT(PATH ${SHIBOKEN_EXECUTABLE}) + SALOME_ACCUMULATE_ENVIRONMENT(LD_LIBRARY_PATH ${SHIBOKEN_PYTHONPATH}) + SALOME_ACCUMULATE_ENVIRONMENT(PYTHONPATH ${SHIBOKEN_PYTHONPATH}) +ENDIF() + diff --git a/adm_local/cmake_files/UsePyQt4.cmake b/adm_local/cmake_files/UsePyQt4.cmake index 11d2d1150..c38a2190a 100644 --- a/adm_local/cmake_files/UsePyQt4.cmake +++ b/adm_local/cmake_files/UsePyQt4.cmake @@ -18,30 +18,7 @@ # # Author: Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com) -#################################################################### -# -# _PYQT4_WRAP_GET_UNIQUE_TARGET_NAME: internal function -# -# Used to generate unique custom target name for usage in -# PYQT4_WRAP_UIC macro. -# -# USAGE: _PYQT4_WRAP_GET_UNIQUE_TARGET_NAME(prefix unique_name) -# -# ARGUMENTS: -# prefix [in] prefix for the name -# unique_name [out] unique name generated by function -# -#################################################################### -FUNCTION(_PYQT4_WRAP_GET_UNIQUE_TARGET_NAME name unique_name) - SET(_propertyName "_PYQT4_WRAP_UNIQUE_COUNTER_${name}") - GET_PROPERTY(_currentCounter GLOBAL PROPERTY "${_propertyName}") - IF(NOT _currentCounter) - SET(_currentCounter 1) - ENDIF() - SET(${unique_name} "${name}_${_currentCounter}" PARENT_SCOPE) - MATH(EXPR _currentCounter "${_currentCounter} + 1") - SET_PROPERTY(GLOBAL PROPERTY ${_propertyName} ${_currentCounter} ) -ENDFUNCTION() +INCLUDE(CommonTools) #################################################################### # diff --git a/adm_local/cmake_files/UsePySide.cmake b/adm_local/cmake_files/UsePySide.cmake new file mode 100644 index 000000000..a790f22f2 --- /dev/null +++ b/adm_local/cmake_files/UsePySide.cmake @@ -0,0 +1,196 @@ +# Copyright (C) 2012-2014 CEA/DEN, EDF R&D, OPEN CASCADE +# +# 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, or (at your option) any later version. +# +# 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: Roman NIKOLAEV, (roman.nikolaev@opencascade.com) + +INCLUDE(CommonTools) + +#################################################################### +# +# PYSIDE_WRAP_UIC macro +# +# Create Python modules by processing input *.ui (Qt designer) files with +# PySide pyside-uic tool. +# +# USAGE: PYSIDE_WRAP_UIC(output_files pyuic_files) +# +# ARGUMENTS: +# output_files [out] variable where output file names are listed to +# pyuic_files [in] list of *.ui files +# +# NOTES: +# - Input files are considered relative to the current source directory. +# - Output files are generated in the current build directory. +# - Macro automatically adds custom build target to generate output files +# +#################################################################### +MACRO(PYSIDE_WRAP_UIC outfiles) + + IF(NOT WIN32) + FOREACH(_input ${ARGN}) + GET_FILENAME_COMPONENT(_input_name ${_input} NAME) + STRING(REPLACE ".ui" "_ui.py" _input_name ${_input_name}) + SET(_output ${CMAKE_CURRENT_BINARY_DIR}/${_input_name}) + ADD_CUSTOM_COMMAND( + OUTPUT ${_output} + COMMAND ${PYSIDE_PYUIC_PATH} -o ${_output} ${CMAKE_CURRENT_SOURCE_DIR}/${_input} + MAIN_DEPENDENCY ${_input} + ) + SET(${outfiles} ${${outfiles}} ${_output}) + ENDFOREACH() + _GET_UNIQUE_TARGET_NAME(BUILD_UI_PY_FILES _uniqueTargetName) + ADD_CUSTOM_TARGET(${_uniqueTargetName} ALL DEPENDS ${${outfiles}}) + + ELSEIF(NOT WIN32) +#### +# ANA: Workaround for the Microsoft Visual Studio 2010. Seems there is a bug in +# the Microsoft Visual Studio 2010 or CMake 2.8.10.2: custom target doesn't work +# for the list of the dependencies. It works only for the first dependency in the +# list. So generate separate target for the each input file. This problem will be +#investigated in the future. +#### + + SET_PROPERTY(GLOBAL PROPERTY USE_FOLDERS ON) + _GET_UNIQUE_TARGET_NAME(BUILD_UI_PY_FILES _uniqueTargetName) + ADD_CUSTOM_TARGET(${_uniqueTargetName} ALL) + FOREACH(_input ${ARGN}) + GET_FILENAME_COMPONENT(_input_name ${_input} NAME) + STRING(REPLACE ".ui" "_ui.py" _input_name ${_input_name}) + SET(_output ${CMAKE_CURRENT_BINARY_DIR}/${_input_name}) + _GET_UNIQUE_TARGET_NAME(BUILD_UI_PY_FILES _TgName) + ADD_CUSTOM_TARGET(${_TgName} ${PYSIDE_PYUIC_PATH} -o ${_output} ${CMAKE_CURRENT_SOURCE_DIR}/${_input} + DEPENDS ${_input} + ) + SET_TARGET_PROPERTIES(${_TgName} PROPERTIES FOLDER PYSIDE_WRAP_UIC_TARGETS) + ADD_DEPENDENCIES(${_uniqueTargetName} DEPEND ${_TgName}) + SET(${outfiles} ${${outfiles}} ${_output}) + ENDFOREACH() + ENDIF(NOT WIN32) +ENDMACRO(PYSIDE_WRAP_UIC) + +#################################################################### +# +# PYSIDE_WRAP_QRC macro +# +# Generate Python wrappings for *.qrc files by processing them with pyrcc4. +# +# USAGE: PYSIDE_WRAP_QRC(output_files qrc_files) +# +# ARGUMENTS: +# output_files [out] variable where output file names are listed to +# qrc_files [in] list of *.qrc files +# +# NOTES: +# - Input files are considered relative to the current source directory. +# - Output files are generated in the current build directory. +# - Macro automatically adds custom build target to generate output files +# +#################################################################### + +MACRO(PYSIDE_WRAP_QRC outfiles) + FOREACH(_input ${ARGN}) + GET_FILENAME_COMPONENT(_input_name ${_input} NAME) + STRING(REPLACE ".qrc" "_qrc.py" _input_name ${_input_name}) + SET(_output ${CMAKE_CURRENT_BINARY_DIR}/${_input_name}) + ADD_CUSTOM_COMMAND( + OUTPUT ${_output} + COMMAND ${PYSIDE_PYRCC_PATH} -o ${_output} ${CMAKE_CURRENT_SOURCE_DIR}/${_input} + MAIN_DEPENDENCY ${_input} + ) + SET(${outfiles} ${${outfiles}} ${_output}) + ENDFOREACH() + _GET_UNIQUE_TARGET_NAME(BUILD_QRC_PY_FILES _uniqueTargetName) + ADD_CUSTOM_TARGET(${_uniqueTargetName} ALL DEPENDS ${${outfiles}}) +ENDMACRO(PYSIDE_WRAP_QRC) + +#################################################################### +# +# CREATE_PYSIDE_MODULE macro +# +# Create PySide module. +# +# USAGE: CREATE_PYSIDE_MODULE( module_name module_include_dir +# module_libraries module_global_file +# module_dependencies module_timesystem_path +# module_sources module_gen_sources ) +# +# ARGUMENTS: +# module_name [in] name of the PySide module. +# module_global_file [in] module global header file +# module_include_dir [in] list of the module include directories. +# module_include_dir [in] list of the libraries with witch to +# be module linked. +# module_dependencies [in] list of the module dependencies. +# module_timesystem_path [in] list of the module typesystem paths. +# module_sources [in] module static sources. +# module_gen_sources [in] list of the sources to be generated. +# +# NOTES: +# - Output files are generated in the current build directory. +# - This version of macro requires class(es) definition in the *_typesystem.xml file. +# +#################################################################### +MACRO(CREATE_PYSIDE_MODULE MODULE_NAME MODULE_GLOBAL_FILE MODULE_INCLUDE_DIR MODULE_LIBRARIES MODULE_DEPS MODULE_TYPESYSTEM_PATH MODULE_SOURCES MODULE_GEN_SOURCES) + + IF(${ARGC} GREATER 8) + SET(TYPESYSTEM_NAME ${ARGV8}) + ELSE() + set (TYPESYSTEM_NAME "") + ENDIF() + + IF(${ARGC} GREATER 9) + string(REPLACE ";" "\\;" DROPPED_ENTRIES "${${ARGV9}}") + ELSE() + SET (DROPPED_ENTRIES "") + ENDIF() + + IF(NOT EXISTS ${TYPESYSTEM_NAME}) + SET(TYPESYSTEM_PATH ${CMAKE_CURRENT_SOURCE_DIR}/${MODULE_NAME}_typesystem.xml) + ELSE() + SET(TYPESYSTEM_PATH ${TYPESYSTEM_NAME}) + ENDIF() + + STRING(REPLACE ";" "${PATH_SEP}" _TMP_QT_INCLUDES "${QT_INCLUDES}") + STRING(REPLACE ";" "${PATH_SEP}" _TMP_MODULE_INCLUDE_DIR "${${MODULE_INCLUDE_DIR}}") + + ADD_CUSTOM_COMMAND(OUTPUT ${${MODULE_GEN_SOURCES}} + COMMAND ${SHIBOKEN_BINARY} ${SIHBOKEN_GENERATOR_EXTRA_FLAGS} + ${MODULE_GLOBAL_FILE} + --include-paths=${PYSIDE_INCLUDE_DIR}${PATH_SEP}${_TMP_QT_INCLUDES}${PATH_SEP}${_TMP_MODULE_INCLUDE_DIR} + --typesystem-paths=${PYSIDE_TYPESYSTEMS}${PATH_SEP}${${MODULE_TYPESYSTEM_PATH}} + --output-directory=${CMAKE_CURRENT_BINARY_DIR} + --avoid-protected-hack + ${TYPESYSTEM_PATH} + --api-version="${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}" + --drop-type-entries="${DROPPED_ENTRIES}" + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMENT "Running shiboken generator for ${MODULE_NAME}..." + MAIN_DEPENDENCY ${TYPESYSTEM_PATH}) + + ADD_LIBRARY(${MODULE_NAME} ${${MODULE_SOURCES}} ${${MODULE_GEN_SOURCES}}) + IF(WIN32) + SET_TARGET_PROPERTIES(${MODULE_NAME} PROPERTIES SUFFIX ".pyd") + SET(${MODULE_NAME}_SUFFIX ".pyd") + ELSE() + SET(${MODULE_NAME}_SUFFIX ${CMAKE_SHARED_MODULE_SUFFIX}) + ENDIF() + TARGET_LINK_LIBRARIES(${MODULE_NAME} ${${MODULE_LIBRARIES}}) + IF(${MODULE_DEPS}) + ADD_DEPENDENCIES(${MODULE_NAME} ${${MODULE_DEPS}}) + ENDIF() +ENDMACRO() \ No newline at end of file diff --git a/src/GUI_PY/CMakeLists.txt b/src/GUI_PY/CMakeLists.txt index 496f5fa05..45449a884 100755 --- a/src/GUI_PY/CMakeLists.txt +++ b/src/GUI_PY/CMakeLists.txt @@ -16,8 +16,11 @@ # # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # - -INCLUDE(UsePyQt4) +IF(SALOME_USE_PYSIDE) + INCLUDE(UsePySide) +ELSE(SALOME_USE_PYSIDE) + INCLUDE(UsePyQt4) +ENDIF(SALOME_USE_PYSIDE) # --- resources --- @@ -32,7 +35,13 @@ SET(_pyuic_files # scripts / pyuic wrappings -PYQT4_WRAP_UIC(_pyuic_SCRIPTS ${_pyuic_files}) +IF(SALOME_USE_PYSIDE) + PYSIDE_WRAP_UIC(_pyuic_SCRIPTS ${_pyuic_files}) +ELSE(SALOME_USE_PYSIDE) + PYQT4_WRAP_UIC(_pyuic_SCRIPTS ${_pyuic_files}) +ENDIF(SALOME_USE_PYSIDE) + + # scripts / static SET(_other_SCRIPTS diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUI/CMakeLists.txt b/src/SALOME_PYQT/SALOME_PYQT_GUI/CMakeLists.txt index 32d2cb984..1d0f07aff 100755 --- a/src/SALOME_PYQT/SALOME_PYQT_GUI/CMakeLists.txt +++ b/src/SALOME_PYQT/SALOME_PYQT_GUI/CMakeLists.txt @@ -42,13 +42,22 @@ INCLUDE_DIRECTORIES( ${PROJECT_SOURCE_DIR}/src/SalomeApp ) + + # additional preprocessor / compiler flags +IF(SALOME_USE_PYSIDE) + SET(PACKAGE_DEFINITIONS ${PYSIDE_DEFINITIONS}) +ELSE(SALOME_USE_PYSIDE) + SET(PACKAGE_DEFINITIONS ${PYQT4_DEFINITIONS}) +ENDIF(SALOME_USE_PYSIDE) + ADD_DEFINITIONS( ${QT_DEFINITIONS} ${CAS_DEFINITIONS} ${PYTHON_DEFINITIONS} ${BOOST_DEFINITIONS} ${OMNIORB_DEFINITIONS} + ${PACKAGE_DEFINITIONS} ) # libraries to link to diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_Module.cxx b/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_Module.cxx index 4b73279a7..e5a1e3a68 100644 --- a/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_Module.cxx +++ b/src/SALOME_PYQT/SALOME_PYQT_GUI/SALOME_PYQT_Module.cxx @@ -45,12 +45,19 @@ // and to get C API from sip : sipBuildResult for example // -#define INIT_FUNCTION initSalomePyQtGUILight -#if defined(SIP_STATIC_MODULE) -extern "C" void INIT_FUNCTION(); -#else -PyMODINIT_FUNC INIT_FUNCTION(); -#endif +#ifdef WITH_PYQT4 + #define INIT_FUNCTION initSalomePyQtGUILight + #if defined(SIP_STATIC_MODULE) + extern "C" void INIT_FUNCTION(); + #else + PyMODINIT_FUNC INIT_FUNCTION(); + #endif //SIP_STATIC_MODULE +#endif //WITH_PYQT4 + +#ifdef WITH_PYSIDE + #define INIT_FUNCTION initSalomePyQtGUILight + extern "C" void INIT_FUNCTION(); +#endif //WITH_PYSIDE /*! \fn CAM_Module* createModule() diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUILight/CMakeLists.txt b/src/SALOME_PYQT/SALOME_PYQT_GUILight/CMakeLists.txt index cf8cc6cf7..f3aad6850 100755 --- a/src/SALOME_PYQT/SALOME_PYQT_GUILight/CMakeLists.txt +++ b/src/SALOME_PYQT/SALOME_PYQT_GUILight/CMakeLists.txt @@ -17,18 +17,24 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # -INCLUDE(UsePyQt4) +IF(SALOME_USE_PYSIDE) + SET(PACKAGE_DEFINITIONS ${PYSIDE_DEFINITIONS}) + INCLUDE(UsePySide) +ELSE(SALOME_USE_PYSIDE) + INCLUDE(UsePyQt4) + SET(PACKAGE_DEFINITIONS ${PYQT4_DEFINITIONS}) +ENDIF(SALOME_USE_PYSIDE) + IF(SALOME_USE_VTKVIEWER) INCLUDE(${VTK_USE_FILE}) ENDIF() # --- options --- -# additional include directories -INCLUDE_DIRECTORIES( +# --- common include directories --- +SET(SalomePyQtGUILight_INCLUDE_DIRS ${CAS_INCLUDE_DIRS} ${QT_INCLUDES} - ${SIP_INCLUDE_DIR} ${PYTHON_INCLUDE_DIRS} ${PTHREAD_INCLUDE_DIR} ${CMAKE_CURRENT_BINARY_DIR} @@ -44,26 +50,51 @@ INCLUDE_DIRECTORIES( ${PROJECT_SOURCE_DIR}/src/SUIT ${PROJECT_SOURCE_DIR}/src/SUITApp ${PROJECT_SOURCE_DIR}/src/ObjBrowser -) + ) + +# additional include directories +IF(SALOME_USE_PYSIDE) + SET(SalomePyQtGUILight_INCLUDE_DIRS + ${SalomePyQtGUILight_INCLUDE_DIRS} + ${CMAKE_CURRENT_BINARY_DIR}/SalomePyQtGUILight + ${SHIBOKEN_INCLUDE_DIR} + ${PYSIDE_INCLUDE_DIRS}) +ELSE(SALOME_USE_PYSIDE) + SET(SalomePyQtGUILight_INCLUDE_DIRS + ${SalomePyQtGUILight_INCLUDE_DIRS} + ${SIP_INCLUDE_DIRS}) +ENDIF(SALOME_USE_PYSIDE) + +INCLUDE_DIRECTORIES(${SalomePyQtGUILight_INCLUDE_DIRS}) # additional preprocessor / compiler flags +IF(SALOME_USE_PYSIDE) + SET(PACKAGE_DEFINITIONS ${PYSIDE_DEFINITIONS}) +ELSE(SALOME_USE_PYSIDE) + SET(PACKAGE_DEFINITIONS ${PYQT4_DEFINITIONS}) +ENDIF(SALOME_USE_PYSIDE) + ADD_DEFINITIONS( ${QT_DEFINITIONS} ${CAS_DEFINITIONS} ${PYTHON_DEFINITIONS} -) + ${PACKAGE_DEFINITIONS}) # libraries to link to SET(_link_LIBRARIES ${PYTHON_LIBRARIES} ${VTK_LIBRARIES} ${OPENGL_LIBRARIES} - LightApp -) + LightApp) + IF(NOT SALOME_LIGHT_ONLY) LIST(APPEND _link_LIBRARIES ${KERNEL_SalomeContainer}) ENDIF() +IF(SALOME_USE_PYSIDE) + LIST(APPEND _link_LIBRARIES ${SHIBOKEN_LIBRARY} ${PYSIDE_LIBRARY}) +ENDIF(SALOME_USE_PYSIDE) + # --- headers --- # header files / to be processed by moc @@ -84,18 +115,16 @@ SET(_other_HEADERS SET(SalomePyQtGUILight_HEADERS ${_moc_HEADERS} ${_other_HEADERS}) # --- resources --- - -# sip files / to be processed by sip -SET(_sip_files SALOME_PYQT_GUILight.sip) +IF(NOT SALOME_USE_PYSIDE) + # sip files / to be processed by sip + SET(_sip_files SALOME_PYQT_GUILight.sip) +ENDIF(NOT SALOME_USE_PYSIDE) # --- sources --- # sources / moc wrappings QT4_WRAP_CPP(_moc_SOURCES ${_moc_HEADERS}) -# sources / sip wrappings -PYQT4_WRAP_SIP(_sip_SOURCES ${_sip_files}) - # sources / static SET(_other_SOURCES SALOME_PYQT_DataModelLight.cxx @@ -105,16 +134,44 @@ SET(_other_SOURCES SALOME_PYQT_PyModule.cxx ) -# sources / to compile -SET(SalomePyQtGUILight_SOURCES ${_other_SOURCES} ${_moc_SOURCES} ${_sip_SOURCES}) +SET(SalomePyQtGUILight_SOURCES ${_other_SOURCES} ${_moc_SOURCES}) -# --- rules --- -ADD_LIBRARY(SalomePyQtGUILight ${SalomePyQtGUILight_SOURCES}) -TARGET_LINK_LIBRARIES(SalomePyQtGUILight ${_link_LIBRARIES}) -INSTALL(TARGETS SalomePyQtGUILight DESTINATION ${SALOME_INSTALL_LIBS}) +IF(SALOME_USE_PYSIDE) + + # --- create pyside module --- + SET(SalomePyQtGUILight_WRAPPED_SOURCES + ${CMAKE_CURRENT_BINARY_DIR}/SalomePyQtGUILight/salomepyqtguilight_module_wrapper.cpp) + + CREATE_PYSIDE_MODULE( + SalomePyQtGUILight + ${CMAKE_CURRENT_SOURCE_DIR}/SALOME_PYQT_GUILight_global.h + "" + _link_LIBRARIES + "" + "" + SalomePyQtGUILight_SOURCES + SalomePyQtGUILight_WRAPPED_SOURCES + ${CMAKE_CURRENT_SOURCE_DIR}/SALOME_PYQT_GUILight_typesystem.xml + ) +ELSE(SALOME_USE_PYSIDE) + # sources / sip wrappings + PYQT4_WRAP_SIP(_sip_SOURCES ${_sip_files}) + # sources / to compile + SET(SalomePyQtGUILight_SOURCES ${SalomePyQtGUILight_SOURCES} ${_sip_SOURCES}) + + # --- rules --- + + ADD_LIBRARY(SalomePyQtGUILight ${SalomePyQtGUILight_SOURCES}) + TARGET_LINK_LIBRARIES(SalomePyQtGUILight ${_link_LIBRARIES}) +ENDIF(SALOME_USE_PYSIDE) + +INSTALL(TARGETS SalomePyQtGUILight DESTINATION ${SALOME_INSTALL_LIBS}) INSTALL(FILES ${SalomePyQtGUILight_HEADERS} DESTINATION ${SALOME_INSTALL_HEADERS}) -FILE(GLOB make_clean_files ${CMAKE_CURRENT_BINARY_DIR}/sip*) +IF(SALOME_USE_PYSIDE) + FILE(GLOB make_clean_files ${CMAKE_CURRENT_BINARY_DIR}/sip*) +ENDIF(SALOME_USE_PYSIDE) + SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${make_clean_files}") diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_GUILight_global.h b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_GUILight_global.h new file mode 100644 index 000000000..3ae5adb91 --- /dev/null +++ b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_GUILight_global.h @@ -0,0 +1,29 @@ +// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE +// +// 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, or (at your option) any later version. +// +// 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 +// + +// File : SALOME_PYQT_ModuleLight_global.h +// Author : Roman NIKOLAEV, (roman.nikolaev@opencascade.com) + +#undef QT_NO_STL +#undef QT_NO_STL_WCHAR +#ifndef NULL +#define NULL 0 +#endif +#include "pyside_global.h" +#include diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_GUILight_typesystem.xml b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_GUILight_typesystem.xml new file mode 100644 index 000000000..6b3a95291 --- /dev/null +++ b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_GUILight_typesystem.xml @@ -0,0 +1,32 @@ + + + + + + + + diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.cxx b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.cxx index da7043dbd..4b4ce7cdc 100644 --- a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.cxx +++ b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.cxx @@ -29,7 +29,14 @@ #include "SUIT_DataObjectIterator.h" #include "LightApp_Application.h" #include "SUIT_DataBrowser.h" + +#ifdef WITH_PYQT4 #include "sipAPISalomePyQtGUILight.h" +#endif + +#ifdef WITH_PYSIDE +#include "salomepyqtguilight_python.h" +#endif #ifndef GUI_DISABLE_CORBA #include @@ -60,12 +67,19 @@ // and to get C API from sip : sipBuildResult for example // -#define INIT_FUNCTION initSalomePyQtGUILight -#if defined(SIP_STATIC_MODULE) -extern "C" void INIT_FUNCTION(); -#else -PyMODINIT_FUNC INIT_FUNCTION(); -#endif +#ifdef WITH_PYQT4 + #define INIT_FUNCTION initSalomePyQtGUILight + #if defined(SIP_STATIC_MODULE) + extern "C" void INIT_FUNCTION(); + #else + PyMODINIT_FUNC INIT_FUNCTION(); + #endif //SIP_STATIC_MODULE +#endif //WITH_PYQT4 + +#ifdef WITH_PYSIDE + #define INIT_FUNCTION initSalomePyQtGUILight + extern "C" void INIT_FUNCTION(); +#endif //WITH_PYSIDE /*! \fn CAM_Module* createModule() diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_PyModule.cxx b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_PyModule.cxx index 4a21a4085..1e8b9e567 100644 --- a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_PyModule.cxx +++ b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_PyModule.cxx @@ -50,7 +50,14 @@ #include +#ifdef WITH_PYQT4 #include "sipAPISalomePyQtGUILight.h" +#endif + +#ifdef WITH_PYSIDE +#include +#include +#endif /*! \brief Default menu group number. @@ -1809,10 +1816,16 @@ void PyModuleHelper::setWorkSpace() if ( d ) aWorkspace = d->workstack(); } +#ifdef WITH_PYQT4 #if SIP_VERSION < 0x040800 PyObjWrapper pyws( sipBuildResult( 0, "M", aWorkspace, sipClass_QWidget) ); #else PyObjWrapper pyws( sipBuildResult( 0, "D", aWorkspace, sipType_QWidget , NULL) ); +#endif +#endif + +#ifdef WITH_PYSIDE + PyObjWrapper pyws(Shiboken::Converter::toPython(aWorkspace)); #endif // ... and finally call Python module's setWorkSpace() method (obsolete) if ( PyObject_HasAttrString( myPyModule, (char*)"setWorkSpace" ) ) { @@ -1898,11 +1911,19 @@ void PyModuleHelper::internalInitialize( CAM_Application* app ) // parse the return value // it should be a map: {integer:integer} int aKey, aValue; +#ifdef WITH_PYQT4 if( key && PyInt_Check( key ) && value && PyInt_Check( value ) ) { - aKey = PyInt_AsLong( key ); + aKey = PyInt_AsLong( key ); aValue = PyInt_AsLong( value ); - myWindowsMap[ aKey ] = aValue; - } + } +#endif +#ifdef WITH_PYSIDE + if( key && Shiboken::isShibokenEnum(key) && value && Shiboken::isShibokenEnum(value) ) { + aKey = Shiboken::Enum::getValue(key); + aValue = Shiboken::Enum::getValue(value); + myWindowsMap[ aKey ] = aValue; + } +#endif } } } @@ -2259,11 +2280,16 @@ void PyModuleHelper::internalContextMenu( const QString& context, QMenu* menu ) // we create popup menus without help of QtxPopupMgr if ( myXmlHandler ) myXmlHandler->createPopup( menu, aContext, aParent, aObject ); - +#ifdef WITH_PYQT4 #if SIP_VERSION < 0x040800 - PyObjWrapper sipPopup( sipBuildResult( 0, "M", menu, sipClass_QMenu ) ); + PyObjWrapper aPopup( sipBuildResult( 0, "M", menu, sipClass_QMenu ) ); #else - PyObjWrapper sipPopup( sipBuildResult( 0, "D", menu, sipType_QMenu, NULL ) ); + PyObjWrapper aPopup( sipBuildResult( 0, "D", menu, sipType_QMenu, NULL ) ); +#endif +#endif + +#ifdef WITH_PYSIDE + PyObjWrapper aPopup( Shiboken::Converter::toPython(menu) ); #endif // then call Python module's createPopupMenu() method (for new modules) @@ -2271,7 +2297,7 @@ void PyModuleHelper::internalContextMenu( const QString& context, QMenu* menu ) PyObjWrapper res1( PyObject_CallMethod( myPyModule, (char*)"createPopupMenu", (char*)"Os", - sipPopup.get(), + aPopup.get(), context.toLatin1().constData() ) ); if( !res1 ) { PyErr_Print(); @@ -2284,7 +2310,7 @@ void PyModuleHelper::internalContextMenu( const QString& context, QMenu* menu ) PyObjWrapper res2( PyObject_CallMethod( myPyModule, (char*)"customPopup", (char*)"Osss", - sipPopup.get(), + aPopup.get(), aContext.toLatin1().constData(), aObject.toLatin1().constData(), aParent.toLatin1().constData() ) ); @@ -2471,14 +2497,21 @@ void PyModuleHelper::internalLoad( const QStringList& files, bool& opened ) QStringList* theList = new QStringList( files ); + +#ifdef WITH_PYQT4 #if SIP_VERSION < 0x040800 - PyObjWrapper sipList( sipBuildResult( 0, "M", theList, sipClass_QStringList ) ); + PyObjWrapper aList( sipBuildResult( 0, "M", theList, sipClass_QStringList ) ); #else - PyObjWrapper sipList( sipBuildResult( 0, "D", theList, sipType_QStringList, NULL ) ); + PyObjWrapper aList( sipBuildResult( 0, "D", theList, sipType_QStringList, NULL ) ); +#endif +#endif + +#ifdef WITH_PYSIDE + PyObjWrapper aList(Shiboken::Conversions::copyToPython(SbkPySide_QtCoreTypeConverters[SBK_QSTRINGLIST_IDX], &files)); #endif if ( PyObject_HasAttrString(myPyModule , (char*)"openFiles") ) { PyObjWrapper res( PyObject_CallMethod( myPyModule, (char*)"openFiles", - (char*)"O", sipList.get())); + (char*)"O", aList.get())); if( !res || !PyBool_Check( res )) { PyErr_Print(); opened = false; @@ -2625,14 +2658,21 @@ void PyModuleHelper::internalDropObjects( const DataObjectList& what, SUIT_DataO if ( dataObject ) theList->append( dataObject->entry() ); } +#ifdef WITH_PYQT4 #if SIP_VERSION < 0x040800 - PyObjWrapper sipList( sipBuildResult( 0, "M", theList, sipClass_QStringList) ); + PyObjWrapper aList( sipBuildResult( 0, "M", theList, sipClass_QStringList) ); #else - PyObjWrapper sipList( sipBuildResult( 0, "D", theList, sipType_QStringList, NULL) ); + PyObjWrapper aList( sipBuildResult( 0, "D", theList, sipType_QStringList, NULL) ); +#endif #endif + +#ifdef WITH_PYSIDE + PyObjWrapper aList(Shiboken::Conversions::copyToPython(SbkPySide_QtCoreTypeConverters[SBK_QSTRINGLIST_IDX], &theList)); +#endif + if ( PyObject_HasAttrString(myPyModule, (char*)"dropObjects") ) { PyObjWrapper res( PyObject_CallMethod( myPyModule, (char*)"dropObjects", (char*)"Osii", - sipList.get(), + aList.get(), whereObject->entry().toLatin1().constData(), row, action ) ); diff --git a/src/SALOME_PYQT/SalomePyQt/CMakeLists.txt b/src/SALOME_PYQT/SalomePyQt/CMakeLists.txt index 692883aac..63b7fc706 100755 --- a/src/SALOME_PYQT/SalomePyQt/CMakeLists.txt +++ b/src/SALOME_PYQT/SalomePyQt/CMakeLists.txt @@ -17,15 +17,19 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # -INCLUDE(UsePyQt4) +IF(SALOME_USE_PYSIDE) + INCLUDE(UsePySide) +ELSE(SALOME_USE_PYSIDE) + INCLUDE(UsePyQt4) +ENDIF(SALOME_USE_PYSIDE) IF(SALOME_USE_VTKVIEWER) INCLUDE(${VTK_USE_FILE}) ENDIF() # --- options --- -# additional include directories -INCLUDE_DIRECTORIES( +# --- common include directories --- +SET(SalomePyQt_INCLUDE_DIRS ${CAS_INCLUDE_DIRS} ${QT_INCLUDES} ${QWT_INCLUDE_DIR} @@ -48,6 +52,23 @@ INCLUDE_DIRECTORIES( ${PROJECT_SOURCE_DIR}/src/SUIT ) +# additional include directories +IF(SALOME_USE_PYSIDE) + SET(SalomePyQt_INCLUDE_DIRS + ${SalomePyQt_INCLUDE_DIRS} + ${CMAKE_CURRENT_BINARY_DIR}/SalomePyQt + ${SHIBOKEN_INCLUDE_DIR} + ${PYSIDE_INCLUDE_DIRS}) +ELSE(SALOME_USE_PYSIDE) + SET(SalomePyQt_INCLUDE_DIRS + ${SalomePyQt_INCLUDE_DIRS} + ${SIP_INCLUDE_DIRS}) +ENDIF(SALOME_USE_PYSIDE) + +INCLUDE_DIRECTORIES( + ${SalomePyQt_INCLUDE_DIRS} +) + IF(SALOME_LIGHT_ONLY) #disable 'ENABLE_CORBA' feature SET(PYQT_SIPFLAGS ${PYQT_SIPFLAGS} "-xENABLE_CORBA;") @@ -58,6 +79,15 @@ ELSE(SALOME_LIGHT_ONLY) ENDIF(SALOME_LIGHT_ONLY) # additional preprocessor / compiler flags + +# additional preprocessor / compiler flags +IF(SALOME_USE_PYSIDE) + SET(PACKAGE_DEFINITIONS ${PYSIDE_DEFINITIONS}) +ELSE(SALOME_USE_PYSIDE) + SET(PACKAGE_DEFINITIONS ${PYQT4_DEFINITIONS}) +ENDIF(SALOME_USE_PYSIDE) + + ADD_DEFINITIONS( ${QWT_DEFINITIONS} ${QT_DEFINITIONS} @@ -65,7 +95,7 @@ ADD_DEFINITIONS( ${BOOST_DEFINITIONS} ${PYTHON_DEFINITIONS} ${OMNIORB_DEFINITIONS} -) + ${PACKAGE_DEFINITIONS}) # libraries to link to SET(_link_LIBRARIES @@ -84,15 +114,19 @@ SET(_moc_HEADERS SalomePyQt.h) # --- resources --- # sip files / to be processed by sip -SET(_sip_files SalomePyQt.sip) +IF(NOT SALOME_USE_PYSIDE) + SET(_sip_files SalomePyQt.sip) +ENDIF(NOT SALOME_USE_PYSIDE) # --- sources --- # sources / moc wrappings QT4_WRAP_CPP(_moc_SOURCES ${_moc_HEADERS}) -# sources / sip wrappings -PYQT4_WRAP_SIP(_sip_SOURCES ${_sip_files}) +IF(NOT SALOME_USE_PYSIDE) + # sources / sip wrappings + PYQT4_WRAP_SIP(_sip_SOURCES ${_sip_files}) +ENDIF(NOT SALOME_USE_PYSIDE) # sources / static SET(_other_SOURCES SalomePyQt.cxx) @@ -101,16 +135,52 @@ SET(_other_SOURCES SalomePyQt.cxx) SET(SalomePyQt_SOURCES ${_other_SOURCES} ${_moc_SOURCES} ${_sip_SOURCES}) # --- rules --- +IF(SALOME_USE_PYSIDE) + + # --- list of the wrapped sources --- + SET(SalomePyQt_WRAPPED_SOURCES + ${CMAKE_CURRENT_BINARY_DIR}/SalomePyQt/salomepyqt_module_wrapper.cpp + ${CMAKE_CURRENT_BINARY_DIR}/SalomePyQt/salome_selection_wrapper.cpp + ${CMAKE_CURRENT_BINARY_DIR}/SalomePyQt/qtxaction_wrapper.cpp + ${CMAKE_CURRENT_BINARY_DIR}/SalomePyQt/qtxactionset_wrapper.cpp + ${CMAKE_CURRENT_BINARY_DIR}/SalomePyQt/qtxactiongroup_wrapper.cpp + ${CMAKE_CURRENT_BINARY_DIR}/SalomePyQt/plot2d_curve_wrapper.cpp + ${CMAKE_CURRENT_BINARY_DIR}/SalomePyQt/salomepyqt_wrapper.cpp) + + # --- module include directories --- + SET(SalomePy_MODULE_INCLUDES + ${PROJECT_SOURCE_DIR}/src/Qtx + ${PROJECT_SOURCE_DIR}/src/Plot2d) + + + # --- create pyside module --- + MESSAGE("Create pyside module in the ${CAMKE_CURRENT_SOURCE_DIR}") + CREATE_PYSIDE_MODULE( + SalomePyQt + ${CMAKE_CURRENT_SOURCE_DIR}/SalomePyQt_global.h + SalomePy_MODULE_INCLUDES + _link_LIBRARIES + "" + "" + SalomePyQt_SOURCES + SalomePyQt_WRAPPED_SOURCES + ${CMAKE_CURRENT_SOURCE_DIR}/SalomePyQt_typesystem.xml + ) -ADD_LIBRARY(SalomePyQt ${SalomePyQt_SOURCES}) -TARGET_LINK_LIBRARIES(SalomePyQt ${_link_LIBRARIES}) -INSTALL(TARGETS SalomePyQt DESTINATION ${SALOME_INSTALL_LIBS}) +ELSE(SALOME_USE_PYSIDE) + ADD_LIBRARY(SalomePyQt ${SalomePyQt_SOURCES}) + TARGET_LINK_LIBRARIES(SalomePyQt ${_link_LIBRARIES}) +ENDIF(SALOME_USE_PYSIDE) +# --- set prefix --- +SET_TARGET_PROPERTIES(SalomePyQt PROPERTIES PREFIX "") + +# --- set correct names of the library on win32 platform --- IF(WIN32) SET_TARGET_PROPERTIES(SalomePyQt PROPERTIES SUFFIX ".pyd" DEBUG_OUTPUT_NAME SalomePyQt_d RELEASE_OUTPUT_NAME SalomePyQt) -ELSE() - SET_TARGET_PROPERTIES(SalomePyQt PROPERTIES PREFIX "") -ENDIF() +ENDIF(WIN32) + +INSTALL(TARGETS SalomePyQt DESTINATION ${SALOME_INSTALL_LIBS}) FILE(GLOB make_clean_files ${CMAKE_CURRENT_BINARY_DIR}/sip*) SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${make_clean_files}") diff --git a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.h b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.h index e9956afd4..8adcc18a9 100644 --- a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.h +++ b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.h @@ -81,7 +81,7 @@ enum MenuName { Help = 7 }; -enum { +enum WindowType { WT_ObjectBrowser = LightApp_Application::WT_ObjectBrowser, WT_PyConsole = LightApp_Application::WT_PyConsole, WT_LogWindow = LightApp_Application::WT_LogWindow, @@ -93,7 +93,7 @@ enum { #endif }; -enum { +enum PrefType { PT_Auto = LightApp_Preferences::Auto, PT_Space = LightApp_Preferences::Space, PT_Bool = LightApp_Preferences::Bool, diff --git a/src/SALOME_PYQT/SalomePyQt/SalomePyQt_global.h b/src/SALOME_PYQT/SalomePyQt/SalomePyQt_global.h new file mode 100644 index 000000000..383934e04 --- /dev/null +++ b/src/SALOME_PYQT/SalomePyQt/SalomePyQt_global.h @@ -0,0 +1,34 @@ +// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE +// +// 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, or (at your option) any later version. +// +// 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 +// + +// File : SalomePyQt_global.h +// Author : Roman NIKOLAEV, (roman.nikolaev@opencascade.com) + +#undef QT_NO_STL +#undef QT_NO_STL_WCHAR +#ifndef NULL +#define NULL 0 +#endif +#include "pyside_global.h" + +#include +#include +#include +#include +#include diff --git a/src/SALOME_PYQT/SalomePyQt/SalomePyQt_typesystem.xml b/src/SALOME_PYQT/SalomePyQt/SalomePyQt_typesystem.xml new file mode 100644 index 000000000..0280b1b56 --- /dev/null +++ b/src/SALOME_PYQT/SalomePyQt/SalomePyQt_typesystem.xml @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + %PYARG_0 = %0; + + + + + diff --git a/src/SalomeApp/salome_pluginsmanager.py b/src/SalomeApp/salome_pluginsmanager.py index fc63c95b4..9f2640920 100644 --- a/src/SalomeApp/salome_pluginsmanager.py +++ b/src/SalomeApp/salome_pluginsmanager.py @@ -44,7 +44,7 @@ name salome_plugins.py (example follows):: import salome_pluginsmanager def about(context): - from PyQt4.QtGui import QMessageBox + from PySide.QtGui import QMessageBox QMessageBox.about(None, "About SALOME pluginmanager", "SALOME plugins manager in SALOME virtual application ") salome_pluginsmanager.AddFunction('About plugins','About SALOME pluginmanager',about) @@ -84,8 +84,8 @@ context attributes: """ import os,sys,traceback -from PyQt4 import QtGui -from PyQt4 import QtCore +from PySide import QtGui +from PySide import QtCore import salome