CTK  0.1.0
The Common Toolkit is a community effort to provide support code for medical image analysis, surgical navigation, and related projects.
Public Types | Signals | Public Member Functions | Static Public Member Functions | Protected Slots | Protected Member Functions | Protected Attributes | List of all members
ctkAbstractPythonManager Class Reference

#include <Libs/Scripting/Python/Core/ctkAbstractPythonManager.h>

Inheritance diagram for ctkAbstractPythonManager:
Inheritance graph
[legend]
Collaboration diagram for ctkAbstractPythonManager:
Collaboration graph
[legend]

Public Types

enum  ExecuteStringMode { EvalInput = 0 , FileInput , SingleInput }
 
typedef QObject Superclass
 

Signals

void pythonInitialized ()
 
void pythonPreInitialized ()
 
void systemExitExceptionRaised (int exitCode)
 

Public Member Functions

void addObjectToPythonMain (const QString &name, QObject *obj)
 
void addWrapperFactory (PythonQtForeignWrapperFactory *factory)
 
 ctkAbstractPythonManager (QObject *_parent=NULL)
 
Q_INVOKABLE void executeFile (const QString &filename)
 Execute a python script with the given filename. More...
 
Q_INVOKABLE QVariant executeString (const QString &code, ExecuteStringMode mode=FileInput)
 
QVariant getVariable (const QString &varName)
 
int initializationFlags () const
 
bool initialize ()
 
bool isPythonInitialized () const
 
PythonQtObjectPtr mainContext ()
 
QStringList pythonAttributes (const QString &pythonVariableName, const QString &module=QLatin1String("__main__"), bool appendParenthesis=false) const
 
bool pythonErrorOccured () const
 
void registerClassForPythonQt (const QMetaObject *metaobject)
 
void registerCPPClassForPythonQt (const char *name)
 
void registerPythonQtDecorator (QObject *decorator)
 
void resetErrorFlag ()
 
void setInitializationFlags (int flags)
 
void setInitializationFunction (void(*initFunction)())
 
void setSystemExitExceptionHandlerEnabled (bool value)
 
bool systemExitExceptionHandlerEnabled () const
 
virtual ~ctkAbstractPythonManager ()
 

Static Public Member Functions

static QStringList dir_object (PyObject *object, bool appendParenthesis=false)
 
static PyObject * pythonModule (const QString &module)
 Given a string of the form "<modulename1>[.<modulenameN>...]" containing modules, return the final module as a PyObject*. More...
 
static PyObject * pythonObject (const QString &variableNameAndFunction)
 
static QStringList splitByDotOutsideParenthesis (const QString &pythonVariableName)
 

Protected Slots

void printStderr (const QString &)
 
void printStdout (const QString &)
 

Protected Member Functions

virtual void executeInitializationScripts ()
 Overload this function to execute script at initialization time. More...
 
void initPythonQt (int flags)
 
virtual void preInitialization ()
 Overload this function to load Decorator and pythonQt wrapper at initialization time. More...
 
virtual QStringList pythonPaths ()
 

Protected Attributes

QScopedPointer< ctkAbstractPythonManagerPrivate > d_ptr
 

Detailed Description

Definition at line 41 of file ctkAbstractPythonManager.h.

Member Typedef Documentation

◆ Superclass

Definition at line 46 of file ctkAbstractPythonManager.h.

Member Enumeration Documentation

◆ ExecuteStringMode

This enum maps to Py_eval_input, Py_file_input and Py_single_input

See also
http://docs.python.org/c-api/veryhigh.html#Py_eval_input
http://docs.python.org/c-api/veryhigh.html#Py_file_input
http://docs.python.org/c-api/veryhigh.html#Py_single_input
Enumerator
EvalInput 
FileInput 
SingleInput 

Definition at line 85 of file ctkAbstractPythonManager.h.

Constructor & Destructor Documentation

◆ ctkAbstractPythonManager()

ctkAbstractPythonManager::ctkAbstractPythonManager ( QObject *  _parent = NULL)

◆ ~ctkAbstractPythonManager()

virtual ctkAbstractPythonManager::~ctkAbstractPythonManager ( )
virtual

Member Function Documentation

◆ addObjectToPythonMain()

void ctkAbstractPythonManager::addObjectToPythonMain ( const QString &  name,
QObject *  obj 
)

◆ addWrapperFactory()

void ctkAbstractPythonManager::addWrapperFactory ( PythonQtForeignWrapperFactory *  factory)

◆ dir_object()

static QStringList ctkAbstractPythonManager::dir_object ( PyObject *  object,
bool  appendParenthesis = false 
)
static

Given a python object, lookup its attributes and return them in a string list. If the argument appendParenthesis is set to True, "()" will be appended to attributes being Python callable.

◆ executeFile()

Q_INVOKABLE void ctkAbstractPythonManager::executeFile ( const QString &  filename)

Execute a python script with the given filename.

◆ executeInitializationScripts()

virtual void ctkAbstractPythonManager::executeInitializationScripts ( )
protectedvirtual

Overload this function to execute script at initialization time.

Reimplemented in ctkSimplePythonManager.

◆ executeString()

Q_INVOKABLE QVariant ctkAbstractPythonManager::executeString ( const QString &  code,
ExecuteStringMode  mode = FileInput 
)

Execute a python of python code (can be multiple lines separated with newline) and return the result as a QVariant.

◆ getVariable()

QVariant ctkAbstractPythonManager::getVariable ( const QString &  varName)

Gets the value of the variable looking in the main module. If the variable is not found returns a default initialized QVariant.

◆ initializationFlags()

int ctkAbstractPythonManager::initializationFlags ( ) const

◆ initialize()

bool ctkAbstractPythonManager::initialize ( )

Initialize python context considering the initializationFlags. Return True if python has been successfully initialized.

See also
setInitializationFlags, mainContext, isPythonInitialized
preInitialization, executeInitializationScripts, pythonPreInitialized, pythonInitialized

◆ initPythonQt()

void ctkAbstractPythonManager::initPythonQt ( int  flags)
protected

◆ isPythonInitialized()

bool ctkAbstractPythonManager::isPythonInitialized ( ) const

Returns True if python is initialized

See also
pythonInitialized

◆ mainContext()

PythonQtObjectPtr ctkAbstractPythonManager::mainContext ( )

Return a reference to the python main context. Calling this function implicitly call initialize() if it hasn't been done.

◆ preInitialization()

virtual void ctkAbstractPythonManager::preInitialization ( )
protectedvirtual

Overload this function to load Decorator and pythonQt wrapper at initialization time.

Reimplemented in ctkSimplePythonManager.

◆ printStderr

void ctkAbstractPythonManager::printStderr ( const QString &  )
protectedslot

◆ printStdout

void ctkAbstractPythonManager::printStdout ( const QString &  )
protectedslot

◆ pythonAttributes()

QStringList ctkAbstractPythonManager::pythonAttributes ( const QString &  pythonVariableName,
const QString &  module = QLatin1String("__main__"),
bool  appendParenthesis = false 
) const

Given a python variable name, if it can be called, try to call the method or instantiate the class, lookup its attributes and return them in a string list. By default the attributes are looked up from main. If the argument appendParenthesis is set to True, "()" will be appended to attributes being Python callable.

◆ pythonErrorOccured()

bool ctkAbstractPythonManager::pythonErrorOccured ( ) const

Returns True if a python error occured.

See also
PythonQt::hadError()

◆ pythonInitialized

void ctkAbstractPythonManager::pythonInitialized ( )
signal

This signal is emitted after python is initialized and scripts are executed

See also
preInitialization
executeScripts

◆ pythonModule()

static PyObject* ctkAbstractPythonManager::pythonModule ( const QString &  module)
static

Given a string of the form "<modulename1>[.<modulenameN>...]" containing modules, return the final module as a PyObject*.

◆ pythonObject()

static PyObject* ctkAbstractPythonManager::pythonObject ( const QString &  variableNameAndFunction)
static

Given a string of the form "<modulename1>[.<modulenameN>...].correspondingObject, return the final object as a PyObject*

See also
pythonModule

◆ pythonPaths()

virtual QStringList ctkAbstractPythonManager::pythonPaths ( )
protectedvirtual

Reimplemented in ctkSimplePythonManager.

◆ pythonPreInitialized

void ctkAbstractPythonManager::pythonPreInitialized ( )
signal

This signal is emitted after python is pre-initialized. Observers can listen for this signal to handle additional initialization steps.

See also
preInitialization

◆ registerClassForPythonQt()

void ctkAbstractPythonManager::registerClassForPythonQt ( const QMetaObject *  metaobject)

◆ registerCPPClassForPythonQt()

void ctkAbstractPythonManager::registerCPPClassForPythonQt ( const char *  name)

◆ registerPythonQtDecorator()

void ctkAbstractPythonManager::registerPythonQtDecorator ( QObject *  decorator)

◆ resetErrorFlag()

void ctkAbstractPythonManager::resetErrorFlag ( )

Reset error flag

See also
PythonQt::clearError()

◆ setInitializationFlags()

void ctkAbstractPythonManager::setInitializationFlags ( int  flags)

Calling this function after mainContext() has been called at least once is a no-op. If not overridden calling this function, the default initialization flags are PythonQt::IgnoreSiteModule and PythonQt::RedirectStdOut.

See also
PythonQt::InitFlags

◆ setInitializationFunction()

void ctkAbstractPythonManager::setInitializationFunction ( void(*)()  initFunction)

Set function that is initialized after preInitialization and before executeInitializationScripts

See also
preInitialization executeInitializationScripts

◆ setSystemExitExceptionHandlerEnabled()

void ctkAbstractPythonManager::setSystemExitExceptionHandlerEnabled ( bool  value)
See also
PythonQt::setSystemExitExceptionHandlerEnabled

◆ splitByDotOutsideParenthesis()

static QStringList ctkAbstractPythonManager::splitByDotOutsideParenthesis ( const QString &  pythonVariableName)
static

Given a python variable name, it returns the string list splited at every dots which will be outside parenthesis (It also takes care about the possibility that quotes can include parenthesis)

◆ systemExitExceptionHandlerEnabled()

bool ctkAbstractPythonManager::systemExitExceptionHandlerEnabled ( ) const
See also
PythonQt::systemExitExceptionHandlerEnabled

◆ systemExitExceptionRaised

void ctkAbstractPythonManager::systemExitExceptionRaised ( int  exitCode)
signal

emitted when both custom SystemExit exception handler is enabled and a SystemExit exception is raised.

See also
setSystemExitExceptionHandlerEnabled(bool), PythonQt::systemExitExceptionRaised(int)

Member Data Documentation

◆ d_ptr

QScopedPointer<ctkAbstractPythonManagerPrivate> ctkAbstractPythonManager::d_ptr
protected

Definition at line 180 of file ctkAbstractPythonManager.h.


The documentation for this class was generated from the following file: