Krita Source Code Documentation
Loading...
Searching...
No Matches
PyKrita Namespace Reference

Classes

class  Python
 
class  version
 Class version. More...
 
class  version_checker
 Class version_checker. More...
 

Enumerations

enum  InitResult {
  INIT_UNINITIALIZED , INIT_OK , INIT_CANNOT_LOAD_PYTHON_LIBRARY , INIT_CANNOT_SET_PYTHON_PATHS ,
  INIT_CANNOT_LOAD_PYKRITA_MODULE
}
 

Functions

void finalize ()
 
InitResult initialize ()
 
bool operator!= (const version &left, const version &right)
 
bool operator< (const version &left, const version &right)
 
bool operator<= (const version &left, const version &right)
 
bool operator== (const version &left, const version &right)
 
bool operator> (const version &left, const version &right)
 
bool operator>= (const version &left, const version &right)
 
PythonPluginManagerpluginManager ()
 

Variables

static InitResult initStatus = INIT_UNINITIALIZED
 
static QScopedPointer< PythonPluginManagerpluginManagerInstance
 

Enumeration Type Documentation

◆ InitResult

Enumerator
INIT_UNINITIALIZED 
INIT_OK 
INIT_CANNOT_LOAD_PYTHON_LIBRARY 
INIT_CANNOT_SET_PYTHON_PATHS 
INIT_CANNOT_LOAD_PYKRITA_MODULE 

Definition at line 27 of file utilities.h.

Function Documentation

◆ finalize()

void PyKrita::finalize ( )

Cleanup after Python. Note: doing this as part of static/global destruction will not work. The call to Py_Finalize() would happen after the Python runtime has already been finalized, leading to a segfault.

Definition at line 99 of file utilities.cpp.

99 {
100 dbgScript << "Going to destroy the Python engine";
101 if (pluginManagerInstance) {
102 pluginManagerInstance->unloadAllModules();
103
106
107 pluginManagerInstance.reset();
109 }
110 }
static void libraryUnload()
static void maybeFinalize()
#define dbgScript
Definition kis_debug.h:56
static QScopedPointer< PythonPluginManager > pluginManagerInstance
Definition utilities.cpp:42
static InitResult initStatus
Definition utilities.cpp:41

References dbgScript, INIT_UNINITIALIZED, initStatus, PyKrita::Python::libraryUnload(), PyKrita::Python::maybeFinalize(), pluginManagerInstance, and PythonPluginManager::unloadAllModules().

◆ initialize()

InitResult PyKrita::initialize ( )

Initialize the Python environment and plugin manager. This should be called first before using the manager or the Python class.

Definition at line 44 of file utilities.cpp.

45 {
46 // Already initialized?
47 if (initStatus == INIT_OK) return INIT_OK;
48
49 dbgScript << "Initializing Python plugin for Python" << PY_MAJOR_VERSION << "," << PY_MINOR_VERSION;
50
51 if (!Python::libraryLoad()) {
53 }
54
55 // Update PYTHONPATH
56 // 0) custom plugin directories (prefer local dir over systems')
57 // 1) shipped krita module's dir
58 QStringList pluginDirectories = KoResourcePaths::findDirs("pythonscripts");
59 dbgScript << "Plugin Directories: " << pluginDirectories;
60 if (!Python::setPath(pluginDirectories)) {
61 initStatus = INIT_CANNOT_SET_PYTHON_PATHS;
62 return initStatus;
63 }
64
65 if (0 != PyImport_AppendInittab(Python::PYKRITA_ENGINE, PYKRITA_INIT)) {
67 return initStatus;
68 }
69
70 Python::ensureInitialized();
71 Python py = Python();
72
73 // Initialize 'plugins' dict of module 'pykrita'
74 PyObject* plugins = PyDict_New();
75 py.itemStringSet("plugins", plugins);
76
78
79 // Initialize our built-in module.
80 auto pykritaModule = PYKRITA_INIT();
81
82 if (!pykritaModule) {
84 return initStatus;
85 //return i18nc("@info:tooltip ", "No <icode>pykrita</icode> built-in module");
86 }
87
89 return initStatus;
90 }
#define PYKRITA_INIT
static QStringList findDirs(const QString &type)

References dbgScript, PyKrita::Python::ensureInitialized(), KoResourcePaths::findDirs(), INIT_CANNOT_LOAD_PYKRITA_MODULE, INIT_CANNOT_LOAD_PYTHON_LIBRARY, INIT_CANNOT_SET_PYTHON_PATHS, INIT_OK, initStatus, PyKrita::Python::itemStringSet(), PyKrita::Python::libraryLoad(), pluginManagerInstance, PyKrita::Python::PYKRITA_ENGINE, PYKRITA_INIT, and PyKrita::Python::setPath().

◆ operator!=()

bool PyKrita::operator!= ( const version & left,
const version & right )
inline

Definition at line 149 of file version_checker.h.

150{
151 return !(left == right);
152}

◆ operator<()

bool PyKrita::operator< ( const version & left,
const version & right )
inline

Definition at line 154 of file version_checker.h.

155{
156 return left._major() < right._major()
157 || (left._major() == right._major() && left._minor() < right._minor())
158 || (left._major() == right._major() && left._minor() == right._minor() && left.patch() < right.patch())
159 ;
160}

References PyKrita::version::_major(), PyKrita::version::_minor(), and PyKrita::version::patch().

◆ operator<=()

bool PyKrita::operator<= ( const version & left,
const version & right )
inline

Definition at line 170 of file version_checker.h.

171{
172 return left == right || left < right;
173}

◆ operator==()

bool PyKrita::operator== ( const version & left,
const version & right )
inline

Definition at line 141 of file version_checker.h.

142{
143 return left._major() == right._major()
144 && left._minor() == right._minor()
145 && left.patch() == right.patch()
146 ;
147}

References PyKrita::version::_major(), PyKrita::version::_minor(), and PyKrita::version::patch().

◆ operator>()

bool PyKrita::operator> ( const version & left,
const version & right )
inline

Definition at line 162 of file version_checker.h.

163{
164 return left._major() > right._major()
165 || (left._major() == right._major() && left._minor() > right._minor())
166 || (left._major() == right._major() && left._minor() == right._minor() && left.patch() > right.patch())
167 ;
168}

References PyKrita::version::_major(), PyKrita::version::_minor(), and PyKrita::version::patch().

◆ operator>=()

bool PyKrita::operator>= ( const version & left,
const version & right )
inline

Definition at line 175 of file version_checker.h.

176{
177 return left == right || left > right;
178}

◆ pluginManager()

PythonPluginManager * PyKrita::pluginManager ( )

Gets the instance of the plugin manager. Note: PyKrita::initialize() must be called before using this function.

Definition at line 92 of file utilities.cpp.

93 {
95 KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(pluginManager, nullptr);
96 return pluginManager;
97 }
#define KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(cond, val)
Definition kis_assert.h:129
PythonPluginManager * pluginManager()
Definition utilities.cpp:92

References KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE, pluginManager(), and pluginManagerInstance.

Variable Documentation

◆ initStatus

InitResult PyKrita::initStatus = INIT_UNINITIALIZED
static

Definition at line 41 of file utilities.cpp.

◆ pluginManagerInstance

QScopedPointer<PythonPluginManager> PyKrita::pluginManagerInstance
static

Definition at line 42 of file utilities.cpp.