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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
/**
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Contributor(s): Campbell Barton
*
* ***** END GPL LICENSE BLOCK *****
*/
#include "bpy_operator_wrap.h"
#include "WM_api.h"
#include "WM_types.h"
#include "RNA_define.h"
#include "bpy_rna.h"
static void operator_properties_init(wmOperatorType *ot)
{
PyObject *py_class = ot->ext.data;
PyObject *item= ((PyTypeObject*)py_class)->tp_dict; /* getattr(..., "__dict__") returns a proxy */
RNA_struct_blender_type_set(ot->ext.srna, ot);
if(item) {
/* only call this so pyrna_deferred_register_props gives a useful error
* WM_operatortype_append_ptr will call RNA_def_struct_identifier
* later */
RNA_def_struct_identifier(ot->srna, ot->idname);
if(pyrna_deferred_register_props(ot->srna, item) != 0) {
PyErr_Print(); /* failed to register operator props */
PyErr_Clear();
}
}
else {
PyErr_Clear();
}
}
void operator_wrapper(wmOperatorType *ot, void *userdata)
{
/* take care not to overwrite anything set in
* WM_operatortype_append_ptr before opfunc() is called */
StructRNA *srna = ot->srna;
*ot= *((wmOperatorType *)userdata);
ot->srna= srna; /* restore */
operator_properties_init(ot);
{ /* XXX - not nice, set the first enum as searchable, should have a way for python to set */
PointerRNA ptr;
PropertyRNA *prop;
RNA_pointer_create(NULL, ot->srna, NULL, &ptr);
prop = RNA_struct_find_property(&ptr, "type");
if(prop)
ot->prop= prop;
}
}
void macro_wrapper(wmOperatorType *ot, void *userdata)
{
wmOperatorType *data = (wmOperatorType *)userdata;
/* only copy a couple of things, the rest is set by the macro registration */
ot->name = data->name;
ot->idname = data->idname;
ot->description = data->description;
ot->flag |= data->flag; /* append flags to the one set by registration */
ot->pyop_poll = data->pyop_poll;
ot->ui = data->ui;
ot->ext = data->ext;
operator_properties_init(ot);
}
PyObject *PYOP_wrap_macro_define(PyObject *self, PyObject *args)
{
wmOperatorType *ot;
wmOperatorTypeMacro *otmacro;
PyObject *macro;
PointerRNA ptr_otmacro;
StructRNA *srna;
char *opname;
const char *macroname;
if (!PyArg_ParseTuple(args, "Os:_bpy.ops.macro_define", ¯o, &opname))
return NULL;
if (WM_operatortype_exists(opname) == NULL) {
PyErr_Format(PyExc_ValueError, "Macro Define: '%s' is not a valid operator id", opname);
return NULL;
}
/* identifiers */
srna= srna_from_self(macro, "Macro Define:");
macroname = RNA_struct_identifier(srna);
ot = WM_operatortype_exists(macroname);
if (!ot) {
PyErr_Format(PyExc_ValueError, "Macro Define: '%s' is not a valid macro or hasn't been registered yet", macroname);
return NULL;
}
otmacro = WM_operatortype_macro_define(ot, opname);
RNA_pointer_create(NULL, &RNA_OperatorTypeMacro, otmacro, &ptr_otmacro);
return pyrna_struct_CreatePyObject(&ptr_otmacro);
}
|