|
Krita Source Code Documentation
|
#include <utilities.h>
Public Member Functions | |
| PyObject * | functionCall (const char *functionName, const char *moduleName, PyObject *arguments) |
| bool | functionCall (const char *functionName, const char *moduleName=PYKRITA_ENGINE) |
| PyObject * | itemString (const char *item, const char *moduleName=PYKRITA_ENGINE) |
| PyObject * | itemString (const char *item, PyObject *dict) |
| bool | itemStringDel (const char *item, const char *moduleName=PYKRITA_ENGINE) |
| bool | itemStringSet (const char *item, PyObject *value, const char *moduleName=PYKRITA_ENGINE) |
| QString | lastTraceback (void) const |
| PyObject * | moduleActions (const char *moduleName) |
| PyObject * | moduleConfigPages (const char *moduleName) |
| PyObject * | moduleDict (const char *moduleName=PYKRITA_ENGINE) |
| QString | moduleHelp (const char *moduleName) |
| PyObject * | moduleImport (const char *moduleName) |
| bool | prependPythonPaths (const QString &path) |
| bool | prependPythonPaths (const QStringList &paths) |
| bool | prependStringToList (PyObject *list, const QString &value) |
| Prepend a QString to a list as a Python unicode object. | |
| Python () | |
| void | traceback (const QString &description) |
| ~Python () | |
Static Public Member Functions | |
| static void | ensureInitialized () |
| static bool | isUnicode (PyObject *string) |
| Test if a Python object is compatible with a QString. | |
| static bool | libraryLoad () |
| static void | libraryUnload () |
| static void | maybeFinalize () |
| static bool | setPath (const QStringList &scriptPaths) |
| static PyObject * | unicode (const QString &string) |
| Convert a QString to a Python unicode object. | |
| static QString | unicode (PyObject *string) |
| Convert a Python unicode object to a QString. | |
Static Public Attributes | |
| static const char * | PYKRITA_ENGINE = "pykrita" |
Private Member Functions | |
| PyObject * | kritaHandler (const char *moduleName, const char *handler) |
| bool | prependPythonPaths (const QString &, PyObject *) |
Private Attributes | |
| PyGILState_STATE | m_state |
| QString | m_traceback |
Instantiate this class on the stack to automatically get and release the GIL.
Also, making all the utility functions members of this class means that in many cases the compiler tells us where the class in needed. In the remaining cases (i.e. bare calls to the Python C API), inspection is used to needed to add the requisite Python() object. To prevent this object being optimised away in these cases due to lack of use, all instances have the form of an assignment, e.g.:
Python py = Python()
This adds a little overhead, but this is a small price for consistency.
Definition at line 72 of file utilities.h.
| PyKrita::Python::Python | ( | ) |
Definition at line 123 of file utilities.cpp.
References m_state.
| PyKrita::Python::~Python | ( | ) |
Definition at line 130 of file utilities.cpp.
References m_state.
|
static |
Make sure the Python interpreter is initialized. Ideally should be only called once.
Definition at line 429 of file utilities.cpp.
References dbgScript, errScript, and warnScript.
| PyObject * PyKrita::Python::functionCall | ( | const char * | functionName, |
| const char * | moduleName, | ||
| PyObject * | arguments ) |
Definition at line 155 of file utilities.cpp.
References errScript, itemString(), and traceback().
| bool PyKrita::Python::functionCall | ( | const char * | functionName, |
| const char * | moduleName = PYKRITA_ENGINE ) |
Call the named module's named entry point.
Definition at line 147 of file utilities.cpp.
References functionCall().
|
static |
Test if a Python object is compatible with a QString.
Definition at line 606 of file utilities.cpp.
| PyObject * PyKrita::Python::itemString | ( | const char * | item, |
| const char * | moduleName = PYKRITA_ENGINE ) |
Get the item from the named module's dictionary.
Definition at line 191 of file utilities.cpp.
References errScript, itemString(), moduleDict(), and value().
| PyObject * PyKrita::Python::itemString | ( | const char * | item, |
| PyObject * | dict ) |
Get the item from the given dictionary.
Definition at line 200 of file utilities.cpp.
References traceback(), and value().
| bool PyKrita::Python::itemStringDel | ( | const char * | item, |
| const char * | moduleName = PYKRITA_ENGINE ) |
Delete the item from the named module's dictionary.
Definition at line 182 of file utilities.cpp.
References moduleDict(), and traceback().
| bool PyKrita::Python::itemStringSet | ( | const char * | item, |
| PyObject * | value, | ||
| const char * | moduleName = PYKRITA_ENGINE ) |
Set the item in the named module's dictionary.
Definition at line 209 of file utilities.cpp.
References moduleDict(), traceback(), and value().
|
private |
Run a handler function supplied by the krita module on another module.
Definition at line 218 of file utilities.cpp.
References functionCall(), and moduleImport().
| QString PyKrita::Python::lastTraceback | ( | void | ) | const |
Store the last traceback we handled using traceback().
Definition at line 225 of file utilities.cpp.
References m_traceback.
|
static |
Load the Python shared library. This does nothing on Windows.
Definition at line 232 of file utilities.cpp.
References dbgScript.
|
static |
Unload the Python shared library. This does nothing on Windows.
Definition at line 458 of file utilities.cpp.
|
static |
Finalize the Python interpreter. Not guaranteed to work.
Definition at line 446 of file utilities.cpp.
References warnScript.
| PyObject * PyKrita::Python::moduleActions | ( | const char * | moduleName | ) |
Get the Actions defined by a module. The returned object is [ { function, ( text, icon, shortcut, menu ) }... ] for each module function decorated with action.
Definition at line 473 of file utilities.cpp.
References kritaHandler().
| PyObject * PyKrita::Python::moduleConfigPages | ( | const char * | moduleName | ) |
Get the ConfigPages defined by a module. The returned object is [ { function, callable, ( name, fullName, icon ) }... ] for each module function decorated with configPage.
Definition at line 478 of file utilities.cpp.
References kritaHandler().
| PyObject * PyKrita::Python::moduleDict | ( | const char * | moduleName = PYKRITA_ENGINE | ) |
Get the named module's dictionary.
Definition at line 494 of file utilities.cpp.
References traceback().
| QString PyKrita::Python::moduleHelp | ( | const char * | moduleName | ) |
Get the help text defined by a module.
Definition at line 483 of file utilities.cpp.
References kritaHandler(), and unicode().
| PyObject * PyKrita::Python::moduleImport | ( | const char * | moduleName | ) |
Import the named module.
Definition at line 505 of file utilities.cpp.
References traceback().
|
private |
Definition at line 638 of file utilities.cpp.
References prependStringToList().
| bool PyKrita::Python::prependPythonPaths | ( | const QString & | path | ) |
Add a given path to to the front of PYTHONPATH
| path | A string (path) to be added |
true on success, false otherwise. Definition at line 611 of file utilities.cpp.
References itemString(), and prependPythonPaths().
| bool PyKrita::Python::prependPythonPaths | ( | const QStringList & | paths | ) |
Add listed paths to to the front of PYTHONPATH
| paths | A string list (paths) to be added |
true on success, false otherwise. Definition at line 617 of file utilities.cpp.
References itemString(), and prependPythonPaths().
| bool PyKrita::Python::prependStringToList | ( | PyObject * | list, |
| const QString & | value ) |
Prepend a QString to a list as a Python unicode object.
Definition at line 137 of file utilities.cpp.
References traceback(), u, unicode(), and value().
|
static |
Set the Python paths by calling Py_SetPath. This should be called before initialization to ensure the proper libraries get loaded.
Definition at line 291 of file utilities.cpp.
References dbgScript, errScript, KoResourcePaths::getApplicationRoot(), KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE, p, and p2.
| void PyKrita::Python::traceback | ( | const QString & | description | ) |
Print and save (see lastTraceback()) the current traceback in a form approximating what Python would print:
* Traceback (most recent call last): * File "/home/shahhaqu/.kde/share/apps/krita/pykrita/pluginmgr.py", line 13, in <module> * import kdeui * ImportError: No module named kdeui * Could not import pluginmgr. *
Definition at line 516 of file utilities.cpp.
References errScript, functionCall(), m_traceback, and unicode().
|
static |
Convert a QString to a Python unicode object.
Definition at line 577 of file utilities.cpp.
References length().
|
static |
Convert a Python unicode object to a QString.
Definition at line 584 of file utilities.cpp.
|
private |
Definition at line 224 of file utilities.h.
|
mutableprivate |
Definition at line 225 of file utilities.h.
|
static |
Definition at line 219 of file utilities.h.