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 | 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)
 
void executeFile (const QString &filename)
 Execute a python script with the given filename. More...
 
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 ()
 

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 37 of file ctkAbstractPythonManager.h.

Member Typedef Documentation

Definition at line 42 of file ctkAbstractPythonManager.h.

Member Enumeration Documentation

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 81 of file ctkAbstractPythonManager.h.

Constructor & Destructor Documentation

ctkAbstractPythonManager::ctkAbstractPythonManager ( QObject *  _parent = NULL)
virtual ctkAbstractPythonManager::~ctkAbstractPythonManager ( )
virtual

Member Function Documentation

void ctkAbstractPythonManager::addObjectToPythonMain ( const QString &  name,
QObject *  obj 
)
void ctkAbstractPythonManager::addWrapperFactory ( PythonQtForeignWrapperFactory *  factory)
void ctkAbstractPythonManager::executeFile ( const QString &  filename)

Execute a python script with the given filename.

virtual void ctkAbstractPythonManager::executeInitializationScripts ( )
protectedvirtual

Overload this function to execute script at initialization time.

Reimplemented in ctkSimplePythonManager.

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.

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.

int ctkAbstractPythonManager::initializationFlags ( ) const
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
void ctkAbstractPythonManager::initPythonQt ( int  flags)
protected
bool ctkAbstractPythonManager::isPythonInitialized ( ) const

Returns True if python is initialized

See also
pythonInitialized
PythonQtObjectPtr ctkAbstractPythonManager::mainContext ( )

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

virtual void ctkAbstractPythonManager::preInitialization ( )
protectedvirtual

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

Reimplemented in ctkSimplePythonManager.

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

Given a python variable name, 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.

bool ctkAbstractPythonManager::pythonErrorOccured ( ) const

Returns True if a python error occured.

See also
PythonQt::hadError()
void ctkAbstractPythonManager::pythonInitialized ( )
signal

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

See also
preInitialization
executeScripts
virtual QStringList ctkAbstractPythonManager::pythonPaths ( )
protectedvirtual

Reimplemented in ctkSimplePythonManager.

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
void ctkAbstractPythonManager::registerClassForPythonQt ( const QMetaObject *  metaobject)
void ctkAbstractPythonManager::registerCPPClassForPythonQt ( const char *  name)
void ctkAbstractPythonManager::registerPythonQtDecorator ( QObject *  decorator)
void ctkAbstractPythonManager::resetErrorFlag ( )

Reset error flag

See also
PythonQt::clearError()
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
void ctkAbstractPythonManager::setInitializationFunction ( void(*)()  initFunction)

Set function that is initialized after preInitialization and before executeInitializationScripts

See also
preInitialization executeInitializationScripts
void ctkAbstractPythonManager::setSystemExitExceptionHandlerEnabled ( bool  value)
See also
PythonQt::setSystemExitExceptionHandlerEnabled
bool ctkAbstractPythonManager::systemExitExceptionHandlerEnabled ( ) const
See also
PythonQt::systemExitExceptionHandlerEnabled
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

QScopedPointer<ctkAbstractPythonManagerPrivate> ctkAbstractPythonManager::d_ptr
protected

Definition at line 157 of file ctkAbstractPythonManager.h.


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