Commit 1e9b2313 authored by jcfr's avatar jcfr
Browse files

ENH: SlicerQT - Added Base/Python directory containing a set of python script...

ENH: SlicerQT - Added Base/Python directory containing a set of python script loaded by the python shell.

slicerqt.py is the main script that should be executed by the python shell.

The scripts logic.py, mrml.py, remoteio.py, teem.py, freesurfer.py will
take care of loading the vtk libraries wrapped in python.

All the script will also be pre-compiled and copied in {Slicer_home}/bin/Python

git-svn-id: http://svn.slicer.org/Slicer4/trunk@12231 3bd1e089-480b-0410-8dfb-8563597acbee
parent 0ebaa023
......@@ -32,3 +32,7 @@ IF (Slicer3_USE_KWWIDGETS)
ENDIF (Slicer3_USE_KWWIDGETS)
ADD_SUBDIRECTORY(CLI)
IF(Slicer3_USE_PYTHONQT)
ADD_SUBDIRECTORY(Python)
ENDIF(Slicer3_USE_PYTHONQT)
#
# Based on ParaView/VTK/Utilities/vtkTclTest2Py/CMakeLists.txt and
# ParaView/VTK/Wrapping/Python/CMakeLists.txt
#
SET(Slicer_PYTHON_FILES
slicer/__init__
slicer/logic
slicer/mrml
slicer/teem
slicer/freesurfer
slicer/remoteio
slicer/slicerqt
slicer/vtk/__init__
)
SET(copied_python_files)
SET(Slicer_PYTHON_MODULE_BINARY_DIR "${Slicer3_BINARY_DIR}/bin/Python")
FOREACH(file ${Slicer_PYTHON_FILES})
SET(src "${CMAKE_CURRENT_SOURCE_DIR}/${file}.py")
SET(tgt "${Slicer_PYTHON_MODULE_BINARY_DIR}/${file}.py")
SET(copied_python_files ${copied_python_files} ${tgt})
ADD_CUSTOM_COMMAND(DEPENDS ${src}
COMMAND ${CMAKE_COMMAND} -E copy ${src} ${tgt}
OUTPUT ${tgt}
COMMENT "source copy")
ENDFOREACH(file)
ADD_CUSTOM_TARGET(CopyPythonFiles
ALL
DEPENDS ${copied_python_files})
# Byte compile the Python files.
SET(compile_all_script "${CMAKE_CURRENT_BINARY_DIR}/compile_all_slicer.py")
CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/compile_all_slicer.py.in"
${compile_all_script}
@ONLY IMMEDIATE)
ADD_CUSTOM_COMMAND(
COMMAND ${PYTHON_EXECUTABLE}
ARGS "${compile_all_script}"
DEPENDS ${copied_python_files} ${compile_all_script}
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/slicer_python_compile_complete"
)
ADD_CUSTOM_TARGET(slicer_pyc ALL
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/slicer_python_compile_complete")
# Install the slicer python module directory
INSTALL(DIRECTORY "${Slicer3_BINARY_DIR}/bin/Python"
DESTINATION "${Slicer3_INSTALL_BIN_DIR}" COMPONENT Runtime
USE_SOURCE_PERMISSIONS)
# Based on paraview/VTK/Wrapping/Python/compile_all_vtk.py.in
import compileall
compileall.compile_dir('@Slicer_PYTHON_MODULE_BINARY_DIR@')
file = open('@CMAKE_CURRENT_BINARY_DIR@/slicer_python_compile_complete', 'w')
file.write('Done')
\ No newline at end of file
""" This module loads the Slicer library modules into its namespace."""
from logic import *
from mrml import *
from teem import *
from freesurfer import *
from remoteio import *
""" This module loads all the classes from the FreeSurfer library into its
namespace."""
import os
if os.name == 'posix':
from libFreeSurferPython import *
else:
from FreeSurferPython import *
""" This module loads all the classes from the vtkSlicerBaseLogic library into its
namespace."""
import os
if os.name == 'posix':
from libSlicerBaseLogicPython import *
else:
from SlicerBaseLogicPython import *
""" This module loads all the classes from the MRML library into its
namespace."""
import os
if os.name == 'posix':
from libMRMLPython import *
else:
from MRMLPython import *
""" This module loads all the classes from the RemoteIO library into its
namespace."""
import os
if os.name == 'posix':
from libRemoteIOPython import *
else:
from RemoteIOPython import *
import slicer
from slicer import vtk
def quit():
exit()
def exit():
app().quit()
def app():
return _qSlicerCoreApplicationInstance
def getModuleNames():
return app().moduleManager().factoryManager().moduleNames()
def getModule(moduleName):
module = app().moduleManager().module(moduleName);
if not module:
print "Could not find module with name '%s" % moduleName
return None
return module
def getModuleGui(moduleName):
module = getModule(moduleName)
if not module:
return None
widgetRepr = module.widgetRepresentation()
if not widgetRepr:
print "Could not find module widget representation with name '%s" % moduleName
return None
return widgetRepr
""" This module loads all the classes from the vtkTeem library into its
namespace."""
import os
if os.name == 'posix':
from libvtkTeemPython import *
else:
from vtkTeemPython import *
""" This will load a subset of vtk"""
import os
libs_to_load = [
"Common",
"Filtering",
"Rendering",
"Graphics",
"Hybrid",
"Views",
"Infovis",
"Widgets",
"Imaging",
"IO"]
# Other libraries to consider loading: Parallel VolumeRendering TextAnalysis Geovis GenericFiltering
prefix = "vtk"
if os.name == 'posix': prefix = "libvtk"
for lib in libs_to_load:
exec "from %s%sPython import *" % (prefix, lib)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment