Blender V5.3
bpy_rna_context.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10
11#include <Python.h>
12
13#include "BLI_listbase.hh"
14#include "BLI_utildefines.hh"
15
16#include "BKE_context.hh"
17#include "BKE_main.hh"
18#include "BKE_screen.hh"
19#include "BKE_workspace.hh"
20
21#include "WM_api.hh"
22#include "WM_types.hh"
23
24#include "bpy_rna_context.hh"
25
27#include "../generic/python_compat.hh" /* IWYU pragma: keep. */
28
29#include "RNA_access.hh"
30#include "RNA_prototypes.hh"
31
32#include "bpy_rna.hh"
33
34namespace blender {
35
36/* -------------------------------------------------------------------- */
39
41{
42 if (screen == nullptr) {
43 return;
44 }
45 if (screen == WM_window_get_active_screen(win)) {
46 return;
47 }
48
49 WorkSpace *workspace;
51 /* Changing workspace instead of just screen as they are tied. */
52 WM_window_set_active_workspace(C, win, workspace);
53 WM_window_set_active_screen(win, workspace, screen);
54}
55
59static bool wm_check_screen_switch_supported(const bScreen *screen)
60{
61 if (screen->temp != 0) {
62 return false;
63 }
65 return false;
66 }
67 return true;
68}
69
70static bool wm_check_window_exists(const Main *bmain, const wmWindow *win)
71{
72 for (wmWindowManager &wm : bmain->wm) {
73 if (BLI_findindex(&wm.windows, win) != -1) {
74 return true;
75 }
76 }
77 return false;
78}
79
80static bool wm_check_screen_exists(const Main *bmain, const bScreen *screen)
81{
82 if (BLI_findindex(&bmain->screens, screen) != -1) {
83 return true;
84 }
85 return false;
86}
87
88static bool wm_check_area_exists(const wmWindow *win, const bScreen *screen, const ScrArea *area)
89{
90 if (win && (BLI_findindex(&win->global_areas.areabase, area) != -1)) {
91 return true;
92 }
93 if (screen && (BLI_findindex(&screen->areabase, area) != -1)) {
94 return true;
95 }
96 return false;
97}
98
99static bool wm_check_region_exists(const bScreen *screen,
100 const ScrArea *area,
101 const ARegion *region)
102{
103 if (screen && (BLI_findindex(&screen->regionbase, region) != -1)) {
104 return true;
105 }
106 if (area && (BLI_findindex(&area->regionbase, region) != -1)) {
107 return true;
108 }
109 return false;
110}
111
113
114/* -------------------------------------------------------------------- */
117
128
158
160{
161 PyObject_GC_UnTrack(self);
162 Py_CLEAR(self->py_state_context_dict);
163 PyObject_GC_Del(self);
164}
165
167 visitproc visit,
168 void *arg)
169{
170 Py_VISIT(self->py_state_context_dict);
171 return 0;
172}
173
175{
176 Py_CLEAR(self->py_state_context_dict);
177 return 0;
178}
179
181 const Main *bmain,
182 const wmWindow *win,
183 const bScreen *screen,
184 const ScrArea *area,
185 const ARegion *region)
186{
187
188 /* NOTE(@ideasman42): Regarding sanity checks.
189 * There are 3 different situations to be accounted for here regarding overriding windowing data.
190 *
191 * - 1) Nothing is overridden.
192 * Simple, no sanity checks needed.
193 *
194 * - 2) Some members are overridden.
195 * Check the state is consistent (that the region is part the area or screen for example).
196 *
197 * - 3) Some members are overridden *but* the context members are unchanged.
198 * This is a less obvious case which often happens when a Python script copies the context
199 * typically via `context.copy()`, manipulates it and passes it in as keyword arguments.
200 *
201 * A naive approach could be to behave as if these arguments weren't passed in
202 * which would work in many situations however there is a difference
203 * since these members are used to restore the context afterwards.
204 * It's possible a script might use this context-manager to *pin* the context,
205 * running actions that change the context, relying on the context to be restored.
206 *
207 * When error-checking unchanged context members some error checks must be skipped
208 * such as the check to disallow temporary screens since that could break using
209 * `temp_override(..)` running with the current context from a render-window for example.
210 *
211 * In fact all sanity checks could be disabled when the members involved remain unchanged
212 * however it's possible Python scripts corrupt Blender's internal windowing state so keeping
213 * the checks is harmless and alerts developers early on that something is wrong.
214 */
215
216 if (self->ctx_temp.region_is_set && (region != nullptr)) {
217 if (screen == nullptr && area == nullptr) {
218 PyErr_SetString(PyExc_TypeError, "Region set with screen & area set to None");
219 return false;
220 }
221 if (!wm_check_region_exists(screen, area, region)) {
222 PyErr_SetString(PyExc_TypeError, "Region not found in area or screen");
223 return false;
224 }
225 }
226
227 if (self->ctx_temp.area_is_set && (area != nullptr)) {
228 if (win == nullptr && screen == nullptr) {
229 PyErr_SetString(PyExc_TypeError, "Area set with window & screen set to None");
230 return false;
231 }
232 if (!wm_check_area_exists(win, screen, area)) {
233 PyErr_SetString(PyExc_TypeError, "Area not found in screen");
234 return false;
235 }
236 }
237
238 if (self->ctx_temp.screen_is_set && (screen != nullptr)) {
239 if (win == nullptr) {
240 PyErr_SetString(PyExc_TypeError, "Screen set with null window");
241 return false;
242 }
243 if (!wm_check_screen_exists(bmain, screen)) {
244 PyErr_SetString(PyExc_TypeError, "Screen not found");
245 return false;
246 }
247
248 /* Skip some checks when the screen is unchanged. */
249 if (self->ctx_init.screen_is_set) {
250 /* Switching away from a temporary screen isn't supported. */
251 if ((self->ctx_init.screen != nullptr) &&
253 {
254 PyErr_SetString(PyExc_TypeError,
255 "Overriding context with an active temporary screen isn't supported");
256 return false;
257 }
259 PyErr_SetString(PyExc_TypeError,
260 "Overriding context with temporary screen isn't supported");
261 return false;
262 }
263 if (BKE_workspace_layout_find_global(bmain, screen, nullptr) == nullptr) {
264 PyErr_SetString(PyExc_TypeError, "Screen has no workspace");
265 return false;
266 }
267
268 for (wmWindowManager &wm : bmain->wm) {
269 for (wmWindow &win_iter : wm.windows) {
270 if (&win_iter == win) {
271 continue;
272 }
273 if (screen == WM_window_get_active_screen(&win_iter)) {
274 PyErr_SetString(PyExc_TypeError, "Screen is used by another window");
275 return false;
276 }
277 }
278 }
279 }
280 }
281
282 if (self->ctx_temp.win_is_set && (win != nullptr)) {
283 if (!wm_check_window_exists(bmain, win)) {
284 PyErr_SetString(PyExc_TypeError, "Window not found");
285 return false;
286 }
287 }
288
289 return true;
290}
291
293{
294 bContext *C = self->context;
295 Main *bmain = CTX_data_main(C);
296
297 /* It's crucial to call #CTX_py_state_pop if this function fails with an error. */
299
300 self->ctx_init.win = CTX_wm_window(C);
303 self->ctx_init.area = CTX_wm_area(C);
305
306 wmWindow *win = self->ctx_temp.win_is_set ? self->ctx_temp.win : self->ctx_init.win;
307 bScreen *screen = self->ctx_temp.screen_is_set ? self->ctx_temp.screen : self->ctx_init.screen;
308 ScrArea *area = self->ctx_temp.area_is_set ? self->ctx_temp.area : self->ctx_init.area;
309 ARegion *region = self->ctx_temp.region_is_set ? self->ctx_temp.region : self->ctx_init.region;
310
311 self->ctx_init.win_is_set = (self->ctx_init.win != win);
312 self->ctx_init.screen_is_set = (self->ctx_init.screen != screen);
313 self->ctx_init.area_is_set = (self->ctx_init.area != area);
314 self->ctx_init.region_is_set = (self->ctx_init.region != region);
315
316 /* When the screen isn't passed but a window is, match the screen to the window,
317 * it's important to do this after setting `self->ctx_init.screen_is_set` because the screen is
318 * *not* set, only the window, restoring the window will also restore its screen, see #116297. */
319 if ((self->ctx_temp.win_is_set == true) && (self->ctx_temp.screen_is_set == false)) {
320 screen = win ? WM_window_get_active_screen(win) : nullptr;
321 }
322
323 if (!bpy_rna_context_temp_override_enter_ok_or_error(self, bmain, win, screen, area, region)) {
324 CTX_py_state_pop(C, &self->py_state);
325 return nullptr;
326 }
327
328 /* Manipulate the context (setup). */
329 if (self->ctx_temp.screen_is_set) {
330 /* A `None` window may be passed in, as the window defines the screen,
331 * there is nothing to do here. */
332 if (win != nullptr) {
333 self->ctx_temp_orig.screen = WM_window_get_active_screen(win);
335 }
336 }
337
338 /* NOTE: always set these members, even when they are equal to the current values because
339 * setting the window (for example) clears the area & region, setting the area clears the region.
340 * While it would be useful in some cases to leave the context as-is when setting members
341 * to their current values.
342 *
343 * Favor predictable behavior, where setting a member *always* clears the nested
344 * values it contains - no matter the state of the current context.
345 * If this difference is important, the caller can always detect this case and avoid
346 * passing in the context override altogether. */
347
348 if (self->ctx_temp.win_is_set) {
350 }
351 if (self->ctx_temp.screen_is_set) {
353 }
354 if (self->ctx_temp.area_is_set) {
356 }
357 if (self->ctx_temp.region_is_set) {
359 }
360
361 return Py_NewRef(self);
362}
363
365 PyObject * /*args*/)
366{
367 bContext *C = self->context;
368
369 Main *bmain = CTX_data_main(C);
370
371 /* Manipulate the context (restore). */
372 if (self->ctx_temp.screen_is_set) {
373 if (self->ctx_temp_orig.screen && wm_check_screen_exists(bmain, self->ctx_temp_orig.screen)) {
374 wmWindow *win = self->ctx_temp.win_is_set ? self->ctx_temp.win : self->ctx_init.win;
375 if (win && wm_check_window_exists(bmain, win)) {
376 /* Disallow switching away from temporary-screens & full-screen areas, while it could be
377 * useful to support this, closing screens uses different and more involved logic
378 * compared with switching between user managed screens, see: #117188. */
381 }
382 }
383 }
384 }
385
386 /* Account for the window to be freed on file-read,
387 * in this case the window should not be restored, see: #92818.
388 * Also account for other windowing members to be removed on exit,
389 * in this case the context is cleared. */
390 bool do_restore = true;
391
392 /* Restore context members as needed.
393 *
394 * The checks here behaves as follows:
395 * - When `self->ctx_init.win_is_set` is true, the window was changed by the override.
396 * in this case restore the initial window.
397 * - When `self->ctx_temp.win_is_set` is true, the window was set to the current value.
398 * Setting the window (even to the current value) must be accounted for
399 * because setting the window clears the area and the region members,
400 * which must now be restored.
401 *
402 * `is_container_set` is used to detect if nested context members need to be restored.
403 * The comments above refer to the window, it also applies to the screen containing an area
404 * and area which contains a region. */
405 bool is_container_set = false;
406
407 /* Handle Window. */
408 if (do_restore) {
409 if (self->ctx_init.win && !wm_check_window_exists(bmain, self->ctx_init.win)) {
410 CTX_wm_window_set(C, nullptr);
411 do_restore = false;
412 }
413
414 if (do_restore) {
415 if (self->ctx_init.win_is_set) {
417 is_container_set = true;
418 }
419 else if (self->ctx_temp.win_is_set) {
420 if (self->ctx_init.win == CTX_wm_window(C)) {
421 is_container_set = true;
422 }
423 else {
424 /* If the context changed, it's incorrect to attempt to restored nested members,
425 * in this case leave the context as-is, see: #119202. */
426 do_restore = false;
427 }
428 }
429 }
430 }
431
432 /* Handle Screen. */
433 if (do_restore) {
434 if (self->ctx_init.screen && !wm_check_screen_exists(bmain, self->ctx_init.screen)) {
435 CTX_wm_screen_set(C, nullptr);
436 do_restore = false;
437 }
438
439 if (do_restore) {
440 if (self->ctx_init.screen_is_set || is_container_set) {
442 is_container_set = true;
443 }
444 else if (self->ctx_temp.screen_is_set) {
445 if (self->ctx_init.screen == CTX_wm_screen(C)) {
446 is_container_set = true;
447 }
448 else {
449 do_restore = false;
450 }
451 }
452 }
453 }
454
455 /* Handle Area. */
456 if (do_restore) {
457 if (self->ctx_init.area &&
459 {
460 CTX_wm_area_set(C, nullptr);
461 do_restore = false;
462 }
463
464 if (do_restore) {
465 if (self->ctx_init.area_is_set || is_container_set) {
467 is_container_set = true;
468 }
469 else if (self->ctx_temp.area_is_set) {
470 if (self->ctx_init.area == CTX_wm_area(C)) {
471 is_container_set = true;
472 }
473 else {
474 do_restore = false;
475 }
476 }
477 }
478 }
479
480 /* Handle Region. */
481 if (do_restore) {
482 if (self->ctx_init.region &&
484 {
485 CTX_wm_region_set(C, nullptr);
486 do_restore = false;
487 }
488
489 if (do_restore) {
490 if (self->ctx_init.region_is_set || is_container_set) {
492 is_container_set = true;
493 }
494 /* Enable is there is ever data nested within the region. */
495 else if (false && self->ctx_temp.region_is_set) {
496 if (self->ctx_init.region == CTX_wm_region(C)) {
497 is_container_set = true;
498 }
499 else {
500 do_restore = false;
501 }
502 }
503 }
504 }
505 UNUSED_VARS(is_container_set, do_restore);
506
507 /* Finished restoring the context. */
508
509 /* A copy may have been made when writing context members, see #BPY_context_dict_clear_members */
510 PyObject *context_dict_test = static_cast<PyObject *>(CTX_py_dict_get(C));
511 if (context_dict_test && (context_dict_test != self->py_state_context_dict)) {
512 Py_DECREF(context_dict_test);
513 }
514
515 /* Restore the original logging flags. */
517
518 CTX_py_state_pop(C, &self->py_state);
519
520 Py_RETURN_NONE;
521}
522
524 /* Wrap. */
525 bpy_rna_context_temp_override_logging_set_doc,
526 ".. method:: logging_set(enable, *, hide_missing=False)\n"
527 "\n"
528 " Set context member logging options for this temporary override.\n"
529 "\n"
530 " :param enable: Enable logging of context member access.\n"
531 " :type enable: bool\n"
532 " :param hide_missing: When true, suppress logging access to members that\n"
533 " are not available in the current context.\n"
534 " :type hide_missing: bool\n");
536 PyObject *args,
537 PyObject *kwds)
538{
539 bool enable = true;
540 bool hide_missing = false;
541
542 static const char *_keywords[] = {
543 "enable",
544 "hide_missing",
545 nullptr,
546 };
547 static _PyArg_Parser _parser = {
548 "O&" /* `enable` */
549 "|$" /* Optional, keyword only arguments. */
550 "O&" /* `hide_missing` */
551 ":logging_set",
552 _keywords,
553 nullptr,
554 };
555 if (!_PyArg_ParseTupleAndKeywordsFast(
556 args, kwds, &_parser, PyC_ParseBool, &enable, PyC_ParseBool, &hide_missing))
557 {
558 return nullptr;
559 }
560
561 CTX_LogFlag flag = CTX_LogFlag(0);
562 if (enable) {
563 flag |= CTX_LogFlag::Access;
564 }
565 if (hide_missing) {
567 }
569
570 Py_RETURN_NONE;
571}
572
573#ifdef __GNUC__
574# ifdef __clang__
575# pragma clang diagnostic push
576# pragma clang diagnostic ignored "-Wcast-function-type"
577# else
578# pragma GCC diagnostic push
579# pragma GCC diagnostic ignored "-Wcast-function-type"
580# endif
581#endif
582
584 {"__enter__", reinterpret_cast<PyCFunction>(bpy_rna_context_temp_override_enter), METH_NOARGS},
585 {"__exit__", reinterpret_cast<PyCFunction>(bpy_rna_context_temp_override_exit), METH_VARARGS},
586 {"logging_set",
587 reinterpret_cast<PyCFunction>(bpy_rna_context_temp_override_logging_set),
588 METH_VARARGS | METH_KEYWORDS,
589 bpy_rna_context_temp_override_logging_set_doc},
590 {nullptr},
591};
592
593#ifdef __GNUC__
594# ifdef __clang__
595# pragma clang diagnostic pop
596# else
597# pragma GCC diagnostic pop
598# endif
599#endif
600
601static PyTypeObject BPyContextTempOverride_Type = {
602 /*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
603 /*tp_name*/ "ContextTempOverride",
604 /*tp_basicsize*/ sizeof(BPyContextTempOverride),
605 /*tp_itemsize*/ 0,
606 /*tp_dealloc*/ reinterpret_cast<destructor>(bpy_rna_context_temp_override_dealloc),
607 /*tp_vectorcall_offset*/ 0,
608 /*tp_getattr*/ nullptr,
609 /*tp_setattr*/ nullptr,
610 /*tp_as_async*/ nullptr,
611 /*tp_repr*/ nullptr,
612 /*tp_as_number*/ nullptr,
613 /*tp_as_sequence*/ nullptr,
614 /*tp_as_mapping*/ nullptr,
615 /*tp_hash*/ nullptr,
616 /*tp_call*/ nullptr,
617 /*tp_str*/ nullptr,
618 /*tp_getattro*/ nullptr,
619 /*tp_setattro*/ nullptr,
620 /*tp_as_buffer*/ nullptr,
621 /*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
622 /*tp_doc*/ nullptr,
623 /*tp_traverse*/ reinterpret_cast<traverseproc>(bpy_rna_context_temp_override_traverse),
624 /*tp_clear*/ reinterpret_cast<inquiry>(bpy_rna_context_temp_override_clear),
625 /*tp_richcompare*/ nullptr,
626 /*tp_weaklistoffset*/ 0,
627 /*tp_iter*/ nullptr,
628 /*tp_iternext*/ nullptr,
630 /*tp_members*/ nullptr,
631 /*tp_getset*/ nullptr,
632 /*tp_base*/ nullptr,
633 /*tp_dict*/ nullptr,
634 /*tp_descr_get*/ nullptr,
635 /*tp_descr_set*/ nullptr,
636 /*tp_dictoffset*/ 0,
637 /*tp_init*/ nullptr,
638 /*tp_alloc*/ nullptr,
639 /*tp_new*/ nullptr,
640 /*tp_free*/ nullptr,
641 /*tp_is_gc*/ nullptr,
642 /*tp_bases*/ nullptr,
643 /*tp_mro*/ nullptr,
644 /*tp_cache*/ nullptr,
645 /*tp_subclasses*/ nullptr,
646 /*tp_weaklist*/ nullptr,
647 /*tp_del*/ nullptr,
648 /*tp_version_tag*/ 0,
649 /*tp_finalize*/ nullptr,
650 /*tp_vectorcall*/ nullptr,
651};
652
654
655/* -------------------------------------------------------------------- */
658
659static PyObject *bpy_context_temp_override_extract_known_args(const char *const *kwds_static,
660 PyObject *kwds)
661{
662 PyObject *kwds_parse = PyDict_New();
663 for (int i = 0; kwds_static[i]; i++) {
664 PyObject *key = PyUnicode_FromString(kwds_static[i]);
665 PyObject *val;
666
667 switch (PyDict_Pop(kwds, key, &val)) {
668 case 1: {
669 if (PyDict_SetItem(kwds_parse, key, val) == -1) {
671 }
672 Py_DECREF(val);
673 break;
674 }
675 case -1: {
676 /* Not expected, but allow for an error. */
677 BLI_assert(false);
678 PyErr_Clear();
679 break;
680 }
681 }
682
683 Py_DECREF(key);
684 }
685 return kwds_parse;
686}
687
689 /* Wrap. */
690 bpy_context_temp_override_doc,
691 ".. method:: temp_override(*, window=None, screen=None, area=None, region=None, **keywords)\n"
692 "\n"
693 " Context manager to temporarily override members in the context.\n"
694 "\n"
695 " :param window: Window override or None.\n"
696 " :type window: :class:`bpy.types.Window` | None\n"
697 " :param screen: Screen override or None.\n"
698 "\n"
699 " .. note:: Switching to or away from full-screen areas & temporary screens "
700 "isn't supported. Passing in these screens will raise an exception, "
701 "actions that leave the context such screens won't restore the prior screen.\n"
702 "\n"
703 " .. note:: Changing the screen has wider implications "
704 "than other arguments as it will also change the works-space "
705 "and potentially the scene (when pinned).\n"
706 "\n"
707 " :type screen: :class:`bpy.types.Screen` | None\n"
708 " :param area: Area override or None.\n"
709 " :type area: :class:`bpy.types.Area` | None\n"
710 " :param region: Region override or None.\n"
711 " :type region: :class:`bpy.types.Region` | None\n"
712 " :param keywords: Additional keywords override context members.\n"
713 " :return: The context manager.\n"
714 " :rtype: :class:`bpy.types.ContextTempOverride`\n");
715static PyObject *bpy_context_temp_override(PyObject *self, PyObject *args, PyObject *kwds)
716{
717 const PointerRNA *context_ptr = pyrna_struct_as_ptr(self, RNA_Context);
718 if (context_ptr == nullptr) {
719 return nullptr;
720 }
721
722 if (kwds == nullptr) {
723 /* While this is effectively NOP, support having no keywords as it's more involved
724 * to return an alternative (dummy) context manager. */
725 }
726 else {
727 /* Needed because the keywords copied into `kwds_parse` could contain anything.
728 * As the types of keys aren't checked. */
729 if (!PyArg_ValidateKeywordArguments(kwds)) {
730 return nullptr;
731 }
732 }
733
734 struct {
735 BPy_StructRNA_Parse window;
736 BPy_StructRNA_Parse screen;
738 BPy_StructRNA_Parse region;
739 } params{};
740 params.window.type = RNA_Window;
741 params.screen.type = RNA_Screen;
742 params.area.type = RNA_Area;
743 params.region.type = RNA_Region;
744
745 static const char *const _keywords[] = {
746 "window",
747 "screen",
748 "area",
749 "region",
750 nullptr,
751 };
752 static _PyArg_Parser _parser = {
753 "|$" /* Optional, keyword only arguments. */
754 "O&" /* `window` */
755 "O&" /* `screen` */
756 "O&" /* `area` */
757 "O&" /* `region` */
758 ":temp_override",
759 _keywords,
760 nullptr,
761 };
762 /* Parse known keywords, the remaining keywords are set using #CTX_py_state_push. */
763 kwds = kwds ? PyDict_Copy(kwds) : PyDict_New();
764 {
765 PyObject *kwds_parse = bpy_context_temp_override_extract_known_args(_keywords, kwds);
766 const int parse_result = _PyArg_ParseTupleAndKeywordsFast(args,
767 kwds_parse,
768 &_parser,
770 &params.window,
772 &params.screen,
774 &params.area,
776 &params.region);
777 Py_DECREF(kwds_parse);
778 if (!parse_result) {
779 Py_DECREF(kwds);
780 return nullptr;
781 }
782 }
783
784 bContext *C = static_cast<bContext *>(context_ptr->data);
785 {
786 /* Merge existing keys that don't exist in the keywords passed in.
787 * This makes it possible to nest context overrides. */
788 PyObject *context_dict_current = static_cast<PyObject *>(CTX_py_dict_get(C));
789 if (context_dict_current != nullptr) {
790 PyDict_Merge(kwds, context_dict_current, 0);
791 }
792 }
793
794 ContextStore ctx_temp = {nullptr};
795 if (params.window.ptr != nullptr) {
796 ctx_temp.win = static_cast<wmWindow *>(params.window.ptr->data);
797 ctx_temp.win_is_set = true;
798 }
799
800 if (params.screen.ptr != nullptr) {
801 ctx_temp.screen = static_cast<bScreen *>(params.screen.ptr->data);
802 ctx_temp.screen_is_set = true;
803 }
804
805 if (params.area.ptr != nullptr) {
806 ctx_temp.area = static_cast<ScrArea *>(params.area.ptr->data);
807 ctx_temp.area_is_set = true;
808 }
809
810 if (params.region.ptr != nullptr) {
811 ctx_temp.region = static_cast<ARegion *>(params.region.ptr->data);
812 ctx_temp.region_is_set = true;
813 }
814
817 ret->context = C;
818 ret->ctx_temp = ctx_temp;
819 memset(&ret->ctx_init, 0, sizeof(ret->ctx_init));
820
821 ret->ctx_temp_orig.screen = nullptr;
822 /* Store original logging flags now, before any logging_set() calls can modify them. */
823 ret->ctx_temp_orig.log_flag = CTX_member_logging_flag_get(C);
824
825 ret->py_state_context_dict = kwds;
826
827 PyObject_GC_Track(ret);
828
829 return reinterpret_cast<PyObject *>(ret);
830}
831
833
834/* -------------------------------------------------------------------- */
837
838#ifdef __GNUC__
839# ifdef __clang__
840# pragma clang diagnostic push
841# pragma clang diagnostic ignored "-Wcast-function-type"
842# else
843# pragma GCC diagnostic push
844# pragma GCC diagnostic ignored "-Wcast-function-type"
845# endif
846#endif
847
849 "temp_override",
850 reinterpret_cast<PyCFunction>(bpy_context_temp_override),
851 METH_VARARGS | METH_KEYWORDS,
852 bpy_context_temp_override_doc,
853};
854
855#ifdef __GNUC__
856# ifdef __clang__
857# pragma clang diagnostic pop
858# else
859# pragma GCC diagnostic pop
860# endif
861#endif
862
863void bpy_rna_context_types_init(PyObject *bpy_types)
864{
865 if (PyType_Ready(&BPyContextTempOverride_Type) < 0) {
867 return;
868 }
869 PyModule_AddType(bpy_types, &BPyContextTempOverride_Type);
870}
871
873
874} // namespace blender
#define C
Definition RandGen.cpp:29
#define BLI_assert_unreachable()
#define UNUSED_VARS(...)
BMesh Iterators.
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
static PyObject * bpy_context_temp_override_extract_known_args(const char *const *kwds_static, PyObject *kwds)
ScrArea * CTX_wm_area(const bContext *C)
void * CTX_py_dict_get(const bContext *C)
static bool wm_check_window_exists(const Main *bmain, const wmWindow *win)
static bool bpy_rna_context_temp_override_enter_ok_or_error(const BPyContextTempOverride *self, const Main *bmain, const wmWindow *win, const bScreen *screen, const ScrArea *area, const ARegion *region)
int PyC_ParseBool(PyObject *o, void *p)
static bool wm_check_screen_exists(const Main *bmain, const bScreen *screen)
static PyTypeObject BPyContextTempOverride_Type
void CTX_wm_window_set(bContext *C, wmWindow *win)
PyDoc_STRVAR(bpy_bm_new_doc, ".. function:: new(*, use_operators=True)\n" "\n" " :param use_operators: Support calling operators in :mod:`bmesh.ops` (uses some " "extra memory per vert/edge/face).\n" " :type use_operators: bool\n" " :return: Return a new, empty BMesh.\n" " :rtype: :class:`bmesh.types.BMesh`\n")
static bool wm_check_region_exists(const bScreen *screen, const ScrArea *area, const ARegion *region)
CTX_LogFlag CTX_member_logging_flag_get(const bContext *C)
static PyObject * bpy_rna_context_temp_override_logging_set(BPyContextTempOverride *self, PyObject *args, PyObject *kwds)
static int bpy_rna_context_temp_override_traverse(BPyContextTempOverride *self, visitproc visit, void *arg)
wmWindow * CTX_wm_window(const bContext *C)
void WM_window_set_active_workspace(bContext *C, wmWindow *win, WorkSpace *workspace)
static bool wm_check_screen_switch_supported(const bScreen *screen)
int pyrna_struct_as_ptr_or_null_parse(PyObject *o, void *p)
Definition bpy_rna.cc:9425
static int bpy_rna_context_temp_override_clear(BPyContextTempOverride *self)
void WM_window_set_active_screen(wmWindow *win, WorkSpace *workspace, bScreen *screen)
int BLI_findindex(const ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:593
void CTX_wm_screen_set(bContext *C, bScreen *screen)
static PyMethodDef bpy_rna_context_temp_override_methods[]
WorkSpaceLayout * BKE_workspace_layout_find_global(const Main *bmain, const bScreen *screen, WorkSpace **r_workspace) ATTR_NONNULL(1
Definition workspace.cc:516
void CTX_py_state_push(bContext *C, bContext_PyState *pystate, void *value)
static PyObject * bpy_context_temp_override(PyObject *self, PyObject *args, PyObject *kwds)
void CTX_py_state_pop(bContext *C, bContext_PyState *pystate)
static bool wm_check_area_exists(const wmWindow *win, const bScreen *screen, const ScrArea *area)
const PointerRNA * pyrna_struct_as_ptr(PyObject *py_obj, const StructRNA *srna)
Definition bpy_rna.cc:9391
Main * CTX_data_main(const bContext *C)
static void bpy_rna_context_temp_set_screen_for_window(bContext *C, wmWindow *win, bScreen *screen)
PyMethodDef BPY_rna_context_temp_override_method_def
void bpy_rna_context_types_init(PyObject *bpy_types)
bool BKE_screen_is_fullscreen_area(const bScreen *screen) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition screen.cc:1293
bScreen * CTX_wm_screen(const bContext *C)
void CTX_wm_region_set(bContext *C, ARegion *region)
static void bpy_rna_context_temp_override_dealloc(BPyContextTempOverride *self)
void CTX_member_logging_flag_set(bContext *C, CTX_LogFlag flag)
bScreen * WM_window_get_active_screen(const wmWindow *win)
ARegion * CTX_wm_region(const bContext *C)
static PyObject * bpy_rna_context_temp_override_enter(BPyContextTempOverride *self)
static PyObject * bpy_rna_context_temp_override_exit(BPyContextTempOverride *self, PyObject *)
void CTX_wm_area_set(bContext *C, ScrArea *area)
header-only compatibility defines.
struct blender::BPyContextTempOverride::@002306043167116355020201354203267051156052202164 ctx_temp_orig
PyObject_HEAD bContext * context
ListBaseT< wmWindowManager > wm
Definition BKE_main.hh:415
ListBaseT< bScreen > screens
Definition BKE_main.hh:400
ListBaseT< ScrArea > areabase
ListBaseT< ARegion > regionbase
ListBaseT< struct ScrArea > areabase
ListBaseT< ARegion > regionbase