An update will be applied December 9th, between 12PM and 1:00PM EST (UTC -5:00). The site may be slow during that time.

Commit 4ca8f272 authored by jcfr's avatar jcfr
Browse files

ENH: SlicerQT - Added QTCore/qSlicerPythonManager class and QTCore pythonqt decorator.

SlicerPythonManager is responsible to configure pythonQt by
 - adding the correct path containing the different wrapped libraries.
 - registering the pythonqt decorator
 - executing the python main script 'slicerqt.py'

git-svn-id: http://svn.slicer.org/Slicer4/trunk@12234 3bd1e089-480b-0410-8dfb-8563597acbee
parent e254fe35
......@@ -14,6 +14,7 @@ SET(slicer_qtbase_include_directories
${ModuleDescriptionParser_BINARY_DIR}
${MRMLCLI_SOURCE_DIR}
${MRMLCLI_BINARY_DIR}
${qCTKWidgets_PYTHONQT_INCLUDE_DIR}
)
# Source files
......@@ -36,8 +37,14 @@ SET(slicer_qtbase_SRCS
SET(slicer_qtbase_MOC_SRCS
qSlicerCoreApplication.h
qSlicerModuleManager.h
${slicer_qtbase_pythonqt_MOC_SRCS}
)
# PythonQt decorator
IF(Slicer3_USE_PYTHONQT)
SET(slicer_qtbase_MOC_SRCS ${slicer_qtbase_MOC_SRCS} qSlicerBaseQTBasePythonQtDecorators.h)
ENDIF(Slicer3_USE_PYTHONQT)
# UI files
#SET(slicer_qtbase_UI_SRCS)
......@@ -46,6 +53,7 @@ SET(slicer_qtbase_target_libraries
ModuleDescriptionParser
MRMLCLI
qSlicerBaseQTBase
${qCTKWidgets_PYTHONQT_LIBRARIES}
)
# Resources
......@@ -53,6 +61,24 @@ SET(qt_module_resources
Resources/qSlicerBaseQTCore.qrc
)
# Python wrap
IF(Slicer3_USE_PYTHONQT)
# Sources
SET(slicer_qtbase_SRCS
${slicer_qtbase_SRCS}
qSlicerPythonManager.cxx
qSlicerPythonManager.h
)
# Headers that should run through moc
SET(slicer_qtbase_MOC_SRCS
${slicer_qtbase_MOC_SRCS}
qSlicerPythonManager.h
)
ENDIF(Slicer3_USE_PYTHONQT)
Slicer3_build_slicer_qtbase_library(
NAME ${PROJECT_NAME}
EXPORT_DIRECTIVE ${slicer_qtbase_export_directive}
......
/*=auto=========================================================================
Portions (c) Copyright 2005 Brigham and Women's Hospital (BWH)
All Rights Reserved.
See Doc/copyright/copyright.txt
or http://www.slicer.org/copyright/copyright.txt for details.
Program: 3D Slicer
=========================================================================auto=*/
#ifndef __qSlicerBaseQTBasePythonQtDecorators_h
#define __qSlicerBaseQTBasePythonQtDecorators_h
// QT includes
#include <QObject>
// qCTK includes
#include <qCTKAbstractPythonManager.h>
// VTK includes
#include <vtkInstantiator.h>
#include <vtkPythonUtil.h>
#include <vtkPython.h>
// PythonQT includes
#include <PythonQtObjectPtr.h>
// SlicerQT includes
#include "qSlicerCoreApplication.h"
#include "qSlicerModuleManager.h"
#include "qSlicerModuleFactoryManager.h"
#include "qSlicerAbstractModule.h"
#include "qSlicerAbstractModuleWidget.h"
#include "qSlicerBaseQTCoreExport.h"
// NOTE:
//
// For decorators it is assumed that the methods will never be called
// with the self argument as NULL. The self argument is the first argument
// for non-static methods.
//
class Q_SLICER_BASE_QTCORE_EXPORT qSlicerBaseQTBasePythonQtDecorators : public QObject
{
Q_OBJECT
public:
qSlicerBaseQTBasePythonQtDecorators(qCTKAbstractPythonManager* pythonManager)
{
Q_ASSERT(pythonManager);
pythonManager->registerClassForPythonQt(&qSlicerCoreApplication::staticMetaObject);
pythonManager->registerClassForPythonQt(&qSlicerModuleManager::staticMetaObject);
pythonManager->registerClassForPythonQt(&qSlicerAbstractModule::staticMetaObject);
pythonManager->registerClassForPythonQt(&qSlicerAbstractModuleWidget::staticMetaObject);
pythonManager->registerCPPClassForPythonQt("qSlicerModuleFactoryManager");
}
public slots:
// static methods
QList<QWidget*> static_qSlicerCoreApplication_allWidgets()
{
return qSlicerCoreApplication::allWidgets();
}
//----------------------------------------------------------------------------
// qSlicerCoreApplication
qSlicerModuleManager* moduleManager(qSlicerCoreApplication* app)const
{
return app->moduleManager();
}
void sendEvent(qSlicerCoreApplication* app, QObject* _receiver, QEvent* _event)
{
app->sendEvent(_receiver, _event);
}
void processEvents(qSlicerCoreApplication* app)
{
app->processEvents();
}
//----------------------------------------------------------------------------
// qSlicerModuleFactoryManager
QStringList moduleNames(qSlicerModuleFactoryManager* _factoryManager)
{
return _factoryManager->moduleNames();
}
//----------------------------------------------------------------------------
// qSlicerModuleManager
qSlicerModuleFactoryManager* factoryManager(qSlicerModuleManager* _moduleManager)
{
return _moduleManager->factoryManager();
}
///
bool loadModule(qSlicerModuleManager* _moduleManager, const QString& name)
{
return _moduleManager->loadModule(name);
}
///
bool unLoadModule(qSlicerModuleManager* _moduleManager, const QString& name)
{
return _moduleManager->unLoadModule(name);
}
///
bool isLoaded(qSlicerModuleManager* _moduleManager, const QString& name)const
{
return _moduleManager->isLoaded(name);
}
///
qSlicerAbstractModule* module(qSlicerModuleManager* _moduleManager, const QString& name)
{
return _moduleManager->module(name);
}
//----------------------------------------------------------------------------
// qSlicerAbstractModule
qSlicerAbstractModuleWidget* widgetRepresentation(qSlicerAbstractModule* _module)
{
return _module->widgetRepresentation();
}
};
#endif
/*=auto=========================================================================
Portions (c) Copyright 2005 Brigham and Women's Hospital (BWH)
All Rights Reserved.
See Doc/copyright/copyright.txt
or http://www.slicer.org/copyright/copyright.txt for details.
Program: 3D Slicer
=========================================================================auto=*/
// SlicerQt includes
#include "qSlicerUtils.h"
#include "qSlicerPythonManager.h"
#include "qSlicerCoreApplication.h"
#include "qSlicerBaseQTBasePythonQtDecorators.h"
#include "vtkSlicerConfigure.h" // For VTK_DIR
//-----------------------------------------------------------------------------
qSlicerPythonManager::qSlicerPythonManager(QObject* _parent) : Superclass(_parent)
{
}
//-----------------------------------------------------------------------------
qSlicerPythonManager::~qSlicerPythonManager()
{
}
//-----------------------------------------------------------------------------
QStringList qSlicerPythonManager::pythonPaths()
{
qSlicerCoreApplication * app = qSlicerCoreApplication::application();
QStringList paths;
paths << Superclass::pythonPaths();
paths << app->slicerHome() + "/bin/" + app->intDir();
paths << app->slicerHome() + "/bin/Python";
QString executableExtension = qSlicerUtils::executableExtension();
if (!app->isInstalled())
{
paths << qSlicerUtils::searchTargetInIntDir(QLatin1String(VTK_DIR)+"/bin",
QString("vtk%1").arg(executableExtension));
}
else
{
paths << app->slicerHome() + QString("/lib/vtk-%1.%2").arg(VTK_MAJOR_VERSION).
arg(VTK_MINOR_VERSION);
paths << app->slicerHome() + "/lib/MRML";
paths << app->slicerHome() + "/lib/vtkTeem";
paths << app->slicerHome() + "/lib/FreeSurfer";
paths << app->slicerHome() + "/lib/RemoteIO";
}
return paths;
}
//-----------------------------------------------------------------------------
void qSlicerPythonManager::preInitialization()
{
Superclass::preInitialization();
// Register decorators
this->registerPythonQtDecorator(new qSlicerBaseQTBasePythonQtDecorators(this));
qSlicerCoreApplication* app = qSlicerCoreApplication::application();
// Add object to python interpreter context
this->addObjectToPythonMain("_qSlicerCoreApplicationInstance", app);
// Evaluate application script
this->executeFile(app->slicerHome() + "/bin/Python/slicer/slicerqt.py");
}
/*=auto=========================================================================
Portions (c) Copyright 2005 Brigham and Women's Hospital (BWH)
All Rights Reserved.
See Doc/copyright/copyright.txt
or http://www.slicer.org/copyright/copyright.txt for details.
Program: 3D Slicer
=========================================================================auto=*/
#ifndef __qSlicerPythonManager_h
#define __qSlicerPythonManager_h
// qVTK includes
# include <qVTKAbstractPythonManager.h>
#include "qSlicerBaseQTCoreExport.h"
class PythonQtObjectPtr;
class Q_SLICER_BASE_QTCORE_EXPORT qSlicerPythonManager : public qVTKAbstractPythonManager
{
Q_OBJECT
public:
typedef qVTKAbstractPythonManager Superclass;
qSlicerPythonManager(QObject* parent=NULL);
~qSlicerPythonManager();
protected:
virtual QStringList pythonPaths();
virtual void preInitialization();
};
#endif
......@@ -73,3 +73,7 @@
#else
#define SlicerQDebug(_arg)
#endif
// Library sub-directory
#define VTK_DIR "@VTK_DIR@"
//#define Teem_DIR "@Teem_DIR@"
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