Blender V5.3
bpy_app.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
12
13#include <Python.h>
14
15#include "bpy_app.hh"
16
17#include "bpy_app_alembic.hh"
19#include "bpy_app_ffmpeg.hh"
20#include "bpy_app_ocio.hh"
21#include "bpy_app_oiio.hh"
22#include "bpy_app_opensubdiv.hh"
23#include "bpy_app_openvdb.hh"
24#include "bpy_app_sdl.hh"
25
26#include "bpy_app_usd.hh"
27
29
30#include "bpy_app_handlers.hh"
31#include "bpy_capi_utils.hh"
32#include "bpy_driver.hh"
33
34#include "BPY_extern_python.hh" /* For #BPY_python_app_help_text_fn. */
35
36/* modules */
37#include "bpy_app_icons.hh"
38#include "bpy_app_timers.hh"
39
40#include "BLI_utildefines.hh"
41
42#include "BKE_appdir.hh"
43#include "BKE_blender_version.h"
44#include "BKE_global.hh"
45#include "BKE_main.hh"
46
47#include "GPU_init_exit.hh"
48#include "GPU_shader.hh"
49
50#include "UI_interface_icons.hh"
51
52#include "ED_undo.hh"
53#include "MEM_guardedalloc.h"
54
55#include "RNA_enum_types.hh" /* For `rna_enum_wm_job_type_items`. */
56
57/* for notifiers */
58#include "WM_api.hh"
59#include "WM_types.hh"
60
63#include "../generic/python_compat.hh" /* IWYU pragma: keep. */
64
65namespace blender {
66
67#ifdef BUILD_DATE
68extern "C" char build_date[];
69extern "C" char build_time[];
71extern "C" char build_commit_date[];
72extern "C" char build_commit_time[];
73extern "C" char build_hash[];
74extern "C" char build_branch[];
75extern "C" char build_platform[];
76extern "C" char build_type[];
77extern "C" char build_cflags[];
78extern "C" char build_cxxflags[];
79extern "C" char build_linkflags[];
80extern "C" char build_system[];
81#endif
82
83static PyTypeObject BlenderAppType;
84
85static PyStructSequence_Field app_info_fields[] = {
86 {"version",
87 "The Blender version as a tuple of 3 numbers (major, minor, micro). eg. (4, 3, 1)\n"
88 "\n"
89 ":type: tuple[int, int, int]\n"},
90 {"version_file",
91 "The Blender File version, as a tuple of 3 numbers (major, minor, file sub-version), that "
92 "will be used to save a .blend file. The last item in this tuple indicates the file "
93 "sub-version, which is different from the release micro version (the last item of the "
94 "``bpy.app.version`` tuple). The file sub-version can be incremented multiple times while a "
95 "Blender version is under development. This value is, and should be, used for handling "
96 "compatibility changes between Blender versions\n"
97 "\n"
98 ":type: tuple[int, int, int]\n"},
99 {"version_string",
100 "The Blender version formatted as a string\n"
101 "\n"
102 ":type: str\n"},
103 {"version_cycle",
104 "The release status of this build alpha/beta/rc/release\n"
105 "\n"
106 ":type: str\n"},
107 {"background",
108 "Boolean, True when blender is running without a user interface (started with -b)\n"
109 "\n"
110 ":type: bool\n"},
111 {"module",
112 "Boolean, True when running Blender as a python module\n"
113 "\n"
114 ":type: bool\n"},
115 {"factory_startup",
116 "Boolean, True when blender is running with --factory-startup\n"
117 "\n"
118 ":type: bool\n"},
119 {"portable",
120 "Boolean, True unless blender was built to reference absolute paths (on UNIX).\n"
121 "\n"
122 ":type: bool\n"},
123
124 /* buildinfo */
125 {"build_date",
126 "The date this Blender instance was built\n"
127 "\n"
128 ":type: bytes\n"},
129 {"build_time",
130 "The time this Blender instance was built\n"
131 "\n"
132 ":type: bytes\n"},
133 {"build_commit_timestamp",
134 "The unix timestamp of the commit this Blender instance was built from\n"
135 "\n"
136 ":type: int\n"},
137 {"build_commit_date",
138 "The date of the commit this Blender instance was built from\n"
139 "\n"
140 ":type: bytes\n"},
141 {"build_commit_time",
142 "The time of the commit this Blender instance was built from\n"
143 "\n"
144 ":type: bytes\n"},
145 {"build_hash",
146 "The commit hash this Blender instance was built with\n"
147 "\n"
148 ":type: bytes\n"},
149 {"build_branch",
150 "The branch this blender instance was built from\n"
151 "\n"
152 ":type: bytes\n"},
153 {"build_platform",
154 "The platform this blender instance was built for\n"
155 "\n"
156 ":type: bytes\n"},
157 {"build_type",
158 "The type of build (Release, Debug)\n"
159 "\n"
160 ":type: bytes\n"},
161 {"build_cflags",
162 "C compiler flags\n"
163 "\n"
164 ":type: bytes\n"},
165 {"build_cxxflags",
166 "C++ compiler flags\n"
167 "\n"
168 ":type: bytes\n"},
169 {"build_linkflags",
170 "Binary linking flags\n"
171 "\n"
172 ":type: bytes\n"},
173 {"build_system",
174 "Build system used\n"
175 "\n"
176 ":type: bytes\n"},
177
178 /* submodules */
179 {"alembic", "Alembic library information backend"},
180 {"usd", "USD library information backend"},
181 {"ffmpeg", "FFmpeg library information backend"},
182 {"ocio", "OpenColorIO library information backend"},
183 {"oiio", "OpenImageIO library information backend"},
184 {"opensubdiv", "OpenSubdiv library information backend"},
185 {"openvdb", "OpenVDB library information backend"},
186 {"sdl", "SDL library information backend"},
187 {"build_options", "A set containing most important enabled optional build features"},
188 {"handlers", "Application handler callbacks"},
189 {"translations", "Application and addons internationalization API"},
190
191 /* Modules (not struct sequence). */
192 {"icons", "Manage custom icons"},
193 {"timers", "Manage timers"},
194 {nullptr},
195};
196
198 /* Wrap. */
199 bpy_app_doc,
200 "This module contains application values that remain unchanged during runtime.\n");
201static PyStructSequence_Desc app_info_desc = {
202 /*name*/ "bpy.app",
203 /*doc*/ bpy_app_doc,
204 /*fields*/ app_info_fields,
205 /*n_in_sequence*/ ARRAY_SIZE(app_info_fields) - 1,
206};
207
208static PyObject *make_app_info()
209{
210 PyObject *app_info;
211 int pos = 0;
212
213 app_info = PyStructSequence_New(&BlenderAppType);
214 if (app_info == nullptr) {
215 return nullptr;
216 }
217#define SetIntItem(flag) PyStructSequence_SET_ITEM(app_info, pos++, PyLong_FromLong(flag))
218#define SetStrItem(str) PyStructSequence_SET_ITEM(app_info, pos++, PyUnicode_FromString(str))
219#define SetBytesItem(str) PyStructSequence_SET_ITEM(app_info, pos++, PyBytes_FromString(str))
220#define SetObjItem(obj) PyStructSequence_SET_ITEM(app_info, pos++, obj)
221
227
229 SetObjItem(PyBool_FromLong(G.background));
230#ifdef WITH_PYTHON_MODULE
231 SetObjItem(Py_NewRef(Py_True));
232#else
233 SetObjItem(Py_NewRef(Py_False));
234#endif
235 SetObjItem(PyBool_FromLong(G.factory_startup));
236
237#ifdef WITH_INSTALL_PORTABLE
238 SetObjItem(Py_NewRef(Py_True));
239#else
240 SetObjItem(Py_NewRef(Py_False));
241#endif
242
243/* build info, use bytes since we can't assume _any_ encoding:
244 * see patch #30154 for issue */
245#ifdef BUILD_DATE
259#else
260 SetBytesItem("Unknown");
261 SetBytesItem("Unknown");
262 SetIntItem(0);
263 SetBytesItem("Unknown");
264 SetBytesItem("Unknown");
265 SetBytesItem("Unknown");
266 SetBytesItem("Unknown");
267 SetBytesItem("Unknown");
268 SetBytesItem("Unknown");
269 SetBytesItem("Unknown");
270 SetBytesItem("Unknown");
271 SetBytesItem("Unknown");
272 SetBytesItem("Unknown");
273#endif
274
286
287 /* modules */
290
291#undef SetIntItem
292#undef SetStrItem
293#undef SetBytesItem
294#undef SetObjItem
295
296 if (PyErr_Occurred()) {
297 Py_DECREF(app_info);
298 return nullptr;
299 }
300 return app_info;
301}
302
303/* a few getsets because it makes sense for them to be in bpy.app even though
304 * they are not static */
305
307 /* Wrap. */
308 bpy_app_debug_doc,
309 "Boolean, for debug info "
310 "(started with ``--debug`` / ``--debug-*`` matching this attribute name).\n"
311 "\n"
312 ":type: bool\n");
313static PyObject *bpy_app_debug_get(PyObject * /*self*/, void *closure)
314{
315 const int flag = POINTER_AS_INT(closure);
316 return PyBool_FromLong(G.debug & flag);
317}
318
319static int bpy_app_debug_set(PyObject * /*self*/, PyObject *value, void *closure)
320{
321 const int flag = POINTER_AS_INT(closure);
322 const int param = PyObject_IsTrue(value);
323
324 if (param == -1) {
325 PyErr_SetString(PyExc_TypeError, "bpy.app.debug can only be True/False");
326 return -1;
327 }
328
329 if (param) {
330 G.debug |= flag;
331 }
332 else {
333 G.debug &= ~flag;
334 }
335
336 return 0;
337}
338
340 /* Wrap. */
341 bpy_app_internet_offline_doc,
342 "Boolean, true when internet access is allowed by Blender & 3rd party scripts "
343 "(read-only).\n"
344 "\n"
345 ":type: bool\n");
347 /* Wrap. */
348 bpy_app_internet_offline_override_doc,
349 "Boolean, true when internet access preference is overridden by the command line "
350 "(read-only).\n"
351 "\n"
352 ":type: bool\n");
354 /* Wrap. */
355 bpy_app_global_flag_doc,
356 "Boolean, for application behavior "
357 "(started with ``--enable-*`` matching this attribute name)\n"
358 "\n"
359 ":type: bool\n");
360
362 /* Wrap. */
363 bpy_app_autoexec_doc,
364 "Boolean, True when auto-execution is allowed (read-only).\n"
365 "\n"
366 ":type: bool\n");
368 /* Wrap. */
369 bpy_app_autoexec_override_doc,
370 "The auto-execution set by the command line, None when the preference isn't overridden "
371 "(read-only).\n"
372 "\n"
373 ":type: bool | None\n");
375 /* Wrap. */
376 bpy_app_autoexec_fail_doc,
377 "Boolean, True when auto-execution of scripts failed (read-only).\n"
378 "\n"
379 ":type: bool\n");
381 /* Wrap. */
382 bpy_app_autoexec_fail_quiet_doc,
383 "Boolean, True when auto-execution failure should be quiet, set after the warning is shown "
384 "once for the current blend file (read-only).\n"
385 "\n"
386 ":type: bool\n");
387
388static PyObject *bpy_app_global_flag_get(PyObject * /*self*/, void *closure)
389{
390 const int flag = POINTER_AS_INT(closure);
391 return PyBool_FromLong(G.f & flag);
392}
393
394static PyObject *bpy_app_autoexec_override_get(PyObject * /*self*/, void * /*closure*/)
395{
396 if (!G.autoexec_override.has_value()) {
397 Py_RETURN_NONE;
398 }
399 return PyBool_FromLong(*G.autoexec_override);
400}
401
402static int bpy_app_global_flag_set(PyObject * /*self*/, PyObject *value, void *closure)
403{
404 const int flag = POINTER_AS_INT(closure);
405 const int param = PyObject_IsTrue(value);
406
407 if (param == -1) {
408 PyErr_SetString(PyExc_TypeError, "bpy.app.use_* can only be True/False");
409 return -1;
410 }
411
412 if (param) {
413 G.f |= flag;
414 }
415 else {
416 G.f &= ~flag;
417 }
418
419 return 0;
420}
421
422static int bpy_app_global_flag_set__only_disable(PyObject * /*self*/,
423 PyObject *value,
424 void *closure)
425{
426 const int param = PyObject_IsTrue(value);
427 if (param == 1) {
428 PyErr_SetString(PyExc_ValueError, "This bpy.app.use_* option can only be disabled");
429 return -1;
430 }
431 return bpy_app_global_flag_set(nullptr, value, closure);
432}
433
435 /* Wrap. */
436 bpy_app_debug_value_doc,
437 "Integer value which can be set to non-zero values for testing purposes.\n"
438 "\n"
439 ":type: int\n");
440static PyObject *bpy_app_debug_value_get(PyObject * /*self*/, void * /*closure*/)
441{
442 return PyLong_FromLong(G.debug_value);
443}
444
445static int bpy_app_debug_value_set(PyObject * /*self*/, PyObject *value, void * /*closure*/)
446{
447 const short param = PyC_Long_AsI16(value);
448
449 if (param == -1 && PyErr_Occurred()) {
450 PyC_Err_SetString_Prefix(PyExc_TypeError,
451 "bpy.app.debug_value can only be set to a whole number");
452 return -1;
453 }
454
455 G.debug_value = param;
456
458
459 return 0;
460}
461
463 /* Wrap. */
464 bpy_app_tempdir_doc,
465 "String, the temp directory used by blender (read-only).\n"
466 "\n"
467 ":type: str\n");
468static PyObject *bpy_app_tempdir_get(PyObject * /*self*/, void * /*closure*/)
469{
471}
472
474 /* Wrap. */
475 bpy_app_cachedir_doc,
476 "String, the cache directory used by blender (read-only).\n"
477 "\n"
478 "In rare cases the default cache directory may not be available;\n"
479 "in this case a temporary directory is used.\n"
480 "\n"
481 ":type: str\n");
482static PyObject *bpy_app_cachedir_get(PyObject * /*self*/, void * /*closure*/)
483{
484 char cache_path[FILE_MAX];
485 BKE_appdir_folder_caches(cache_path, sizeof(cache_path));
486 BLI_assert_msg(cache_path[0], "BKE_appdir_folder_caches must never return an empty path");
487 return PyC_UnicodeFromBytes(cache_path);
488}
489
491 /* Wrap. */
492 bpy_app_driver_dict_doc,
493 "Dictionary for drivers namespace, editable in-place, reset on file load (read-only).\n"
494 "\n"
495 ":type: dict[str, Any]\n");
496static PyObject *bpy_app_driver_dict_get(PyObject * /*self*/, void * /*closure*/)
497{
498 if (bpy_pydriver_Dict == nullptr) {
499 if (bpy_pydriver_create_dict() != 0) {
500 PyErr_SetString(PyExc_RuntimeError, "bpy.app.driver_namespace failed to create dictionary");
501 return nullptr;
502 }
503 }
504
505 return Py_NewRef(bpy_pydriver_Dict);
506}
507
509 /* Wrap. */
510 bpy_app_render_icon_size_doc,
511 "Reference size for icon renders (read-only).\n"
512 "\n"
513 ":type: int\n");
515 /* Wrap. */
516 bpy_app_render_preview_size_doc,
517 "Reference size for preview renders (read-only).\n"
518 "\n"
519 ":type: int\n");
520static PyObject *bpy_app_render_preview_or_icon_size_get(PyObject * /*self*/, void *closure)
521{
522 return PyLong_FromLong(
524}
525
527 /* Wrap. */
528 bpy_app_autoexec_fail_message_doc,
529 "String, message describing the auto-execution failure (read-only).\n"
530 "\n"
531 ":type: str\n");
532
533static PyObject *bpy_app_autoexec_fail_message_get(PyObject * /*self*/, void * /*closure*/)
534{
535 return PyC_UnicodeFromBytes(G.autoexec_fail);
536}
537
539 /* Wrap. */
540 bpy_app_python_args_doc,
541 "Leading arguments to use when calling Python directly (via ``sys.executable``). "
542 "These arguments match settings Blender uses to "
543 "ensure Python runs with a compatible environment (read-only).\n"
544 "\n"
545 ":type: tuple[str, ...]\n");
546static PyObject *bpy_app_python_args_get(PyObject * /*self*/, void * /*closure*/)
547{
548 const char *args[1];
549 int args_num = 0;
551 /* Isolated Python environment. */
552 args[args_num++] = "-I";
553 }
554 return PyC_Tuple_PackArray_String(args, args_num);
555}
556
558 /* Wrap. */
559 bpy_app_binary_path_doc,
560 "The location of Blender's executable, useful for utilities that open new instances. "
561 "Read-only unless Blender is built as a Python module - in this case the value is "
562 "an empty string which script authors may point to a Blender binary.\n"
563 "\n"
564 ":type: str\n");
565static PyObject *bpy_app_binary_path_get(PyObject * /*self*/, void * /*closure*/)
566{
568}
569
570static int bpy_app_binary_path_set(PyObject * /*self*/, PyObject *value, void * /*closure*/)
571{
572#ifndef WITH_PYTHON_MODULE
573 PyErr_SetString(PyExc_AttributeError,
574 "bpy.app.binary_path is only writable when built as a Python module");
575 return -1;
576#endif
577 PyObject *value_coerce = nullptr;
578 const char *filepath = PyC_UnicodeAsBytes(value, &value_coerce);
579 if (filepath == nullptr) {
580 PyErr_Format(PyExc_ValueError, "expected a string or bytes, got %s", Py_TYPE(value)->tp_name);
581 return -1;
582 }
584 Py_XDECREF(value_coerce);
585 return 0;
586}
587
588static PyGetSetDef bpy_app_getsets[] = {
589 {"debug",
592 bpy_app_debug_doc,
593 reinterpret_cast<void *>(G_DEBUG)},
594 {"debug_freestyle",
597 bpy_app_debug_doc,
598 reinterpret_cast<void *>(G_DEBUG_FREESTYLE)},
599 {"debug_python",
602 bpy_app_debug_doc,
603 reinterpret_cast<void *>(G_DEBUG_PYTHON)},
604 {"debug_events",
607 bpy_app_debug_doc,
608 reinterpret_cast<void *>(G_DEBUG_EVENTS)},
609 {"debug_handlers",
612 bpy_app_debug_doc,
613 reinterpret_cast<void *>(G_DEBUG_HANDLERS)},
614 {"debug_wm",
617 bpy_app_debug_doc,
618 reinterpret_cast<void *>(G_DEBUG_WM)},
619 {"debug_depsgraph",
622 bpy_app_debug_doc,
623 reinterpret_cast<void *>(G_DEBUG_DEPSGRAPH)},
624 {"debug_depsgraph_build",
627 bpy_app_debug_doc,
628 reinterpret_cast<void *>(G_DEBUG_DEPSGRAPH_BUILD)},
629 {"debug_depsgraph_eval",
632 bpy_app_debug_doc,
633 reinterpret_cast<void *>(G_DEBUG_DEPSGRAPH_EVAL)},
634 {"debug_depsgraph_tag",
637 bpy_app_debug_doc,
638 reinterpret_cast<void *>(G_DEBUG_DEPSGRAPH_TAG)},
639 {"debug_depsgraph_time",
642 bpy_app_debug_doc,
643 reinterpret_cast<void *>(G_DEBUG_DEPSGRAPH_TIME)},
644 {"debug_depsgraph_pretty",
647 bpy_app_debug_doc,
648 reinterpret_cast<void *>(G_DEBUG_DEPSGRAPH_PRETTY)},
649 {"debug_simdata",
652 bpy_app_debug_doc,
653 reinterpret_cast<void *>(G_DEBUG_SIMDATA)},
654 {"debug_io",
657 bpy_app_debug_doc,
658 reinterpret_cast<void *>(G_DEBUG_IO)},
659
660 {"use_event_simulate",
663 bpy_app_global_flag_doc,
664 reinterpret_cast<void *>(G_FLAG_EVENT_SIMULATE)},
665
666 {"use_userpref_skip_save_on_exit",
669 bpy_app_global_flag_doc,
670 reinterpret_cast<void *>(G_FLAG_USERPREF_NO_SAVE_ON_EXIT)},
671
672 {"debug_value",
675 bpy_app_debug_value_doc,
676 nullptr},
677 {"tempdir", bpy_app_tempdir_get, nullptr, bpy_app_tempdir_doc, nullptr},
678 {"cachedir", bpy_app_cachedir_get, nullptr, bpy_app_cachedir_doc, nullptr},
679 {"driver_namespace", bpy_app_driver_dict_get, nullptr, bpy_app_driver_dict_doc, nullptr},
680
681 {"render_icon_size",
683 nullptr,
684 bpy_app_render_icon_size_doc,
685 reinterpret_cast<void *>(ICON_SIZE_ICON)},
686 {"render_preview_size",
688 nullptr,
689 bpy_app_render_preview_size_doc,
690 reinterpret_cast<void *>(ICON_SIZE_PREVIEW)},
691
692 {"online_access",
694 nullptr,
695 bpy_app_internet_offline_doc,
696 reinterpret_cast<void *>(G_FLAG_INTERNET_ALLOW)},
697 {"online_access_override",
699 nullptr,
700 bpy_app_internet_offline_override_doc,
701 reinterpret_cast<void *> G_FLAG_INTERNET_OVERRIDE_PREF_ANY},
702
703 /* security */
704 {"autoexec",
706 nullptr,
707 bpy_app_autoexec_doc,
708 reinterpret_cast<void *>(G_FLAG_SCRIPT_AUTOEXEC)},
709 {"autoexec_override",
711 nullptr,
712 bpy_app_autoexec_override_doc,
713 nullptr},
714 {"autoexec_fail",
716 nullptr,
717 bpy_app_autoexec_fail_doc,
718 reinterpret_cast<void *>(G_FLAG_SCRIPT_AUTOEXEC_FAIL)},
719 {"autoexec_fail_quiet",
721 nullptr,
722 bpy_app_autoexec_fail_quiet_doc,
723 reinterpret_cast<void *>(G_FLAG_SCRIPT_AUTOEXEC_FAIL_QUIET)},
724 {"autoexec_fail_message",
726 nullptr,
727 bpy_app_autoexec_fail_message_doc,
728 nullptr},
729
730 {"python_args", bpy_app_python_args_get, nullptr, bpy_app_python_args_doc, nullptr},
731
732 /* Support script authors setting the Blender binary path to use, otherwise this value
733 * is not known when built as a Python module. */
734 {"binary_path",
737 bpy_app_binary_path_doc,
738 nullptr},
739
740 {nullptr, nullptr, nullptr, nullptr, nullptr},
741};
742
744 /* Wrap. */
745 bpy_app_is_job_running_doc,
746 ".. function:: is_job_running(job_type)\n"
747 "\n"
748 " Check whether a job of the given type is running.\n"
749 "\n"
750 " :param job_type: job type in :ref:`rna_enum_wm_job_type_items`.\n"
751 " :type job_type: str\n"
752 " :return: Whether a job of the given type is currently running.\n"
753 " :rtype: bool\n");
754static PyObject *bpy_app_is_job_running(PyObject * /*self*/, PyObject *args, PyObject *kwds)
755{
756 BPy_EnumProperty_Parse job_type_enum{};
757 job_type_enum.items = rna_enum_wm_job_type_items;
758 job_type_enum.value = 0;
759
760 static const char *_keywords[] = {"job_type", nullptr};
761 static _PyArg_Parser _parser = {
762 "O&" /* `job_type` */
763 ":is_job_running",
764 _keywords,
765 nullptr,
766 };
767 if (!_PyArg_ParseTupleAndKeywordsFast(
768 args, kwds, &_parser, pyrna_enum_value_parse_string, &job_type_enum))
769 {
770 return nullptr;
771 }
772 wmWindowManager *wm = G_MAIN->wm.first();
773 if (job_type_enum.value == WM_JOB_TYPE_SHADER_COMPILATION) {
774 /* Shader compilation no longer uses the WM_job API, so we handle this as a special case
775 * to avoid breaking the Python API. */
776 return PyBool_FromLong(GPU_is_init() && GPU_shader_compiler_has_pending_work());
777 }
778 return PyBool_FromLong(WM_jobs_has_running(wm, nullptr, eWM_JobType(job_type_enum.value)));
779}
780
781char *(*BPY_python_app_help_text_fn)(bool all) = nullptr;
782
784 /* Wrap. */
785 bpy_app_help_text_doc,
786 ".. function:: help_text(*, all=False)\n"
787 "\n"
788 " Return the help text as a string.\n"
789 "\n"
790 " :param all: Return all arguments, "
791 "even those which aren't available for the current platform.\n"
792 " :type all: bool\n"
793 " :return: Help text.\n"
794 " :rtype: str\n");
795static PyObject *bpy_app_help_text(PyObject * /*self*/, PyObject *args, PyObject *kwds)
796{
797 bool all = false;
798 static const char *_keywords[] = {"all", nullptr};
799 static _PyArg_Parser _parser = {
800 "|$" /* Optional, keyword only arguments. */
801 "O&" /* `all` */
802 ":help_text",
803 _keywords,
804 nullptr,
805 };
806 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwds, &_parser, PyC_ParseBool, &all)) {
807 return nullptr;
808 }
809
810 char *buf = BPY_python_app_help_text_fn(all);
811 PyObject *result = PyUnicode_FromString(buf);
812 MEM_delete(buf);
813 return result;
814}
815
816#ifdef __GNUC__
817# ifdef __clang__
818# pragma clang diagnostic push
819# pragma clang diagnostic ignored "-Wcast-function-type"
820# else
821# pragma GCC diagnostic push
822# pragma GCC diagnostic ignored "-Wcast-function-type"
823# endif
824#endif
826 /* Wrap. */
827 bpy_app_memory_usage_undo_doc,
828 ".. function:: memory_usage_undo()\n"
829 "\n"
830 " Get undo memory usage information.\n"
831 "\n"
832 " :return: Memory usage of the undo stack in bytes.\n"
833 " :rtype: int\n");
834
835static PyObject *bpy_app_memory_usage_undo(PyObject * /*self*/, PyObject * /*args*/)
836{
837 size_t total_memory = 0;
838 UndoStack *ustack = ED_undo_stack_get();
839 if (ustack) {
840 total_memory = ED_undosys_total_memory_calc(ustack);
841 }
842 return PyLong_FromSize_t(total_memory);
843}
844
845static PyMethodDef bpy_app_methods[] = {
846 {"is_job_running",
847 reinterpret_cast<PyCFunction>(bpy_app_is_job_running),
848 METH_VARARGS | METH_KEYWORDS | METH_STATIC,
849 bpy_app_is_job_running_doc},
850 {"help_text",
851 reinterpret_cast<PyCFunction>(bpy_app_help_text),
852 METH_VARARGS | METH_KEYWORDS | METH_STATIC,
853 bpy_app_help_text_doc},
854 {"memory_usage_undo",
855 static_cast<PyCFunction>(bpy_app_memory_usage_undo),
856 METH_NOARGS | METH_STATIC,
857 bpy_app_memory_usage_undo_doc},
858 {nullptr, nullptr, 0, nullptr},
859};
860
861#ifdef __GNUC__
862# ifdef __clang__
863# pragma clang diagnostic pop
864# else
865# pragma GCC diagnostic pop
866# endif
867#endif
868
870{
871 /* tricky dynamic members, not to py-spec! */
872 for (PyGetSetDef *getset = bpy_app_getsets; getset->name; getset++) {
873 PyObject *item = PyDescr_NewGetSet(&BlenderAppType, getset);
874 PyDict_SetItem(BlenderAppType.tp_dict, PyDescr_NAME(item), item);
875 Py_DECREF(item);
876 }
877}
878
880{
881 for (PyMethodDef *method = bpy_app_methods; method->ml_name; method++) {
882 BLI_assert_msg(method->ml_flags & METH_STATIC, "Only static methods make sense for 'bpy.app'");
883 PyObject *item = PyCFunction_New(method, nullptr);
884 PyDict_SetItemString(BlenderAppType.tp_dict, method->ml_name, item);
885 Py_DECREF(item);
886 }
887}
888
889/* end dynamic bpy.app */
890
891PyObject *BPY_app_struct()
892{
893 PyObject *ret;
894
895 PyStructSequence_InitType(&BlenderAppType, &app_info_desc);
896
897 ret = make_app_info();
898
899 /* prevent user from creating new instances */
900 BlenderAppType.tp_init = nullptr;
901 BlenderAppType.tp_new = nullptr;
902 /* Without this we can't do `set(sys.modules)` #29635. */
903 BlenderAppType.tp_hash = reinterpret_cast<hashfunc>(Py_HashPointer);
904
905 /* Kind of a hack on top of #PyStructSequence. */
908
909 return ret;
910}
911
912} // namespace blender
#define BLENDER_VERSION_PATCH
#define BLENDER_VERSION_CYCLE
#define BLENDER_FILE_SUBVERSION
#define BLENDER_VERSION
#define BLENDER_FILE_VERSION
#define G_MAIN
#define G_FLAG_INTERNET_OVERRIDE_PREF_ANY
#define FILE_MAX
Read Blender memory allocation and freeing.
#define NC_WINDOW
Definition WM_types.hh:388
#define STRINGIFY(x)
#define POINTER_AS_INT(i)
#define BLI_assert_msg(a, msg)
#define SetBytesItem(str)
#define SetIntItem(flag)
#define SetStrItem(str)
#define SetObjItem(obj)
bool all(VecOp< bool, D >) RET
int icon_preview_to_render_size(enum eIconSizes size)
BMesh Iterators.
void WM_main_add_notifier(uint type, void *reference)
PyObject * PyC_Tuple_PackArray_String(const char **array, uint len)
const EnumPropertyItem rna_enum_wm_job_type_items[]
Definition rna_wm.cc:216
PyObject * PyC_Err_SetString_Prefix(PyObject *exception_type_prefix, const char *str)
@ ICON_SIZE_ICON
@ ICON_SIZE_PREVIEW
static PyObject * bpy_app_memory_usage_undo(PyObject *, PyObject *)
Definition bpy_app.cc:835
char build_system[]
Definition bpy_app.cc:80
int PyC_ParseBool(PyObject *o, void *p)
static PyObject * bpy_app_autoexec_override_get(PyObject *, void *)
Definition bpy_app.cc:394
PyObject * BPY_app_timers_module()
UndoStack * ED_undo_stack_get()
Definition ed_undo.cc:690
static void py_struct_seq_method_init()
Definition bpy_app.cc:879
static PyStructSequence_Desc app_info_desc
Definition bpy_app.cc:201
static PyObject * bpy_app_binary_path_get(PyObject *, void *)
Definition bpy_app.cc:565
static PyObject * bpy_app_cachedir_get(PyObject *, void *)
Definition bpy_app.cc:482
static PyGetSetDef bpy_app_getsets[]
Definition bpy_app.cc:588
int bpy_pydriver_create_dict()
Definition bpy_driver.cc:48
PyObject * BPY_app_icons_module()
@ WM_JOB_TYPE_SHADER_COMPILATION
Definition WM_api.hh:2040
PyObject * BPY_app_oiio_struct()
static int bpy_app_debug_set(PyObject *, PyObject *value, void *closure)
Definition bpy_app.cc:319
bool BPY_python_use_system_env_get()
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")
unsigned long ulong
Definition BKE_text.h:57
const char * BKE_tempdir_session() ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL
Definition appdir.cc:1283
static PyObject * bpy_app_debug_get(PyObject *, void *closure)
Definition bpy_app.cc:313
PyObject * PyC_UnicodeFromBytes(const char *str)
static PyTypeObject BlenderAppType
Definition bpy_app.cc:83
@ G_DEBUG_HANDLERS
@ G_DEBUG_EVENTS
@ G_DEBUG_DEPSGRAPH_PRETTY
@ G_DEBUG_FREESTYLE
@ G_DEBUG_PYTHON
@ G_DEBUG_DEPSGRAPH_BUILD
@ G_DEBUG_DEPSGRAPH_TAG
@ G_DEBUG_SIMDATA
@ G_DEBUG_DEPSGRAPH_EVAL
@ G_DEBUG_DEPSGRAPH
@ G_DEBUG_DEPSGRAPH_TIME
Global G
Definition blender.cc:57
PyObject * PyC_Tuple_Pack_I32(const Span< int > values)
static int bpy_app_global_flag_set__only_disable(PyObject *, PyObject *value, void *closure)
Definition bpy_app.cc:422
char build_commit_time[]
Definition bpy_app.cc:72
PyObject * BPY_app_openvdb_struct()
char build_platform[]
Definition bpy_app.cc:75
PyObject * bpy_pydriver_Dict
Definition bpy_driver.cc:42
PyObject * BPY_app_usd_struct()
static void py_struct_seq_getset_init()
Definition bpy_app.cc:869
PyObject * BPY_app_ocio_struct()
bool WM_jobs_has_running(const wmWindowManager *window_manager, const void *owner, const eWM_JobType type, const eWM_JobFlag exclude_flags)
Definition wm_jobs.cc:809
static PyMethodDef bpy_app_methods[]
Definition bpy_app.cc:845
bool GPU_shader_compiler_has_pending_work()
static PyObject * bpy_app_debug_value_get(PyObject *, void *)
Definition bpy_app.cc:440
static PyStructSequence_Field app_info_fields[]
Definition bpy_app.cc:85
int16_t PyC_Long_AsI16(PyObject *value)
char build_hash[]
Definition bpy_app.cc:73
static PyObject * bpy_app_global_flag_get(PyObject *, void *closure)
Definition bpy_app.cc:388
constexpr size_t ARRAY_SIZE(const T(&arg)[N]) noexcept
static int bpy_app_binary_path_set(PyObject *, PyObject *value, void *)
Definition bpy_app.cc:570
static PyObject * bpy_app_tempdir_get(PyObject *, void *)
Definition bpy_app.cc:468
PyObject * BPY_app_alembic_struct()
size_t ED_undosys_total_memory_calc(UndoStack *ustack)
Definition ed_undo.cc:1171
PyObject * BPY_app_opensubdiv_struct()
char build_linkflags[]
Definition bpy_app.cc:79
char build_branch[]
Definition bpy_app.cc:74
static PyObject * make_app_info()
Definition bpy_app.cc:208
const char * PyC_UnicodeAsBytes(PyObject *py_str, PyObject **r_coerce)
PyObject * BPY_app_handlers_struct()
char build_type[]
Definition bpy_app.cc:76
void BKE_appdir_program_path_init(const char *argv0) ATTR_NONNULL(1)
Definition appdir.cc:978
PyObject * BPY_app_translations_struct()
PyObject * BPY_app_build_options_struct()
@ G_FLAG_USERPREF_NO_SAVE_ON_EXIT
@ G_FLAG_INTERNET_ALLOW
@ G_FLAG_SCRIPT_AUTOEXEC_FAIL_QUIET
@ G_FLAG_EVENT_SIMULATE
@ G_FLAG_SCRIPT_AUTOEXEC_FAIL
@ G_FLAG_SCRIPT_AUTOEXEC
void BKE_appdir_folder_caches(char *path, size_t path_maxncpy) ATTR_NONNULL(1)
Definition appdir.cc:206
char build_time[]
Definition bpy_app.cc:69
char build_cflags[]
Definition bpy_app.cc:77
PyObject * BPY_app_ffmpeg_struct()
static int bpy_app_debug_value_set(PyObject *, PyObject *value, void *)
Definition bpy_app.cc:445
static PyObject * bpy_app_autoexec_fail_message_get(PyObject *, void *)
Definition bpy_app.cc:533
static PyObject * bpy_app_is_job_running(PyObject *, PyObject *args, PyObject *kwds)
Definition bpy_app.cc:754
PyObject * BPY_app_sdl_struct()
char build_commit_date[]
Definition bpy_app.cc:71
char *(*) BPY_python_app_help_text_fn(bool all)
Definition bpy_app.cc:781
const char * BKE_appdir_program_path() ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL
Definition appdir.cc:1001
static PyObject * bpy_app_render_preview_or_icon_size_get(PyObject *, void *closure)
Definition bpy_app.cc:520
char build_date[]
Definition bpy_app.cc:68
char build_cxxflags[]
Definition bpy_app.cc:78
int pyrna_enum_value_parse_string(PyObject *o, void *p)
bool GPU_is_init()
const char * BKE_blender_version_string()
Definition blender.cc:147
PyObject * BPY_app_struct()
Definition bpy_app.cc:891
static PyObject * bpy_app_driver_dict_get(PyObject *, void *)
Definition bpy_app.cc:496
static PyObject * bpy_app_python_args_get(PyObject *, void *)
Definition bpy_app.cc:546
static PyObject * bpy_app_help_text(PyObject *, PyObject *args, PyObject *kwds)
Definition bpy_app.cc:795
static int bpy_app_global_flag_set(PyObject *, PyObject *value, void *closure)
Definition bpy_app.cc:402
ulong build_commit_timestamp
Definition bpy_app.cc:70
header-only compatibility defines.
#define Py_HashPointer
const EnumPropertyItem * items