Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Michael Reuter
committed
May 14, 2014
1 parent
3d36609
commit 2d258e0
Showing
5 changed files
with
240 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
########################################################################### | ||
# Do the sip generation, for python bindings | ||
########################################################################### | ||
|
||
set( PY_MODULE_NAME mantidvsipython ) | ||
|
||
include_directories ( ${PYTHON_INCLUDE_PATH} ) | ||
|
||
set ( SIP_SPEC ${CMAKE_CURRENT_SOURCE_DIR}/mantidvsi.sip ) | ||
set ( SIP_SRC_IN ${CMAKE_CURRENT_SOURCE_DIR}/sip_mantidvsi.cpp.in ) | ||
set ( SIP_SRC ${CMAKE_CURRENT_BINARY_DIR}/sip_mantidvsi.cpp ) | ||
set ( SIP_SRC_AUTO sipmantidvsipythonpart0.cpp ) | ||
|
||
# We need to manually add all the headers that are in the sip file | ||
# so that the dependencies are known to CMake | ||
set ( SIP_HDRS | ||
../../../MantidQt/API/inc/MantidQtAPI/VatesViewerInterface.h | ||
../ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/MdViewerWidget.h | ||
) | ||
|
||
set( SRC_UNITY_IGNORE_FILES ) | ||
|
||
########################################################################### | ||
# Sip generated files | ||
########################################################################### | ||
|
||
# The code generated by sip causes compiler warnings therefore the | ||
# generated file is wrapped by ${SIP_SRC} and these warnings are | ||
# disabled. In order for VS2010 to to this correctly the second | ||
# custom command below is required | ||
|
||
# Flags used: | ||
# -e : C++ exceptions turn into python exceptions. | ||
# -j1 : split into 1 file | ||
# -w : enable warnings | ||
# -o : automatic docstrings (not supported in old version < 4.10) | ||
|
||
add_custom_command ( OUTPUT ${SIP_SRC_AUTO} | ||
COMMAND ${SIP_EXECUTABLE} | ||
-I ${PYQT4_SIP_DIR} ${PYQT4_SIP_FLAGS} | ||
-c ${CMAKE_CURRENT_BINARY_DIR} -j1 -w | ||
-e | ||
${SIP_SPEC} | ||
DEPENDS mantidvsi.sip ${SIP_HDRS} | ||
COMMENT "Generating mantidvsi python bindings using sip" | ||
) | ||
|
||
add_custom_command ( OUTPUT ${SIP_SRC} | ||
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${SIP_SRC_IN} ${SIP_SRC} | ||
DEPENDS ${SIP_SRC_AUTO} | ||
COMMENT "" | ||
) | ||
|
||
# Needed for sip.h header that can end up in a different place to to the main Python include directory | ||
include_directories ( ${SIP_INCLUDE_DIR} ) | ||
|
||
# Needed for sip generated files to find includes in src | ||
include_directories ( ${CMAKE_CURRENT_SOURCE_DIR} ) | ||
|
||
# Other folders that need to be included... | ||
include_directories ( ../QtWidgets/inc ) | ||
include_directories ( ../ViewWidgets/inc ) | ||
include_directories ( ${CMAKE_SOURCE_DIR}/MantidQt/API/inc ) | ||
# to find the ui_*.h auto-generated files | ||
include_directories ( ${CMAKE_CURRENT_BINARY_DIR}/../QtWidgets ) | ||
include_directories ( ${CMAKE_CURRENT_BINARY_DIR}/../ViewWidgets ) | ||
|
||
########################################################################### | ||
# Python files | ||
########################################################################### | ||
set( PY_FILES vsi.py ) | ||
copy_python_files_to_dir ( "${PY_FILES}" | ||
${CMAKE_CURRENT_SOURCE_DIR} | ||
${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR} | ||
PYTHON_INSTALL_FILES ) | ||
|
||
|
||
# This creates the target library for python bindings and handles the python modules | ||
add_library ( ${PY_MODULE_NAME} MODULE ${SIP_SRC} ${PYTHON_INSTALL_FILES} ) | ||
|
||
if(WIN32) | ||
# Windows: Python library name needs to end in .pyd for Windows | ||
set_target_properties( ${PY_MODULE_NAME} PROPERTIES PREFIX "" SUFFIX ".pyd" ) | ||
# Debug python library expects imported module names to end in _d | ||
if ( PYTHON_DEBUG_LIBRARY ) | ||
set_target_properties ( ${PY_MODULE_NAME} PROPERTIES DEBUG_OUTPUT_NAME ${PY_MODULE_NAME}_d ) | ||
endif () | ||
elseif ( APPLE ) | ||
# Mac: and in .so on the Mac, with no "lib" prefix either | ||
set_target_properties ( ${PY_MODULE_NAME} PROPERTIES PREFIX "" SUFFIX .so ) | ||
else () | ||
# Linux: needs to NOT have the usual "lib" prefix. | ||
set_target_properties( ${PY_MODULE_NAME} PROPERTIES PREFIX "" ) | ||
endif () | ||
|
||
# ... and links to other required libs ... | ||
target_link_libraries ( ${PY_MODULE_NAME} | ||
VatesAPI MantidQtAPI VatesSimpleGuiViewWidgets VatesSimpleGuiQtWidgets | ||
${QT_LIBRARIES} ${QWT_LIBRARIES} | ||
${PYTHON_LIBRARIES} | ||
) | ||
|
||
########################################################################### | ||
# Installation settings | ||
########################################################################### | ||
|
||
install ( TARGETS ${PY_MODULE_NAME} DESTINATION ${BIN_DIR} ) | ||
|
||
install ( FILES ${PY_FILES} DESTINATION ${BIN_DIR} ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/******************************************************************/ | ||
/* | ||
This file is a SIP file for binding C++ methods of the VatesSimpleGui to Python. | ||
*/ | ||
/******************************************************************/ | ||
|
||
// Define the module name. This has to match the library filename | ||
%Module mantidvsipython | ||
|
||
/******************************** SIP Imports *********************/ | ||
%Import QtCore/QtCoremod.sip | ||
%Import QtGui/QtGuimod.sip | ||
|
||
/******************************************************************/ | ||
/* | ||
namespace MantidQt | ||
{ | ||
namespace API | ||
{ | ||
|
||
class VatesViewerInterface : public QWidget { | ||
%TypeHeaderCode | ||
#include "MantidQtAPI/VatesViewerInterface.h" | ||
%End | ||
|
||
public: | ||
VatesViewerInterface(); | ||
}; | ||
|
||
}; // namespace API | ||
}; // namespace MantidQt | ||
|
||
namespace Mantid | ||
{ | ||
namespace Vates | ||
{ | ||
namespace SimpleGui | ||
{ | ||
namespace MantidQt.API; | ||
|
||
class MdViewerWidget : public MantidQt.API.VatesViewerInterface { | ||
%TypeHeaderCode | ||
#include "MantidVatesSimpleGuiViewWidgets/MdViewerWidget.h" | ||
%End | ||
|
||
public: | ||
MdViewerWidget(); | ||
void setupPluginMode(); | ||
}; | ||
|
||
}; // namespace SimpleGui | ||
}; // namespace Vates | ||
}; // namespace Mantid | ||
*/ | ||
|
||
|
||
namespace Mantid | ||
{ | ||
namespace Vates | ||
{ | ||
namespace SimpleGui | ||
{ | ||
|
||
class MdViewerWidget : public QWidget { | ||
%TypeHeaderCode | ||
#include "MantidVatesSimpleGuiViewWidgets/MdViewerWidget.h" | ||
%End | ||
|
||
public: | ||
MdViewerWidget(); | ||
void setupPluginMode(); | ||
}; | ||
|
||
}; // namespace SimpleGui | ||
}; // namespace Vates | ||
}; // namespace Mantid | ||
|
13 changes: 13 additions & 0 deletions
13
Code/Mantid/Vates/VatesSimpleGui/Python/sip_mantidvsi.cpp.in
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
//------------------------------------------------------------------------------ | ||
// A wrapper for the auto-generated sip*.cpp files to disable warnings | ||
// that we can't control | ||
//------------------------------------------------------------------------------ | ||
#if defined(__GNUC__) && !(defined(__INTEL_COMPILER)) | ||
#pragma GCC diagnostic ignored "-Wuninitialized" | ||
#pragma GCC diagnostic ignored "-Wconversion" | ||
#pragma GCC diagnostic ignored "-Wunused-variable" | ||
#pragma GCC diagnostic ignored "-Wparentheses" | ||
#pragma GCC diagnostic ignored "-Wcast-qual" | ||
#endif | ||
|
||
#include "sipmantidvsipythonpart0.cpp" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
try: | ||
import mantidvsipython as mvp | ||
|
||
def create_window(window_class, *setups): | ||
""" | ||
Function to create the requested widget. | ||
Parameters: | ||
---------- | ||
setups :: Functions (as strings) that need to be called on the widget | ||
before showing. | ||
""" | ||
from PyQt4 import QtCore | ||
from PyQt4 import QtGui | ||
import sys | ||
|
||
app_created = False | ||
app = QtCore.QCoreApplication.instance() | ||
if app is None: | ||
app = QtGui.QApplication(sys.argv) | ||
app_created = True | ||
app.references = set() | ||
window = window_class() | ||
for setup in setups: | ||
getattr(window, setup)() | ||
app.references.add(window) | ||
window.show() | ||
if app_created: | ||
app.exec_() | ||
return window | ||
|
||
def show_vsi(): | ||
widget = create_window(mvp.Mantid.Vates.SimpleGui.MdViewerWidget, | ||
"setupPluginMode") | ||
return widget | ||
|
||
except ImportError: | ||
print "MantidVsi module is not available!" | ||
|