-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpyqbind_detail.h
63 lines (45 loc) · 1.45 KB
/
pyqbind_detail.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#ifndef PYQBIND_DETAIL_H
#define PYQBIND_DETAIL_H
#include <boost/python/object_fwd.hpp>
#include <QMetaProperty>
#include <QMetaMethod>
#include <QObject>
#define log_error_stream( X ) do{ std::cerr << "ERROR: " << X << std::endl; } while(0);
#define log_warn_stream( X ) do{ std::cerr << "WARNING: " << X << std::endl; } while(0);
#define log_debug_stream( X ) do{ /*std::cerr << "DBGMSG: " << X << std::endl;*/ } while(0);
namespace pyqbind_detail {
void register_metatypes();
boost::python::object make_metaproperty_reader( QMetaProperty m );
boost::python::object make_metaproperty_writer( QMetaProperty m );
boost::python::object make_invoker( QMetaMethod m );
/**
* This class provides a fancy invoke()-able way of calling QMetaProperty.read()
* and QMetaProperty.write(), and is used for thread synchronization when pyqbind
* properties are accessed outside the main thread.
*/
class MetapropertyThreadQueue : public QObject{
Q_OBJECT;
public:
QMetaMethod read_method;
QMetaMethod write_method;
MetapropertyThreadQueue();
public Q_SLOTS:
QVariant read( QObject* q, QMetaProperty p );
bool write( QObject* q, QMetaProperty p, const QVariant& value );
};
/**
* RAII class to grab and release the Python Global Interpreter Lock
*/
class ScopedGIL{
private:
PyGILState_STATE s_;
public:
ScopedGIL(){
s_ = PyGILState_Ensure();
}
~ScopedGIL(){
PyGILState_Release( s_ );
}
};
} // namespace pyqbind_detail
#endif /* PYQBIND_DETAIL_H */