| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 | 
// QT includes#include <QFile>#include <QFileInfo>#include <QApplication>// PythonQT includes#include <PythonQt.h>// CTK includes#include "ctkSimplePythonManager.h"#include "ctkSimplePythonQtDecorators.h"#include "ctkSimplePythonShellConfigure.h" // For CTK_WRAP_PYTHONQT_LIGHT, CTK_WRAP_PYTHONQT_USE_VTK and CTK_BUILD_SHARED_LIBS#ifdef CTK_WRAP_PYTHONQT_USE_VTK# include "ctkVTKPythonQtWrapperFactory.h"#endif#if defined(CTK_WRAP_PYTHONQT_LIGHT)# ifndef CTK_BUILD_SHARED_LIBS  // PythonQt wrapper initialization methods  @CTK_PYTHONQT_INITIALIZATION_METHOD_DEFINITION@# endif#endif#ifdef CTK_WRAP_PYTHONQT_USE_VTK# if defined(CMAKE_INTDIR)#  define VTK_PYTHON_LIBRARY_DIR VTK_PYTHON_LIBRARY_DIR_BUILD "/" CMAKE_INTDIR# else#  define VTK_PYTHON_LIBRARY_DIR VTK_PYTHON_LIBRARY_DIR_BUILD# endif#endif//-----------------------------------------------------------------------------ctkSimplePythonManager::ctkSimplePythonManager(QObject* _parent) : Superclass(_parent){}//-----------------------------------------------------------------------------ctkSimplePythonManager::~ctkSimplePythonManager(){}//-----------------------------------------------------------------------------QStringList ctkSimplePythonManager::pythonPaths(){  QStringList paths;  paths << Superclass::pythonPaths();  QString self_dir = QFileInfo(qApp->applicationFilePath()).absolutePath();  QString ctk_python_dir = self_dir;  #if defined(CMAKE_INTDIR)    ctk_python_dir.append("/..");  #endif  ctk_python_dir.append("/Python");  paths << QFileInfo(ctk_python_dir).absoluteFilePath();#ifdef CTK_BUILD_SHARED_LIBS  // Path containing python module  paths << self_dir;#endif#ifdef CTK_WRAP_PYTHONQT_USE_VTK  // Try to put the VTK python module location in sys.path.  QString vtk_package_dir = "@VTK_DIR@/Wrapping/Python";  bool found_vtk = false;  QFileInfo fi(vtk_package_dir);  vtk_package_dir = fi.absoluteFilePath();  if (fi.isDir())    {    // This executable is running from the build tree.  Prepend the    // library directory and package directory to the search path.    paths << vtk_package_dir;    paths << VTK_PYTHON_LIBRARY_DIR;    found_vtk = true;    }  Q_ASSERT(found_vtk);  if (!found_vtk)    {    // TODO Handle case when the application is started from an installed tree    }#endif  return paths;}//-----------------------------------------------------------------------------void ctkSimplePythonManager::preInitialization(){  Superclass::preInitialization();#if defined(CTK_WRAP_PYTHONQT_LIGHT)# ifndef CTK_BUILD_SHARED_LIBS  // Initialize wrappers  @CTK_PYTHONQT_INITIALIZATION_METHOD_CALL@# endif#endif#ifdef CTK_WRAP_PYTHONQT_USE_VTK  this->addWrapperFactory(new ctkVTKPythonQtWrapperFactory);#endif  // Register decorators  this->registerPythonQtDecorator(new ctkSimplePythonQtDecorators(this));  // Add object to python interpreter context  this->addObjectToPythonMain("_ctkSimplePythonShellInstance", qApp);}//-----------------------------------------------------------------------------void ctkSimplePythonManager::executeInitializationScripts(){  QString self_dir = QFileInfo(qApp->applicationFilePath()).absolutePath();  QString initFile = self_dir;  #if defined(CMAKE_INTDIR)  initFile.append("/..");  #endif  initFile.append("/Python/ctkSimplePythonShell.py");  Q_ASSERT(QFile::exists(initFile));  // Evaluate application script  this->executeFile(initFile);}
 |