22 #include "RNA_prototypes.h"
70 self->ctx_init.win_is_set = (
self->ctx_init.win !=
self->ctx_temp.win);
72 self->ctx_init.area_is_set = (
self->ctx_init.area !=
self->ctx_temp.area);
74 self->ctx_init.region_is_set = (
self->ctx_init.region !=
self->ctx_temp.region);
76 wmWindow *win =
self->ctx_temp.win_is_set ?
self->ctx_temp.win :
self->ctx_init.win;
78 ScrArea *
area =
self->ctx_temp.area_is_set ?
self->ctx_temp.area :
self->ctx_init.area;
79 ARegion *region =
self->ctx_temp.region_is_set ?
self->ctx_temp.region :
self->ctx_init.region;
82 if (
self->ctx_temp.region_is_set && (region !=
NULL)) {
84 PyErr_SetString(PyExc_TypeError,
"Region set with NULL area");
89 PyErr_SetString(PyExc_TypeError,
"Region not found in area");
96 PyErr_SetString(PyExc_TypeError,
"Area set with NULL screen");
100 PyErr_SetString(PyExc_TypeError,
"Area not found in screen");
105 if (
self->ctx_temp.win_is_set) {
108 if (
self->ctx_temp.area_is_set) {
111 if (
self->ctx_temp.region_is_set) {
125 bool do_restore =
true;
126 if (
self->ctx_init.win) {
135 if (
self->ctx_init.win_is_set) {
138 if (
self->ctx_init.area_is_set) {
141 if (
self->ctx_init.region_is_set) {
148 if (context_dict_test && (context_dict_test !=
self->py_state_context_dict)) {
149 Py_DECREF(context_dict_test);
152 Py_CLEAR(
self->py_state_context_dict);
164 PyVarObject_HEAD_INIT(
NULL, 0).tp_name =
"ContextTempOverride",
167 .tp_flags = Py_TPFLAGS_DEFAULT,
180 PyObject *sentinel = Py_Ellipsis;
181 PyObject *kwds_parse = PyDict_New();
182 for (
int i = 0; kwds_static[i]; i++) {
183 PyObject *key = PyUnicode_FromString(kwds_static[i]);
184 PyObject *val = _PyDict_Pop(kwds, key, sentinel);
185 if (val != sentinel) {
186 if (PyDict_SetItem(kwds_parse, key, val) == -1) {
197 ".. method:: temp_override(window, area, region, **keywords)\n"
199 " Context manager to temporarily override members in the context.\n"
201 " :arg window: Window override or None.\n"
202 " :type window: :class:`bpy.types.Window`\n"
203 " :arg area: Area override or None.\n"
204 " :type area: :class:`bpy.types.Area`\n"
205 " :arg region: Region override or None.\n"
206 " :type region: :class:`bpy.types.Region`\n"
207 " :arg keywords: Additional keywords override context members.\n"
208 " :return: The context manager .\n"
209 " :rtype: context manager\n");
213 if (context_ptr ==
NULL) {
224 if (!PyArg_ValidateKeywordArguments(kwds)) {
234 .window = {.type = &RNA_Window},
235 .area = {.type = &RNA_Area},
236 .region = {.type = &RNA_Region},
239 static const char *
const _keywords[] = {
"window",
"area",
"region",
NULL};
240 static _PyArg_Parser _parser = {
250 kwds = kwds ? PyDict_Copy(kwds) : PyDict_New();
253 const int parse_result = _PyArg_ParseTupleAndKeywordsFast(args,
262 Py_DECREF(kwds_parse);
263 if (parse_result == -1) {
274 if (context_dict_current !=
NULL) {
275 PyDict_Merge(kwds, context_dict_current, 0);
296 ret->ctx_temp = ctx_temp;
297 memset(&
ret->ctx_init, 0,
sizeof(
ret->ctx_init));
299 ret->py_state_context_dict = kwds;
301 return (PyObject *)
ret;
309 METH_VARARGS | METH_KEYWORDS,
310 bpy_context_temp_override_doc,
struct ScrArea * CTX_wm_area(const bContext *C)
void CTX_wm_region_set(bContext *C, struct ARegion *region)
void CTX_py_state_push(bContext *C, struct bContext_PyState *pystate, void *value)
void * CTX_py_dict_get(const bContext *C)
struct wmWindowManager * CTX_wm_manager(const bContext *C)
void CTX_py_state_pop(bContext *C, struct bContext_PyState *pystate)
void CTX_wm_window_set(bContext *C, struct wmWindow *win)
struct ARegion * CTX_wm_region(const bContext *C)
void CTX_wm_area_set(bContext *C, struct ScrArea *area)
struct wmWindow * CTX_wm_window(const bContext *C)
#define BLI_assert_unreachable()
int BLI_findindex(const struct ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
int pyrna_struct_as_ptr_or_null_parse(PyObject *o, void *p)
const PointerRNA * pyrna_struct_as_ptr(PyObject *py_obj, const StructRNA *srna)
static PyTypeObject BPyContextTempOverride_Type
static PyObject * bpy_rna_context_temp_override_enter(BPyContextTempOverride *self)
static PyObject * bpy_context_temp_override_extract_known_args(const char *const *kwds_static, PyObject *kwds)
struct BPyContextTempOverride BPyContextTempOverride
struct ContextStore ContextStore
static PyMethodDef bpy_rna_context_temp_override__tp_methods[]
static PyObject * bpy_context_temp_override(PyObject *self, PyObject *args, PyObject *kwds)
static PyObject * bpy_rna_context_temp_override_exit(BPyContextTempOverride *self, PyObject *UNUSED(args))
void bpy_rna_context_types_init(void)
PyMethodDef BPY_rna_context_temp_override_method_def
PyDoc_STRVAR(bpy_context_temp_override_doc, ".. method:: temp_override(window, area, region, **keywords)\n" "\n" " Context manager to temporarily override members in the context.\n" "\n" " :arg window: Window override or None.\n" " :type window: :class:`bpy.types.Window`\n" " :arg area: Area override or None.\n" " :type area: :class:`bpy.types.Area`\n" " :arg region: Region override or None.\n" " :type region: :class:`bpy.types.Region`\n" " :arg keywords: Additional keywords override context members.\n" " :return: The context manager .\n" " :rtype: context manager\n")
static void bpy_rna_context_temp_override__tp_dealloc(BPyContextTempOverride *self)
static void area(int d1, int d2, int e1, int e2, float weights[2])
PyObject_HEAD bContext * context
struct bContext_PyState py_state
PyObject * py_state_context_dict
bScreen * WM_window_get_active_screen(const wmWindow *win)