Adonthell
0.4
|
Python object class. More...
#include <py_object.h>
Public Member Functions | |
py_object () | |
Default constructor. More... | |
~py_object () | |
Destructor. More... | |
void | clear () |
Resets the script to it's post-constructor state. More... | |
PyObject creation | |
bool | create_instance (string file, string classname, PyObject *args=NULL) |
Creates an instance of a Python class. More... | |
bool | reload_instance (string file, string classname, PyObject *args=NULL) |
Similar to create_instance, except that it will reload the module from disk, in case it has been changed in the meantime. More... | |
PyObject method calling | |
PyObject * | call_method_ret (const string &name, PyObject *args=NULL) const |
Call a method of this object. More... | |
void | call_method (const string &name, PyObject *args=NULL) const |
Call a method of this object. More... | |
void | run (PyObject *args=NULL) |
Calls the run () method of this object. More... | |
PyObject member access | |
bool | has_attribute (const std::string &name) |
Tests whether the object contains a certain attribute (i.e. More... | |
PyObject * | get_attribute (const string &name) const |
Returns a new reference to an attribute of this object. More... | |
s_int32 | get_attribute_int (const string &name) |
Returns the given attribute as integer value. More... | |
string | get_attribute_string (const string &name) |
Returns the given attribute as string value. More... | |
void | set_attribute (const string &name, PyObject *value) |
Assign a new attribute to the module, overriding an existing attribute of the same name. More... | |
void | set_attribute_int (const string &name, s_int32 value) |
Assign a new integer attribute to the module, overriding an existing attribute of the same name. More... | |
void | set_attribute_string (const string &name, const string &value) |
Assign a new string attribute to the module, overriding an existing attribute of the same name. More... | |
Member access | |
PyObject * | get_instance (const bool &incref=true) const |
Direct access to the instance object. More... | |
std::string | class_name () const |
Returns the class name of this object. More... | |
std::string | file_name () const |
Returns the file name of this object. More... | |
Protected Attributes | |
PyObject * | Instance |
The python class instance wrapped by py_object. More... | |
Python object class.
Use this class to create instances of Python classes contained in Python modules, then control their execution. You can pass an argument tuple to the class constructor and to any method you want to run. It is further possible to access and change attributes of the Python instance.
Definition at line 41 of file py_object.h.
py_object::py_object | ( | ) |
Default constructor.
Definition at line 29 of file py_object.cc.
py_object::~py_object | ( | ) |
Destructor.
Definition at line 36 of file py_object.cc.
void py_object::clear | ( | ) |
Resets the script to it's post-constructor state.
Definition at line 42 of file py_object.cc.
bool py_object::create_instance | ( | string | file, |
string | classname, | ||
PyObject * | args = NULL |
||
) |
Creates an instance of a Python class.
file | file name of the module to use. |
classname | name of the class to import. |
args | Python tuple containing the arguments to pass to the Python class constructor. |
Definition at line 53 of file py_object.cc.
bool py_object::reload_instance | ( | string | file, |
string | classname, | ||
PyObject * | args = NULL |
||
) |
Similar to create_instance, except that it will reload the module from disk, in case it has been changed in the meantime.
Mainly interesting for script development or tools like dlgedit.
file | file name of the module to use. |
classname | name of the class to import. |
args | Python tuple containing the arguments to pass to the Python class constructor. |
Definition at line 64 of file py_object.cc.
PyObject * py_object::call_method_ret | ( | const string & | name, |
PyObject * | args = NULL |
||
) | const |
Call a method of this object.
name | name of the method to call. |
args | Python tuple containing the arguments to pass to the method. |
Definition at line 108 of file py_object.cc.
|
inline |
Call a method of this object.
name | name of the method to call. |
args | Python tuple containing the arguments to pass to the method. |
Definition at line 109 of file py_object.h.
|
inline |
Calls the run () method of this object.
Equivalent to call_method ("run", args);
args | Python tuple containing the arguments to pass to the method. |
Definition at line 121 of file py_object.h.
bool py_object::has_attribute | ( | const std::string & | name | ) |
Tests whether the object contains a certain attribute (i.e.
method or variable).
name | Name of the attribute to test for |
Definition at line 130 of file py_object.cc.
PyObject * py_object::get_attribute | ( | const string & | name | ) | const |
Returns a new reference to an attribute of this object.
name | Name of the attribute to access |
Definition at line 139 of file py_object.cc.
s_int32 py_object::get_attribute_int | ( | const string & | name | ) |
Returns the given attribute as integer value.
name | Name of the attribute to access |
Definition at line 148 of file py_object.cc.
string py_object::get_attribute_string | ( | const string & | name | ) |
Returns the given attribute as string value.
name | Name of the attribute to access |
Definition at line 165 of file py_object.cc.
void py_object::set_attribute | ( | const string & | name, |
PyObject * | value | ||
) |
Assign a new attribute to the module, overriding an existing attribute of the same name.
name | The attribute's name |
value | The attribute's value |
Definition at line 182 of file py_object.cc.
void py_object::set_attribute_int | ( | const string & | name, |
s_int32 | value | ||
) |
Assign a new integer attribute to the module, overriding an existing attribute of the same name.
name | The attribute's name |
value | The attribute's value |
Definition at line 191 of file py_object.cc.
void py_object::set_attribute_string | ( | const string & | name, |
const string & | value | ||
) |
Assign a new string attribute to the module, overriding an existing attribute of the same name.
name | The attribute's name |
value | The attribute's value |
Definition at line 206 of file py_object.cc.
|
inline |
Direct access to the instance object.
The default behaviour is to increase the instance's reference count, so that this method can be safely called from Python scripts.
incref | whether to increase the reference count. |
Definition at line 204 of file py_object.h.
|
inline |
Returns the class name of this object.
This is the name of the wrapped Python class.
Definition at line 219 of file py_object.h.
|
inline |
Returns the file name of this object.
This is the name of the Python module containing the wrapped class.
Definition at line 230 of file py_object.h.
|
protected |
The python class instance wrapped by py_object.
Definition at line 240 of file py_object.h.