2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2010-01-31 23:41:46 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup pythonintern
|
2011-11-05 08:21:12 +00:00
|
|
|
*
|
|
|
|
|
* This file defines a 'PyStructSequence' accessed via 'bpy.app', mostly
|
|
|
|
|
* exposing static applications variables such as version and buildinfo
|
|
|
|
|
* however some writable variables have been added such as 'debug' and 'tempdir'
|
2011-02-27 20:10:08 +00:00
|
|
|
*/
|
|
|
|
|
|
2011-02-14 04:15:25 +00:00
|
|
|
#include <Python.h>
|
|
|
|
|
|
2024-09-24 12:05:13 +02:00
|
|
|
#include "bpy_app.hh"
|
2011-12-28 12:35:58 +00:00
|
|
|
|
2024-09-24 12:05:13 +02:00
|
|
|
#include "bpy_app_alembic.hh"
|
|
|
|
|
#include "bpy_app_build_options.hh"
|
|
|
|
|
#include "bpy_app_ffmpeg.hh"
|
|
|
|
|
#include "bpy_app_ocio.hh"
|
|
|
|
|
#include "bpy_app_oiio.hh"
|
|
|
|
|
#include "bpy_app_opensubdiv.hh"
|
|
|
|
|
#include "bpy_app_openvdb.hh"
|
|
|
|
|
#include "bpy_app_sdl.hh"
|
2025-09-03 19:15:05 +02:00
|
|
|
|
2024-09-24 12:05:13 +02:00
|
|
|
#include "bpy_app_usd.hh"
|
2011-12-28 12:35:58 +00:00
|
|
|
|
2024-09-24 12:05:13 +02:00
|
|
|
#include "bpy_app_translations.hh"
|
Python i18n API. Many thanks to Campbell and Brecht for the reviews and suggestions!
This commit adds:
* A new bpy.app.translations module giving some info about locales/translation stuff (current active locale, all locales currently known by blender, all translation contexts currently defined, etc.).
* The ability for addons to feature translations, using the (un)register functions of above module.
* Also cleans up "translate py string when storing into RNA prop" by removing "PROP_TRANSLATE" string's subtype, and adding a PROP_STRING_PY_TRANSLATE flag instead (this way it is no more exposed to python...).
Addon translations work with py dictionaries: each addon features a dict {lang: {(context, message): translation, ...}, ...}, which is registered when the addon is enabled (and unregistered when disabled).
Then, when a key (context, message) is not found in regular mo catalog, a cache dict for current locale is built from all registered addon translations, and key is searched in it.
Note: currently addons writers have to do all the work by hand, will add something (probably extend "edit translation" addon) to automate messages extraction from addons soon(ish)! To get a look to expected behavior from addons, have a look at render_copy_settings/__init__.py and render_copy_settings/translations.py (rather stupid example currently, but...). Once we have a complete process, I'll also update relevant wiki pages.
2013-01-20 17:29:07 +00:00
|
|
|
|
2024-09-24 12:05:13 +02:00
|
|
|
#include "bpy_app_handlers.hh"
|
2025-09-03 19:15:05 +02:00
|
|
|
#include "bpy_capi_utils.hh"
|
2024-09-24 12:23:25 +02:00
|
|
|
#include "bpy_driver.hh"
|
2010-01-31 23:41:46 +00:00
|
|
|
|
2024-09-24 17:07:49 +02:00
|
|
|
#include "BPY_extern_python.hh" /* For #BPY_python_app_help_text_fn. */
|
2023-06-28 11:40:17 +10:00
|
|
|
|
2018-04-20 15:25:18 +02:00
|
|
|
/* modules */
|
2024-09-24 12:05:13 +02:00
|
|
|
#include "bpy_app_icons.hh"
|
|
|
|
|
#include "bpy_app_timers.hh"
|
2018-04-20 15:25:18 +02:00
|
|
|
|
2011-01-07 18:36:47 +00:00
|
|
|
#include "BLI_utildefines.h"
|
2011-01-07 19:18:31 +00:00
|
|
|
|
2024-01-21 19:42:13 +01:00
|
|
|
#include "BKE_appdir.hh"
|
2016-04-24 22:42:41 +10:00
|
|
|
#include "BKE_blender_version.h"
|
2024-02-10 18:25:14 +01:00
|
|
|
#include "BKE_global.hh"
|
2023-12-01 19:43:16 +01:00
|
|
|
#include "BKE_main.hh"
|
2010-01-31 23:41:46 +00:00
|
|
|
|
2025-07-31 20:06:27 +02:00
|
|
|
#include "GPU_shader.hh"
|
|
|
|
|
|
2023-08-05 02:57:52 +02:00
|
|
|
#include "UI_interface_icons.hh"
|
2015-08-10 17:26:37 +02:00
|
|
|
|
2025-09-03 19:15:05 +02:00
|
|
|
#include "ED_undo.hh"
|
2023-05-27 16:33:46 +10:00
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
2023-08-10 22:40:27 +02:00
|
|
|
#include "RNA_enum_types.hh" /* For `rna_enum_wm_job_type_items`. */
|
Expose background job info to Python
Add `bpy.app.is_job_running(job_type)` as high-level indicator. Job
types currently exposed are `WM_JOB_TYPE_RENDER`,
`WM_JOB_TYPE_RENDER_PREVIEW`, and `WM_JOB_TYPE_OBJECT_BAKE`, as strings
with the `WM_JOB_TYPE_` prefix removed. The functions can be polled by
Python code to determine whether such background work is still ongoing
or not.
Furthermore, new app handles are added for
`object_bake_{pre,complete,canceled}`, which are called respectively
before an object baking job starts, completes sucessfully, and stops due
to a cancellation.
Motivation: There are various cases where Python can trigger the
execution of a background job, without getting notification that that
background job is done. As a result, it's hard to do things like
cleanups, or auto-quitting Blender after the work is done.
The approach in this commit can easily be extended with other job types,
when the need arises. The rendering of asset previews is one that's
likely to be added sooner than later, as there have already been
requests about this.
Reviewed By: campbellbarton
Differential Revision: https://developer.blender.org/D14587
2022-06-02 11:20:17 +02:00
|
|
|
|
2016-01-09 22:48:50 +11:00
|
|
|
/* for notifiers */
|
2023-08-04 23:11:22 +02:00
|
|
|
#include "WM_api.hh"
|
|
|
|
|
#include "WM_types.hh"
|
2016-01-09 22:48:50 +11:00
|
|
|
|
2024-09-24 15:25:36 +02:00
|
|
|
#include "../generic/py_capi_rna.hh"
|
|
|
|
|
#include "../generic/py_capi_utils.hh"
|
2025-06-20 04:19:35 +00:00
|
|
|
#include "../generic/python_compat.hh" /* IWYU pragma: keep. */
|
2010-10-13 14:14:22 +00:00
|
|
|
|
2010-01-31 23:41:46 +00:00
|
|
|
#ifdef BUILD_DATE
|
2023-07-21 02:18:59 +02:00
|
|
|
extern "C" char build_date[];
|
|
|
|
|
extern "C" char build_time[];
|
|
|
|
|
extern "C" ulong build_commit_timestamp;
|
|
|
|
|
extern "C" char build_commit_date[];
|
|
|
|
|
extern "C" char build_commit_time[];
|
|
|
|
|
extern "C" char build_hash[];
|
|
|
|
|
extern "C" char build_branch[];
|
|
|
|
|
extern "C" char build_platform[];
|
|
|
|
|
extern "C" char build_type[];
|
|
|
|
|
extern "C" char build_cflags[];
|
|
|
|
|
extern "C" char build_cxxflags[];
|
|
|
|
|
extern "C" char build_linkflags[];
|
|
|
|
|
extern "C" char build_system[];
|
2010-01-31 23:41:46 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
static PyTypeObject BlenderAppType;
|
|
|
|
|
|
2011-12-26 12:26:11 +00:00
|
|
|
static PyStructSequence_Field app_info_fields[] = {
|
Cleanup: document difference between `bpy.app.version` and `.version_file`
Clarify the meaning `bpy.app.version_file`, by being more explicit in the
description of `bpy.app.version` and their differences.
### Old:
`bpy.app.version`
: The Blender version as a tuple of 3 numbers. eg. (2, 83, 1)
`bpy.app.version_file`
: The Blender version, as a tuple, last used to save a .blend file, compatible with ``bpy.data.version``. This value should be used for handling compatibility changes between Blender versions
### New:
`bpy.app.version`
: The Blender version as a tuple of 3 numbers (major, minor, micro). eg. (4, 3, 1)
`bpy.app.version_file`
: The Blender File version, as a tuple of 3 numbers (major, minor, file sub-version), that will be used to save a .blend file. The last item in this tuple indicates the file sub-version, which is different from the release micro version (the last item of the `bpy.app.version` tuple). The file sub-version can be incremented multiple times while a Blender version is under development. This value is, and should be, used for handling compatibility changes between Blender versions
Pull Request: https://projects.blender.org/blender/blender/pulls/133142
2025-01-16 11:06:59 +01:00
|
|
|
{"version",
|
|
|
|
|
"The Blender version as a tuple of 3 numbers (major, minor, micro). eg. (4, 3, 1)"},
|
2021-05-30 11:07:38 -04:00
|
|
|
{"version_file",
|
Cleanup: document difference between `bpy.app.version` and `.version_file`
Clarify the meaning `bpy.app.version_file`, by being more explicit in the
description of `bpy.app.version` and their differences.
### Old:
`bpy.app.version`
: The Blender version as a tuple of 3 numbers. eg. (2, 83, 1)
`bpy.app.version_file`
: The Blender version, as a tuple, last used to save a .blend file, compatible with ``bpy.data.version``. This value should be used for handling compatibility changes between Blender versions
### New:
`bpy.app.version`
: The Blender version as a tuple of 3 numbers (major, minor, micro). eg. (4, 3, 1)
`bpy.app.version_file`
: The Blender File version, as a tuple of 3 numbers (major, minor, file sub-version), that will be used to save a .blend file. The last item in this tuple indicates the file sub-version, which is different from the release micro version (the last item of the `bpy.app.version` tuple). The file sub-version can be incremented multiple times while a Blender version is under development. This value is, and should be, used for handling compatibility changes between Blender versions
Pull Request: https://projects.blender.org/blender/blender/pulls/133142
2025-01-16 11:06:59 +01:00
|
|
|
"The Blender File version, as a tuple of 3 numbers (major, minor, file sub-version), that "
|
|
|
|
|
"will be used to save a .blend file. The last item in this tuple indicates the file "
|
|
|
|
|
"sub-version, which is different from the release micro version (the last item of the "
|
2025-08-22 15:10:29 +10:00
|
|
|
"``bpy.app.version`` tuple). The file sub-version can be incremented multiple times while a "
|
Cleanup: document difference between `bpy.app.version` and `.version_file`
Clarify the meaning `bpy.app.version_file`, by being more explicit in the
description of `bpy.app.version` and their differences.
### Old:
`bpy.app.version`
: The Blender version as a tuple of 3 numbers. eg. (2, 83, 1)
`bpy.app.version_file`
: The Blender version, as a tuple, last used to save a .blend file, compatible with ``bpy.data.version``. This value should be used for handling compatibility changes between Blender versions
### New:
`bpy.app.version`
: The Blender version as a tuple of 3 numbers (major, minor, micro). eg. (4, 3, 1)
`bpy.app.version_file`
: The Blender File version, as a tuple of 3 numbers (major, minor, file sub-version), that will be used to save a .blend file. The last item in this tuple indicates the file sub-version, which is different from the release micro version (the last item of the `bpy.app.version` tuple). The file sub-version can be incremented multiple times while a Blender version is under development. This value is, and should be, used for handling compatibility changes between Blender versions
Pull Request: https://projects.blender.org/blender/blender/pulls/133142
2025-01-16 11:06:59 +01:00
|
|
|
"Blender version is under development. This value is, and should be, used for handling "
|
|
|
|
|
"compatibility changes between Blender versions"},
|
2019-12-20 10:42:57 +11:00
|
|
|
{"version_string", "The Blender version formatted as a string"},
|
|
|
|
|
{"version_cycle", "The release status of this build alpha/beta/rc/release"},
|
|
|
|
|
{"background",
|
|
|
|
|
"Boolean, True when blender is running without a user interface (started with -b)"},
|
2025-01-17 10:13:31 +01:00
|
|
|
{"module", "Boolean, True when running Blender as a python module"},
|
2019-12-20 10:42:57 +11:00
|
|
|
{"factory_startup", "Boolean, True when blender is running with --factory-startup)"},
|
2025-01-16 20:31:37 +11:00
|
|
|
{"portable", "Boolean, True unless blender was built to reference absolute paths (on UNIX)."},
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-01-31 23:41:46 +00:00
|
|
|
/* buildinfo */
|
2019-12-20 10:42:57 +11:00
|
|
|
{"build_date", "The date this blender instance was built"},
|
|
|
|
|
{"build_time", "The time this blender instance was built"},
|
|
|
|
|
{"build_commit_timestamp", "The unix timestamp of commit this blender instance was built"},
|
|
|
|
|
{"build_commit_date", "The date of commit this blender instance was built"},
|
|
|
|
|
{"build_commit_time", "The time of commit this blender instance was built"},
|
|
|
|
|
{"build_hash", "The commit hash this blender instance was built with"},
|
|
|
|
|
{"build_branch", "The branch this blender instance was built from"},
|
|
|
|
|
{"build_platform", "The platform this blender instance was built for"},
|
|
|
|
|
{"build_type", "The type of build (Release, Debug)"},
|
|
|
|
|
{"build_cflags", "C compiler flags"},
|
|
|
|
|
{"build_cxxflags", "C++ compiler flags"},
|
|
|
|
|
{"build_linkflags", "Binary linking flags"},
|
|
|
|
|
{"build_system", "Build system used"},
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-06-24 16:54:30 +00:00
|
|
|
/* submodules */
|
2019-12-20 10:42:57 +11:00
|
|
|
{"alembic", "Alembic library information backend"},
|
2020-01-31 10:24:28 +01:00
|
|
|
{"usd", "USD library information backend"},
|
2019-12-20 10:42:57 +11:00
|
|
|
{"ffmpeg", "FFmpeg library information backend"},
|
|
|
|
|
{"ocio", "OpenColorIO library information backend"},
|
|
|
|
|
{"oiio", "OpenImageIO library information backend"},
|
|
|
|
|
{"opensubdiv", "OpenSubdiv library information backend"},
|
|
|
|
|
{"openvdb", "OpenVDB library information backend"},
|
|
|
|
|
{"sdl", "SDL library information backend"},
|
|
|
|
|
{"build_options", "A set containing most important enabled optional build features"},
|
|
|
|
|
{"handlers", "Application handler callbacks"},
|
|
|
|
|
{"translations", "Application and addons internationalization API"},
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-04-20 15:25:18 +02:00
|
|
|
/* Modules (not struct sequence). */
|
2019-12-20 10:42:57 +11:00
|
|
|
{"icons", "Manage custom icons"},
|
|
|
|
|
{"timers", "Manage timers"},
|
2023-07-21 02:18:59 +02:00
|
|
|
{nullptr},
|
2010-01-31 23:41:46 +00:00
|
|
|
};
|
|
|
|
|
|
2024-01-25 10:22:16 +11:00
|
|
|
PyDoc_STRVAR(
|
|
|
|
|
/* Wrap. */
|
|
|
|
|
bpy_app_doc,
|
2025-08-22 14:05:28 +10:00
|
|
|
"This module contains application values that remain unchanged during runtime.\n");
|
2011-12-26 12:26:11 +00:00
|
|
|
static PyStructSequence_Desc app_info_desc = {
|
2024-08-19 11:37:20 +10:00
|
|
|
/*name*/ "bpy.app",
|
|
|
|
|
/*doc*/ bpy_app_doc,
|
|
|
|
|
/*fields*/ app_info_fields,
|
|
|
|
|
/*n_in_sequence*/ ARRAY_SIZE(app_info_fields) - 1,
|
2010-01-31 23:41:46 +00:00
|
|
|
};
|
|
|
|
|
|
2023-07-21 10:59:54 +10:00
|
|
|
static PyObject *make_app_info()
|
2010-01-31 23:41:46 +00:00
|
|
|
{
|
|
|
|
|
PyObject *app_info;
|
2011-12-26 12:26:11 +00:00
|
|
|
int pos = 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-12-26 12:26:11 +00:00
|
|
|
app_info = PyStructSequence_New(&BlenderAppType);
|
2023-07-21 02:18:59 +02:00
|
|
|
if (app_info == nullptr) {
|
|
|
|
|
return nullptr;
|
2010-01-31 23:41:46 +00:00
|
|
|
}
|
|
|
|
|
#define SetIntItem(flag) PyStructSequence_SET_ITEM(app_info, pos++, PyLong_FromLong(flag))
|
2010-02-12 21:45:47 +00:00
|
|
|
#define SetStrItem(str) PyStructSequence_SET_ITEM(app_info, pos++, PyUnicode_FromString(str))
|
2012-03-04 03:14:38 +00:00
|
|
|
#define SetBytesItem(str) PyStructSequence_SET_ITEM(app_info, pos++, PyBytes_FromString(str))
|
2010-01-31 23:41:46 +00:00
|
|
|
#define SetObjItem(obj) PyStructSequence_SET_ITEM(app_info, pos++, obj)
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Blender: change bugfix release versioning from a/b/c to .1/.2/.3
The file subversion is no longer used in the Python API or user interface,
and is now internal to Blender.
User interface, Python API and file I/O metadata now use more consistent
formatting for version numbers. Official releases use "2.83.0", "2.83.1",
and releases under development use "2.90.0 Alpha", "2.90.0 Beta".
Some Python add-ons may need to lower the Blender version in bl_info to
(2, 83, 0) or (2, 90, 0) if they used a subversion number higher than 0.
https://wiki.blender.org/wiki/Reference/Release_Notes/2.83/Python_API#Compatibility
This change is in preparation of LTS releases, and also brings us more
in line with semantic versioning.
Fixes T76058.
Differential Revision: https://developer.blender.org/D7748
2020-05-25 10:49:04 +02:00
|
|
|
SetObjItem(
|
2023-07-21 02:18:59 +02:00
|
|
|
PyC_Tuple_Pack_I32({BLENDER_VERSION / 100, BLENDER_VERSION % 100, BLENDER_VERSION_PATCH}));
|
2020-10-22 12:29:38 +11:00
|
|
|
SetObjItem(PyC_Tuple_Pack_I32(
|
2023-07-21 02:18:59 +02:00
|
|
|
{BLENDER_FILE_VERSION / 100, BLENDER_FILE_VERSION % 100, BLENDER_FILE_SUBVERSION}));
|
Blender: change bugfix release versioning from a/b/c to .1/.2/.3
The file subversion is no longer used in the Python API or user interface,
and is now internal to Blender.
User interface, Python API and file I/O metadata now use more consistent
formatting for version numbers. Official releases use "2.83.0", "2.83.1",
and releases under development use "2.90.0 Alpha", "2.90.0 Beta".
Some Python add-ons may need to lower the Blender version in bl_info to
(2, 83, 0) or (2, 90, 0) if they used a subversion number higher than 0.
https://wiki.blender.org/wiki/Reference/Release_Notes/2.83/Python_API#Compatibility
This change is in preparation of LTS releases, and also brings us more
in line with semantic versioning.
Fixes T76058.
Differential Revision: https://developer.blender.org/D7748
2020-05-25 10:49:04 +02:00
|
|
|
SetStrItem(BKE_blender_version_string());
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-01 14:04:26 +00:00
|
|
|
SetStrItem(STRINGIFY(BLENDER_VERSION_CYCLE));
|
2010-05-18 15:57:51 +00:00
|
|
|
SetObjItem(PyBool_FromLong(G.background));
|
2025-01-17 10:13:31 +01:00
|
|
|
#ifdef WITH_PYTHON_MODULE
|
|
|
|
|
SetObjItem(Py_NewRef(Py_True));
|
|
|
|
|
#else
|
|
|
|
|
SetObjItem(Py_NewRef(Py_False));
|
|
|
|
|
#endif
|
2017-07-25 20:50:12 +10:00
|
|
|
SetObjItem(PyBool_FromLong(G.factory_startup));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2025-01-16 20:31:37 +11:00
|
|
|
#ifdef WITH_INSTALL_PORTABLE
|
|
|
|
|
SetObjItem(Py_NewRef(Py_True));
|
|
|
|
|
#else
|
|
|
|
|
SetObjItem(Py_NewRef(Py_False));
|
|
|
|
|
#endif
|
|
|
|
|
|
2023-07-21 02:18:59 +02:00
|
|
|
/* build info, use bytes since we can't assume _any_ encoding:
|
|
|
|
|
* see patch #30154 for issue */
|
2010-02-28 22:48:50 +00:00
|
|
|
#ifdef BUILD_DATE
|
2012-03-04 03:14:38 +00:00
|
|
|
SetBytesItem(build_date);
|
|
|
|
|
SetBytesItem(build_time);
|
2013-11-15 17:11:59 +06:00
|
|
|
SetIntItem(build_commit_timestamp);
|
|
|
|
|
SetBytesItem(build_commit_date);
|
|
|
|
|
SetBytesItem(build_commit_time);
|
2013-11-04 13:21:39 +00:00
|
|
|
SetBytesItem(build_hash);
|
|
|
|
|
SetBytesItem(build_branch);
|
2012-03-04 03:14:38 +00:00
|
|
|
SetBytesItem(build_platform);
|
|
|
|
|
SetBytesItem(build_type);
|
|
|
|
|
SetBytesItem(build_cflags);
|
|
|
|
|
SetBytesItem(build_cxxflags);
|
|
|
|
|
SetBytesItem(build_linkflags);
|
|
|
|
|
SetBytesItem(build_system);
|
2010-02-28 22:48:50 +00:00
|
|
|
#else
|
2012-03-04 03:14:38 +00:00
|
|
|
SetBytesItem("Unknown");
|
|
|
|
|
SetBytesItem("Unknown");
|
2013-11-15 17:11:59 +06:00
|
|
|
SetIntItem(0);
|
|
|
|
|
SetBytesItem("Unknown");
|
2012-03-04 03:14:38 +00:00
|
|
|
SetBytesItem("Unknown");
|
|
|
|
|
SetBytesItem("Unknown");
|
|
|
|
|
SetBytesItem("Unknown");
|
2013-11-04 13:21:39 +00:00
|
|
|
SetBytesItem("Unknown");
|
|
|
|
|
SetBytesItem("Unknown");
|
2012-03-04 03:14:38 +00:00
|
|
|
SetBytesItem("Unknown");
|
|
|
|
|
SetBytesItem("Unknown");
|
|
|
|
|
SetBytesItem("Unknown");
|
|
|
|
|
SetBytesItem("Unknown");
|
2010-02-28 22:48:50 +00:00
|
|
|
#endif
|
2010-01-31 23:41:46 +00:00
|
|
|
|
Basic Alembic support
All in all, this patch adds an Alembic importer, an Alembic exporter,
and a new CacheFile data block which, for now, wraps around an Alembic
archive. This data block is made available through a new modifier ("Mesh
Sequence Cache") as well as a new constraint ("Transform Cache") to
somewhat properly support respectively geometric and transformation data
streaming from alembic caches.
A more in-depth documentation is to be found on the wiki, as well as a
guide to compile alembic: https://wiki.blender.org/index.php/
User:Kevindietrich/AlembicBasicIo.
Many thanks to everyone involved in this little project, and huge shout
out to "cgstrive" for the thorough testings with Maya, 3ds Max, Houdini
and Realflow as well as @fjuhec, @jensverwiebe and @jasperge for the
custom builds and compile fixes.
Reviewers: sergey, campbellbarton, mont29
Reviewed By: sergey, campbellbarton, mont29
Differential Revision: https://developer.blender.org/D2060
2016-08-06 06:20:37 +02:00
|
|
|
SetObjItem(BPY_app_alembic_struct());
|
2020-01-31 10:24:28 +01:00
|
|
|
SetObjItem(BPY_app_usd_struct());
|
2011-12-28 12:35:58 +00:00
|
|
|
SetObjItem(BPY_app_ffmpeg_struct());
|
2013-12-08 15:03:17 +06:00
|
|
|
SetObjItem(BPY_app_ocio_struct());
|
|
|
|
|
SetObjItem(BPY_app_oiio_struct());
|
2017-06-07 12:16:48 +02:00
|
|
|
SetObjItem(BPY_app_opensubdiv_struct());
|
Implementation of OpenVDB as a possible cache format for smoke
simulations.
This commits implements OpenVDB as an extra cache format in the Point
Cache system for smoke simulations. Compilation with the library is
turned off by default for now, and shall be enabled when the library is
present.
A documentation of its doings is available here: http://
wiki.blender.org/index.php/User:Kevindietrich/OpenVDBSmokeExport.
A guide to compile OpenVDB can be found here (Linux): http://
wiki.blender.org/index.php?title=Dev:Doc/Building_Blender/Linux/
Dependencies_From_Source#OpenVDB
Reviewers: sergey, lukastoenne, brecht, campbellbarton
Reviewed By: brecht, campbellbarton
Subscribers: galenb, Blendify, robocyte, Lapineige, bliblubli,
jtheninja, lukasstockner97, dingto, brecht
Differential Revision: https://developer.blender.org/D1721
2016-01-23 08:39:29 +01:00
|
|
|
SetObjItem(BPY_app_openvdb_struct());
|
2015-02-18 12:07:48 +01:00
|
|
|
SetObjItem(BPY_app_sdl_struct());
|
2012-12-18 18:02:20 +00:00
|
|
|
SetObjItem(BPY_app_build_options_struct());
|
2011-06-24 16:54:30 +00:00
|
|
|
SetObjItem(BPY_app_handlers_struct());
|
Python i18n API. Many thanks to Campbell and Brecht for the reviews and suggestions!
This commit adds:
* A new bpy.app.translations module giving some info about locales/translation stuff (current active locale, all locales currently known by blender, all translation contexts currently defined, etc.).
* The ability for addons to feature translations, using the (un)register functions of above module.
* Also cleans up "translate py string when storing into RNA prop" by removing "PROP_TRANSLATE" string's subtype, and adding a PROP_STRING_PY_TRANSLATE flag instead (this way it is no more exposed to python...).
Addon translations work with py dictionaries: each addon features a dict {lang: {(context, message): translation, ...}, ...}, which is registered when the addon is enabled (and unregistered when disabled).
Then, when a key (context, message) is not found in regular mo catalog, a cache dict for current locale is built from all registered addon translations, and key is searched in it.
Note: currently addons writers have to do all the work by hand, will add something (probably extend "edit translation" addon) to automate messages extraction from addons soon(ish)! To get a look to expected behavior from addons, have a look at render_copy_settings/__init__.py and render_copy_settings/translations.py (rather stupid example currently, but...). Once we have a complete process, I'll also update relevant wiki pages.
2013-01-20 17:29:07 +00:00
|
|
|
SetObjItem(BPY_app_translations_struct());
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-04-20 15:25:18 +02:00
|
|
|
/* modules */
|
|
|
|
|
SetObjItem(BPY_app_icons_module());
|
2018-11-26 20:25:15 +01:00
|
|
|
SetObjItem(BPY_app_timers_module());
|
2018-04-20 15:25:18 +02:00
|
|
|
|
2010-01-31 23:41:46 +00:00
|
|
|
#undef SetIntItem
|
|
|
|
|
#undef SetStrItem
|
2012-03-04 03:14:38 +00:00
|
|
|
#undef SetBytesItem
|
2010-01-31 23:41:46 +00:00
|
|
|
#undef SetObjItem
|
|
|
|
|
|
|
|
|
|
if (PyErr_Occurred()) {
|
2021-03-04 15:46:07 +11:00
|
|
|
Py_DECREF(app_info);
|
2023-07-21 02:18:59 +02:00
|
|
|
return nullptr;
|
2010-01-31 23:41:46 +00:00
|
|
|
}
|
|
|
|
|
return app_info;
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-12 23:47:43 +00:00
|
|
|
/* a few getsets because it makes sense for them to be in bpy.app even though
|
|
|
|
|
* they are not static */
|
2011-11-26 15:18:30 +00:00
|
|
|
|
2024-01-25 10:22:16 +11:00
|
|
|
PyDoc_STRVAR(
|
|
|
|
|
/* Wrap. */
|
|
|
|
|
bpy_app_debug_doc,
|
|
|
|
|
"Boolean, for debug info "
|
2025-08-22 14:05:28 +10:00
|
|
|
"(started with ``--debug`` / ``--debug-*`` matching this attribute name).");
|
2023-07-21 02:18:59 +02:00
|
|
|
static PyObject *bpy_app_debug_get(PyObject * /*self*/, void *closure)
|
2010-10-12 23:47:43 +00:00
|
|
|
{
|
2018-09-19 12:05:58 +10:00
|
|
|
const int flag = POINTER_AS_INT(closure);
|
2012-03-31 00:59:17 +00:00
|
|
|
return PyBool_FromLong(G.debug & flag);
|
2010-10-12 23:47:43 +00:00
|
|
|
}
|
|
|
|
|
|
2023-07-21 02:18:59 +02:00
|
|
|
static int bpy_app_debug_set(PyObject * /*self*/, PyObject *value, void *closure)
|
2010-10-12 23:47:43 +00:00
|
|
|
{
|
2018-09-19 12:05:58 +10:00
|
|
|
const int flag = POINTER_AS_INT(closure);
|
2012-03-31 00:59:17 +00:00
|
|
|
const int param = PyObject_IsTrue(value);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-01-10 15:22:19 +00:00
|
|
|
if (param == -1) {
|
2010-10-12 23:47:43 +00:00
|
|
|
PyErr_SetString(PyExc_TypeError, "bpy.app.debug can only be True/False");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-30 06:12:48 +11:00
|
|
|
if (param) {
|
|
|
|
|
G.debug |= flag;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
G.debug &= ~flag;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-10-12 23:47:43 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-20 10:32:39 +10:00
|
|
|
PyDoc_STRVAR(
|
|
|
|
|
/* Wrap. */
|
|
|
|
|
bpy_app_internet_offline_doc,
|
2025-08-22 14:05:28 +10:00
|
|
|
"Boolean, true when internet access is allowed by Blender & 3rd party scripts "
|
|
|
|
|
"(read-only).");
|
2024-05-24 16:47:02 +10:00
|
|
|
PyDoc_STRVAR(
|
|
|
|
|
/* Wrap. */
|
|
|
|
|
bpy_app_internet_offline_override_doc,
|
2025-08-22 14:05:28 +10:00
|
|
|
"Boolean, true when internet access preference is overridden by the command line "
|
|
|
|
|
"(read-only).");
|
2024-01-25 10:22:16 +11:00
|
|
|
PyDoc_STRVAR(
|
|
|
|
|
/* Wrap. */
|
|
|
|
|
bpy_app_global_flag_doc,
|
|
|
|
|
"Boolean, for application behavior "
|
|
|
|
|
"(started with ``--enable-*`` matching this attribute name)");
|
2025-08-22 14:05:28 +10:00
|
|
|
|
2023-07-21 02:18:59 +02:00
|
|
|
static PyObject *bpy_app_global_flag_get(PyObject * /*self*/, void *closure)
|
2019-02-02 15:14:51 +11:00
|
|
|
{
|
|
|
|
|
const int flag = POINTER_AS_INT(closure);
|
|
|
|
|
return PyBool_FromLong(G.f & flag);
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-21 02:18:59 +02:00
|
|
|
static int bpy_app_global_flag_set(PyObject * /*self*/, PyObject *value, void *closure)
|
2019-02-02 15:14:51 +11:00
|
|
|
{
|
|
|
|
|
const int flag = POINTER_AS_INT(closure);
|
|
|
|
|
const int param = PyObject_IsTrue(value);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-02-02 15:14:51 +11:00
|
|
|
if (param == -1) {
|
|
|
|
|
PyErr_SetString(PyExc_TypeError, "bpy.app.use_* can only be True/False");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-30 06:12:48 +11:00
|
|
|
if (param) {
|
|
|
|
|
G.f |= flag;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
G.f &= ~flag;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-02-02 15:14:51 +11:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-21 02:18:59 +02:00
|
|
|
static int bpy_app_global_flag_set__only_disable(PyObject * /*self*/,
|
2019-02-02 15:14:51 +11:00
|
|
|
PyObject *value,
|
|
|
|
|
void *closure)
|
|
|
|
|
{
|
|
|
|
|
const int param = PyObject_IsTrue(value);
|
|
|
|
|
if (param == 1) {
|
|
|
|
|
PyErr_SetString(PyExc_ValueError, "This bpy.app.use_* option can only be disabled");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2023-07-21 02:18:59 +02:00
|
|
|
return bpy_app_global_flag_set(nullptr, value, closure);
|
2019-02-02 15:14:51 +11:00
|
|
|
}
|
|
|
|
|
|
2024-01-25 10:22:16 +11:00
|
|
|
PyDoc_STRVAR(
|
|
|
|
|
/* Wrap. */
|
|
|
|
|
bpy_app_debug_value_doc,
|
2025-08-22 14:05:28 +10:00
|
|
|
"Short, number which can be set to non-zero values for testing purposes.");
|
2023-07-21 02:18:59 +02:00
|
|
|
static PyObject *bpy_app_debug_value_get(PyObject * /*self*/, void * /*closure*/)
|
2010-12-15 06:03:45 +00:00
|
|
|
{
|
2012-11-21 02:28:36 +00:00
|
|
|
return PyLong_FromLong(G.debug_value);
|
2010-12-15 06:03:45 +00:00
|
|
|
}
|
|
|
|
|
|
2023-07-21 02:18:59 +02:00
|
|
|
static int bpy_app_debug_value_set(PyObject * /*self*/, PyObject *value, void * /*closure*/)
|
2010-12-15 06:03:45 +00:00
|
|
|
{
|
2020-08-20 16:10:13 +10:00
|
|
|
const short param = PyC_Long_AsI16(value);
|
2010-12-15 06:03:45 +00:00
|
|
|
|
|
|
|
|
if (param == -1 && PyErr_Occurred()) {
|
2019-01-17 08:46:36 +11:00
|
|
|
PyC_Err_SetString_Prefix(PyExc_TypeError,
|
|
|
|
|
"bpy.app.debug_value can only be set to a whole number");
|
2010-12-15 06:03:45 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
2018-06-04 08:54:17 +02:00
|
|
|
|
2019-01-17 08:46:36 +11:00
|
|
|
G.debug_value = param;
|
2010-12-15 06:03:45 +00:00
|
|
|
|
2023-07-21 02:18:59 +02:00
|
|
|
WM_main_add_notifier(NC_WINDOW, nullptr);
|
2016-01-09 22:48:50 +11:00
|
|
|
|
2010-12-15 06:03:45 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-25 10:22:16 +11:00
|
|
|
PyDoc_STRVAR(
|
|
|
|
|
/* Wrap. */
|
|
|
|
|
bpy_app_tempdir_doc,
|
2025-08-22 14:05:28 +10:00
|
|
|
"String, the temp directory used by blender (read-only).");
|
2023-07-21 02:18:59 +02:00
|
|
|
static PyObject *bpy_app_tempdir_get(PyObject * /*self*/, void * /*closure*/)
|
2010-10-12 23:47:43 +00:00
|
|
|
{
|
2023-02-15 16:15:59 +11:00
|
|
|
return PyC_UnicodeFromBytes(BKE_tempdir_session());
|
2010-10-12 23:47:43 +00:00
|
|
|
}
|
|
|
|
|
|
2011-11-26 15:18:30 +00:00
|
|
|
PyDoc_STRVAR(
|
2024-01-25 10:22:16 +11:00
|
|
|
/* Wrap. */
|
2011-11-26 15:18:30 +00:00
|
|
|
bpy_app_driver_dict_doc,
|
2025-08-22 14:05:28 +10:00
|
|
|
"Dictionary for drivers namespace, editable in-place, reset on file load (read-only).");
|
2023-07-21 02:18:59 +02:00
|
|
|
static PyObject *bpy_app_driver_dict_get(PyObject * /*self*/, void * /*closure*/)
|
2010-11-27 02:39:51 +00:00
|
|
|
{
|
2023-07-21 02:18:59 +02:00
|
|
|
if (bpy_pydriver_Dict == nullptr) {
|
2010-11-27 02:39:51 +00:00
|
|
|
if (bpy_pydriver_create_dict() != 0) {
|
|
|
|
|
PyErr_SetString(PyExc_RuntimeError, "bpy.app.driver_namespace failed to create dictionary");
|
2023-07-21 02:18:59 +02:00
|
|
|
return nullptr;
|
2012-03-26 20:41:54 +00:00
|
|
|
}
|
2010-11-27 02:39:51 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2024-10-12 00:20:55 +11:00
|
|
|
return Py_NewRef(bpy_pydriver_Dict);
|
2010-11-27 02:39:51 +00:00
|
|
|
}
|
|
|
|
|
|
2024-01-25 10:22:16 +11:00
|
|
|
PyDoc_STRVAR(
|
|
|
|
|
/* Wrap. */
|
|
|
|
|
bpy_app_preview_render_size_doc,
|
2025-08-22 14:05:28 +10:00
|
|
|
"Reference size for icon/preview renders (read-only).");
|
2023-07-21 02:18:59 +02:00
|
|
|
static PyObject *bpy_app_preview_render_size_get(PyObject * /*self*/, void *closure)
|
2015-08-10 17:26:37 +02:00
|
|
|
{
|
2023-07-21 02:18:59 +02:00
|
|
|
return PyLong_FromLong(
|
2023-07-21 10:59:54 +10:00
|
|
|
long(UI_icon_preview_to_render_size(eIconSizes(POINTER_AS_INT(closure)))));
|
2015-08-10 17:26:37 +02:00
|
|
|
}
|
|
|
|
|
|
2023-07-21 02:18:59 +02:00
|
|
|
static PyObject *bpy_app_autoexec_fail_message_get(PyObject * /*self*/, void * /*closure*/)
|
2018-11-23 11:44:57 +01:00
|
|
|
{
|
2023-02-15 16:15:59 +11:00
|
|
|
return PyC_UnicodeFromBytes(G.autoexec_fail);
|
2018-11-23 11:44:57 +01:00
|
|
|
}
|
|
|
|
|
|
2024-07-31 11:34:44 +10:00
|
|
|
PyDoc_STRVAR(
|
|
|
|
|
/* Wrap. */
|
|
|
|
|
bpy_app_python_args_doc,
|
|
|
|
|
"Leading arguments to use when calling Python directly (via ``sys.executable``). "
|
|
|
|
|
"These arguments match settings Blender uses to "
|
|
|
|
|
"ensure Python runs with a compatible environment (read-only).");
|
|
|
|
|
static PyObject *bpy_app_python_args_get(PyObject * /*self*/, void * /*closure*/)
|
|
|
|
|
{
|
|
|
|
|
const char *args[1];
|
|
|
|
|
int args_num = 0;
|
|
|
|
|
if (!BPY_python_use_system_env_get()) {
|
|
|
|
|
/* Isolated Python environment. */
|
|
|
|
|
args[args_num++] = "-I";
|
|
|
|
|
}
|
|
|
|
|
return PyC_Tuple_PackArray_String(args, args_num);
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-25 10:22:16 +11:00
|
|
|
PyDoc_STRVAR(
|
|
|
|
|
/* Wrap. */
|
|
|
|
|
bpy_app_binary_path_doc,
|
|
|
|
|
"The location of Blender's executable, useful for utilities that open new instances. "
|
|
|
|
|
"Read-only unless Blender is built as a Python module - in this case the value is "
|
|
|
|
|
"an empty string which script authors may point to a Blender binary.");
|
2023-07-21 02:18:59 +02:00
|
|
|
static PyObject *bpy_app_binary_path_get(PyObject * /*self*/, void * /*closure*/)
|
2022-09-09 13:59:53 +10:00
|
|
|
{
|
2023-02-15 16:15:59 +11:00
|
|
|
return PyC_UnicodeFromBytes(BKE_appdir_program_path());
|
2022-09-09 13:59:53 +10:00
|
|
|
}
|
|
|
|
|
|
2023-07-21 02:18:59 +02:00
|
|
|
static int bpy_app_binary_path_set(PyObject * /*self*/, PyObject *value, void * /*closure*/)
|
2022-09-09 13:59:53 +10:00
|
|
|
{
|
|
|
|
|
#ifndef WITH_PYTHON_MODULE
|
|
|
|
|
PyErr_SetString(PyExc_AttributeError,
|
|
|
|
|
"bpy.app.binary_path is only writable when built as a Python module");
|
|
|
|
|
return -1;
|
|
|
|
|
#endif
|
2023-07-21 02:18:59 +02:00
|
|
|
PyObject *value_coerce = nullptr;
|
2023-02-15 16:15:59 +11:00
|
|
|
const char *filepath = PyC_UnicodeAsBytes(value, &value_coerce);
|
2023-07-21 02:18:59 +02:00
|
|
|
if (filepath == nullptr) {
|
2022-09-09 13:59:53 +10:00
|
|
|
PyErr_Format(PyExc_ValueError, "expected a string or bytes, got %s", Py_TYPE(value)->tp_name);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
BKE_appdir_program_path_init(filepath);
|
|
|
|
|
Py_XDECREF(value_coerce);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-26 12:26:11 +00:00
|
|
|
static PyGetSetDef bpy_app_getsets[] = {
|
2019-12-20 10:42:57 +11:00
|
|
|
{"debug", bpy_app_debug_get, bpy_app_debug_set, bpy_app_debug_doc, (void *)G_DEBUG},
|
|
|
|
|
{"debug_freestyle",
|
2013-01-03 23:27:20 +00:00
|
|
|
bpy_app_debug_get,
|
|
|
|
|
bpy_app_debug_set,
|
2019-12-20 10:42:57 +11:00
|
|
|
bpy_app_debug_doc,
|
2013-01-03 23:27:20 +00:00
|
|
|
(void *)G_DEBUG_FREESTYLE},
|
2019-12-20 10:42:57 +11:00
|
|
|
{"debug_python",
|
2013-01-03 23:27:20 +00:00
|
|
|
bpy_app_debug_get,
|
|
|
|
|
bpy_app_debug_set,
|
2019-12-20 10:42:57 +11:00
|
|
|
bpy_app_debug_doc,
|
2013-01-03 23:27:20 +00:00
|
|
|
(void *)G_DEBUG_PYTHON},
|
2019-12-20 10:42:57 +11:00
|
|
|
{"debug_events",
|
2013-01-03 23:27:20 +00:00
|
|
|
bpy_app_debug_get,
|
|
|
|
|
bpy_app_debug_set,
|
2019-12-20 10:42:57 +11:00
|
|
|
bpy_app_debug_doc,
|
2013-01-03 23:27:20 +00:00
|
|
|
(void *)G_DEBUG_EVENTS},
|
2019-12-20 10:42:57 +11:00
|
|
|
{"debug_handlers",
|
2013-01-03 23:27:20 +00:00
|
|
|
bpy_app_debug_get,
|
|
|
|
|
bpy_app_debug_set,
|
2019-12-20 10:42:57 +11:00
|
|
|
bpy_app_debug_doc,
|
2013-01-03 23:27:20 +00:00
|
|
|
(void *)G_DEBUG_HANDLERS},
|
2019-12-20 10:42:57 +11:00
|
|
|
{"debug_wm", bpy_app_debug_get, bpy_app_debug_set, bpy_app_debug_doc, (void *)G_DEBUG_WM},
|
|
|
|
|
{"debug_depsgraph",
|
2018-02-21 10:44:36 +01:00
|
|
|
bpy_app_debug_get,
|
|
|
|
|
bpy_app_debug_set,
|
2019-12-20 10:42:57 +11:00
|
|
|
bpy_app_debug_doc,
|
2018-02-21 10:44:36 +01:00
|
|
|
(void *)G_DEBUG_DEPSGRAPH},
|
2019-12-20 10:42:57 +11:00
|
|
|
{"debug_depsgraph_build",
|
2018-02-21 10:44:36 +01:00
|
|
|
bpy_app_debug_get,
|
|
|
|
|
bpy_app_debug_set,
|
2019-12-20 10:42:57 +11:00
|
|
|
bpy_app_debug_doc,
|
2018-02-21 10:44:36 +01:00
|
|
|
(void *)G_DEBUG_DEPSGRAPH_BUILD},
|
2019-12-20 10:42:57 +11:00
|
|
|
{"debug_depsgraph_eval",
|
2018-02-21 10:44:36 +01:00
|
|
|
bpy_app_debug_get,
|
|
|
|
|
bpy_app_debug_set,
|
2019-12-20 10:42:57 +11:00
|
|
|
bpy_app_debug_doc,
|
2018-02-21 10:44:36 +01:00
|
|
|
(void *)G_DEBUG_DEPSGRAPH_EVAL},
|
2019-12-20 10:42:57 +11:00
|
|
|
{"debug_depsgraph_tag",
|
2018-03-12 17:01:02 +01:00
|
|
|
bpy_app_debug_get,
|
|
|
|
|
bpy_app_debug_set,
|
2019-12-20 10:42:57 +11:00
|
|
|
bpy_app_debug_doc,
|
2018-03-12 17:01:02 +01:00
|
|
|
(void *)G_DEBUG_DEPSGRAPH_TAG},
|
2019-12-20 10:42:57 +11:00
|
|
|
{"debug_depsgraph_time",
|
2018-03-16 12:24:08 +01:00
|
|
|
bpy_app_debug_get,
|
|
|
|
|
bpy_app_debug_set,
|
2019-12-20 10:42:57 +11:00
|
|
|
bpy_app_debug_doc,
|
2018-03-16 12:24:08 +01:00
|
|
|
(void *)G_DEBUG_DEPSGRAPH_TIME},
|
2019-12-20 10:42:57 +11:00
|
|
|
{"debug_depsgraph_pretty",
|
2015-01-21 14:00:59 +01:00
|
|
|
bpy_app_debug_get,
|
|
|
|
|
bpy_app_debug_set,
|
2019-12-20 10:42:57 +11:00
|
|
|
bpy_app_debug_doc,
|
2015-01-21 14:00:59 +01:00
|
|
|
(void *)G_DEBUG_DEPSGRAPH_PRETTY},
|
2019-12-20 10:42:57 +11:00
|
|
|
{"debug_simdata",
|
2015-05-06 11:07:15 +10:00
|
|
|
bpy_app_debug_get,
|
|
|
|
|
bpy_app_debug_set,
|
2019-12-20 10:42:57 +11:00
|
|
|
bpy_app_debug_doc,
|
2013-01-03 23:27:20 +00:00
|
|
|
(void *)G_DEBUG_SIMDATA},
|
2019-12-20 10:42:57 +11:00
|
|
|
{"debug_io", bpy_app_debug_get, bpy_app_debug_set, bpy_app_debug_doc, (void *)G_DEBUG_IO},
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-12-20 10:42:57 +11:00
|
|
|
{"use_event_simulate",
|
2019-02-02 15:14:51 +11:00
|
|
|
bpy_app_global_flag_get,
|
|
|
|
|
bpy_app_global_flag_set__only_disable,
|
2019-12-20 10:42:57 +11:00
|
|
|
bpy_app_global_flag_doc,
|
2019-02-02 15:14:51 +11:00
|
|
|
(void *)G_FLAG_EVENT_SIMULATE},
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-12-20 10:42:57 +11:00
|
|
|
{"use_userpref_skip_save_on_exit",
|
2019-06-12 12:21:21 +10:00
|
|
|
bpy_app_global_flag_get,
|
|
|
|
|
bpy_app_global_flag_set,
|
2019-12-20 10:42:57 +11:00
|
|
|
bpy_app_global_flag_doc,
|
2019-06-12 12:21:21 +10:00
|
|
|
(void *)G_FLAG_USERPREF_NO_SAVE_ON_EXIT},
|
|
|
|
|
|
2019-12-20 10:42:57 +11:00
|
|
|
{"debug_value",
|
2011-11-26 15:18:30 +00:00
|
|
|
bpy_app_debug_value_get,
|
|
|
|
|
bpy_app_debug_value_set,
|
2019-12-20 10:42:57 +11:00
|
|
|
bpy_app_debug_value_doc,
|
2023-07-21 02:18:59 +02:00
|
|
|
nullptr},
|
|
|
|
|
{"tempdir", bpy_app_tempdir_get, nullptr, bpy_app_tempdir_doc, nullptr},
|
|
|
|
|
{"driver_namespace", bpy_app_driver_dict_get, nullptr, bpy_app_driver_dict_doc, nullptr},
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-12-20 10:42:57 +11:00
|
|
|
{"render_icon_size",
|
2016-01-09 22:56:28 +11:00
|
|
|
bpy_app_preview_render_size_get,
|
2023-07-21 02:18:59 +02:00
|
|
|
nullptr,
|
2019-12-20 10:42:57 +11:00
|
|
|
bpy_app_preview_render_size_doc,
|
2016-01-09 22:56:28 +11:00
|
|
|
(void *)ICON_SIZE_ICON},
|
2019-12-20 10:42:57 +11:00
|
|
|
{"render_preview_size",
|
2016-01-09 22:56:28 +11:00
|
|
|
bpy_app_preview_render_size_get,
|
2023-07-21 02:18:59 +02:00
|
|
|
nullptr,
|
2019-12-20 10:42:57 +11:00
|
|
|
bpy_app_preview_render_size_doc,
|
2016-01-09 22:56:28 +11:00
|
|
|
(void *)ICON_SIZE_PREVIEW},
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2024-05-20 10:32:39 +10:00
|
|
|
{"online_access",
|
|
|
|
|
bpy_app_global_flag_get,
|
|
|
|
|
nullptr,
|
|
|
|
|
bpy_app_internet_offline_doc,
|
|
|
|
|
(void *)G_FLAG_INTERNET_ALLOW},
|
2024-05-24 16:47:02 +10:00
|
|
|
{"online_access_override",
|
|
|
|
|
bpy_app_global_flag_get,
|
|
|
|
|
nullptr,
|
|
|
|
|
bpy_app_internet_offline_override_doc,
|
|
|
|
|
(void *)G_FLAG_INTERNET_OVERRIDE_PREF_ANY},
|
2024-05-20 10:32:39 +10:00
|
|
|
|
2018-11-23 11:44:57 +01:00
|
|
|
/* security */
|
2023-07-21 02:18:59 +02:00
|
|
|
{"autoexec_fail",
|
|
|
|
|
bpy_app_global_flag_get,
|
|
|
|
|
nullptr,
|
|
|
|
|
nullptr,
|
|
|
|
|
(void *)G_FLAG_SCRIPT_AUTOEXEC_FAIL},
|
2019-12-20 10:42:57 +11:00
|
|
|
{"autoexec_fail_quiet",
|
2019-02-02 13:39:51 +11:00
|
|
|
bpy_app_global_flag_get,
|
2023-07-21 02:18:59 +02:00
|
|
|
nullptr,
|
|
|
|
|
nullptr,
|
2019-02-02 13:39:51 +11:00
|
|
|
(void *)G_FLAG_SCRIPT_AUTOEXEC_FAIL_QUIET},
|
2023-07-21 02:18:59 +02:00
|
|
|
{"autoexec_fail_message", bpy_app_autoexec_fail_message_get, nullptr, nullptr, nullptr},
|
2022-04-07 12:51:48 +02:00
|
|
|
|
2024-07-31 11:34:44 +10:00
|
|
|
{"python_args", bpy_app_python_args_get, nullptr, bpy_app_python_args_doc, nullptr},
|
|
|
|
|
|
2022-09-09 13:59:53 +10:00
|
|
|
/* Support script authors setting the Blender binary path to use, otherwise this value
|
|
|
|
|
* is not known when built as a Python module. */
|
|
|
|
|
{"binary_path",
|
|
|
|
|
bpy_app_binary_path_get,
|
|
|
|
|
bpy_app_binary_path_set,
|
|
|
|
|
bpy_app_binary_path_doc,
|
2023-07-21 02:18:59 +02:00
|
|
|
nullptr},
|
2022-09-09 13:59:53 +10:00
|
|
|
|
2023-07-21 02:18:59 +02:00
|
|
|
{nullptr, nullptr, nullptr, nullptr, nullptr},
|
2010-11-27 02:39:51 +00:00
|
|
|
};
|
2010-10-12 23:47:43 +00:00
|
|
|
|
2024-01-25 10:22:16 +11:00
|
|
|
PyDoc_STRVAR(
|
|
|
|
|
/* Wrap. */
|
|
|
|
|
bpy_app_is_job_running_doc,
|
|
|
|
|
".. staticmethod:: is_job_running(job_type)\n"
|
|
|
|
|
"\n"
|
|
|
|
|
" Check whether a job of the given type is running.\n"
|
|
|
|
|
"\n"
|
|
|
|
|
" :arg job_type: job type in :ref:`rna_enum_wm_job_type_items`.\n"
|
|
|
|
|
" :type job_type: str\n"
|
|
|
|
|
" :return: Whether a job of the given type is currently running.\n"
|
2025-08-22 14:05:28 +10:00
|
|
|
" :rtype: bool\n");
|
2023-07-21 02:18:59 +02:00
|
|
|
static PyObject *bpy_app_is_job_running(PyObject * /*self*/, PyObject *args, PyObject *kwds)
|
Expose background job info to Python
Add `bpy.app.is_job_running(job_type)` as high-level indicator. Job
types currently exposed are `WM_JOB_TYPE_RENDER`,
`WM_JOB_TYPE_RENDER_PREVIEW`, and `WM_JOB_TYPE_OBJECT_BAKE`, as strings
with the `WM_JOB_TYPE_` prefix removed. The functions can be polled by
Python code to determine whether such background work is still ongoing
or not.
Furthermore, new app handles are added for
`object_bake_{pre,complete,canceled}`, which are called respectively
before an object baking job starts, completes sucessfully, and stops due
to a cancellation.
Motivation: There are various cases where Python can trigger the
execution of a background job, without getting notification that that
background job is done. As a result, it's hard to do things like
cleanups, or auto-quitting Blender after the work is done.
The approach in this commit can easily be extended with other job types,
when the need arises. The rendering of asset previews is one that's
likely to be added sooner than later, as there have already been
requests about this.
Reviewed By: campbellbarton
Differential Revision: https://developer.blender.org/D14587
2022-06-02 11:20:17 +02:00
|
|
|
{
|
2023-07-21 02:18:59 +02:00
|
|
|
BPy_EnumProperty_Parse job_type_enum{};
|
|
|
|
|
job_type_enum.items = rna_enum_wm_job_type_items;
|
|
|
|
|
job_type_enum.value = 0;
|
|
|
|
|
|
|
|
|
|
static const char *_keywords[] = {"job_type", nullptr};
|
Expose background job info to Python
Add `bpy.app.is_job_running(job_type)` as high-level indicator. Job
types currently exposed are `WM_JOB_TYPE_RENDER`,
`WM_JOB_TYPE_RENDER_PREVIEW`, and `WM_JOB_TYPE_OBJECT_BAKE`, as strings
with the `WM_JOB_TYPE_` prefix removed. The functions can be polled by
Python code to determine whether such background work is still ongoing
or not.
Furthermore, new app handles are added for
`object_bake_{pre,complete,canceled}`, which are called respectively
before an object baking job starts, completes sucessfully, and stops due
to a cancellation.
Motivation: There are various cases where Python can trigger the
execution of a background job, without getting notification that that
background job is done. As a result, it's hard to do things like
cleanups, or auto-quitting Blender after the work is done.
The approach in this commit can easily be extended with other job types,
when the need arises. The rendering of asset previews is one that's
likely to be added sooner than later, as there have already been
requests about this.
Reviewed By: campbellbarton
Differential Revision: https://developer.blender.org/D14587
2022-06-02 11:20:17 +02:00
|
|
|
static _PyArg_Parser _parser = {
|
2023-08-30 14:05:32 +10:00
|
|
|
PY_ARG_PARSER_HEAD_COMPAT()
|
Expose background job info to Python
Add `bpy.app.is_job_running(job_type)` as high-level indicator. Job
types currently exposed are `WM_JOB_TYPE_RENDER`,
`WM_JOB_TYPE_RENDER_PREVIEW`, and `WM_JOB_TYPE_OBJECT_BAKE`, as strings
with the `WM_JOB_TYPE_` prefix removed. The functions can be polled by
Python code to determine whether such background work is still ongoing
or not.
Furthermore, new app handles are added for
`object_bake_{pre,complete,canceled}`, which are called respectively
before an object baking job starts, completes sucessfully, and stops due
to a cancellation.
Motivation: There are various cases where Python can trigger the
execution of a background job, without getting notification that that
background job is done. As a result, it's hard to do things like
cleanups, or auto-quitting Blender after the work is done.
The approach in this commit can easily be extended with other job types,
when the need arises. The rendering of asset previews is one that's
likely to be added sooner than later, as there have already been
requests about this.
Reviewed By: campbellbarton
Differential Revision: https://developer.blender.org/D14587
2022-06-02 11:20:17 +02:00
|
|
|
"O&" /* `job_type` */
|
|
|
|
|
":is_job_running",
|
|
|
|
|
_keywords,
|
2023-08-03 19:14:53 +10:00
|
|
|
nullptr,
|
Expose background job info to Python
Add `bpy.app.is_job_running(job_type)` as high-level indicator. Job
types currently exposed are `WM_JOB_TYPE_RENDER`,
`WM_JOB_TYPE_RENDER_PREVIEW`, and `WM_JOB_TYPE_OBJECT_BAKE`, as strings
with the `WM_JOB_TYPE_` prefix removed. The functions can be polled by
Python code to determine whether such background work is still ongoing
or not.
Furthermore, new app handles are added for
`object_bake_{pre,complete,canceled}`, which are called respectively
before an object baking job starts, completes sucessfully, and stops due
to a cancellation.
Motivation: There are various cases where Python can trigger the
execution of a background job, without getting notification that that
background job is done. As a result, it's hard to do things like
cleanups, or auto-quitting Blender after the work is done.
The approach in this commit can easily be extended with other job types,
when the need arises. The rendering of asset previews is one that's
likely to be added sooner than later, as there have already been
requests about this.
Reviewed By: campbellbarton
Differential Revision: https://developer.blender.org/D14587
2022-06-02 11:20:17 +02:00
|
|
|
};
|
|
|
|
|
if (!_PyArg_ParseTupleAndKeywordsFast(
|
|
|
|
|
args, kwds, &_parser, pyrna_enum_value_parse_string, &job_type_enum))
|
|
|
|
|
{
|
2023-07-21 02:18:59 +02:00
|
|
|
return nullptr;
|
Expose background job info to Python
Add `bpy.app.is_job_running(job_type)` as high-level indicator. Job
types currently exposed are `WM_JOB_TYPE_RENDER`,
`WM_JOB_TYPE_RENDER_PREVIEW`, and `WM_JOB_TYPE_OBJECT_BAKE`, as strings
with the `WM_JOB_TYPE_` prefix removed. The functions can be polled by
Python code to determine whether such background work is still ongoing
or not.
Furthermore, new app handles are added for
`object_bake_{pre,complete,canceled}`, which are called respectively
before an object baking job starts, completes sucessfully, and stops due
to a cancellation.
Motivation: There are various cases where Python can trigger the
execution of a background job, without getting notification that that
background job is done. As a result, it's hard to do things like
cleanups, or auto-quitting Blender after the work is done.
The approach in this commit can easily be extended with other job types,
when the need arises. The rendering of asset previews is one that's
likely to be added sooner than later, as there have already been
requests about this.
Reviewed By: campbellbarton
Differential Revision: https://developer.blender.org/D14587
2022-06-02 11:20:17 +02:00
|
|
|
}
|
2023-07-21 02:18:59 +02:00
|
|
|
wmWindowManager *wm = static_cast<wmWindowManager *>(G_MAIN->wm.first);
|
2025-07-31 20:06:27 +02:00
|
|
|
if (job_type_enum.value == WM_JOB_TYPE_SHADER_COMPILATION) {
|
|
|
|
|
/* Shader compilation no longer uses the WM_job API, so we handle this as a special case
|
|
|
|
|
* to avoid breaking the Python API. */
|
|
|
|
|
return PyBool_FromLong(GPU_shader_batch_is_compiling());
|
|
|
|
|
}
|
Expose background job info to Python
Add `bpy.app.is_job_running(job_type)` as high-level indicator. Job
types currently exposed are `WM_JOB_TYPE_RENDER`,
`WM_JOB_TYPE_RENDER_PREVIEW`, and `WM_JOB_TYPE_OBJECT_BAKE`, as strings
with the `WM_JOB_TYPE_` prefix removed. The functions can be polled by
Python code to determine whether such background work is still ongoing
or not.
Furthermore, new app handles are added for
`object_bake_{pre,complete,canceled}`, which are called respectively
before an object baking job starts, completes sucessfully, and stops due
to a cancellation.
Motivation: There are various cases where Python can trigger the
execution of a background job, without getting notification that that
background job is done. As a result, it's hard to do things like
cleanups, or auto-quitting Blender after the work is done.
The approach in this commit can easily be extended with other job types,
when the need arises. The rendering of asset previews is one that's
likely to be added sooner than later, as there have already been
requests about this.
Reviewed By: campbellbarton
Differential Revision: https://developer.blender.org/D14587
2022-06-02 11:20:17 +02:00
|
|
|
return PyBool_FromLong(WM_jobs_has_running_type(wm, job_type_enum.value));
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-21 02:18:59 +02:00
|
|
|
char *(*BPY_python_app_help_text_fn)(bool all) = nullptr;
|
2023-05-27 16:33:46 +10:00
|
|
|
|
2024-01-25 10:22:16 +11:00
|
|
|
PyDoc_STRVAR(
|
|
|
|
|
/* Wrap. */
|
|
|
|
|
bpy_app_help_text_doc,
|
2025-08-26 02:14:30 +00:00
|
|
|
".. staticmethod:: help_text(*, all=False)\n"
|
2024-01-25 10:22:16 +11:00
|
|
|
"\n"
|
|
|
|
|
" Return the help text as a string.\n"
|
|
|
|
|
"\n"
|
|
|
|
|
" :arg all: Return all arguments, "
|
|
|
|
|
"even those which aren't available for the current platform.\n"
|
|
|
|
|
" :type all: bool\n");
|
2023-07-21 02:18:59 +02:00
|
|
|
static PyObject *bpy_app_help_text(PyObject * /*self*/, PyObject *args, PyObject *kwds)
|
2023-05-27 16:33:46 +10:00
|
|
|
{
|
2023-05-27 17:23:19 +10:00
|
|
|
bool all = false;
|
2023-07-21 02:18:59 +02:00
|
|
|
static const char *_keywords[] = {"all", nullptr};
|
2023-05-27 17:23:19 +10:00
|
|
|
static _PyArg_Parser _parser = {
|
2023-08-30 14:05:32 +10:00
|
|
|
PY_ARG_PARSER_HEAD_COMPAT()
|
2023-05-27 17:23:19 +10:00
|
|
|
"|$" /* Optional keyword only arguments. */
|
|
|
|
|
"O&" /* `all` */
|
|
|
|
|
":help_text",
|
|
|
|
|
_keywords,
|
2023-08-03 19:14:53 +10:00
|
|
|
nullptr,
|
2023-05-27 17:23:19 +10:00
|
|
|
};
|
|
|
|
|
if (!_PyArg_ParseTupleAndKeywordsFast(args, kwds, &_parser, PyC_ParseBool, &all)) {
|
2023-07-21 02:18:59 +02:00
|
|
|
return nullptr;
|
2023-05-27 17:23:19 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char *buf = BPY_python_app_help_text_fn(all);
|
2023-05-27 16:33:46 +10:00
|
|
|
PyObject *result = PyUnicode_FromString(buf);
|
|
|
|
|
MEM_freeN(buf);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-01 12:06:03 +11:00
|
|
|
#ifdef __GNUC__
|
|
|
|
|
# ifdef __clang__
|
|
|
|
|
# pragma clang diagnostic push
|
|
|
|
|
# pragma clang diagnostic ignored "-Wcast-function-type"
|
|
|
|
|
# else
|
|
|
|
|
# pragma GCC diagnostic push
|
|
|
|
|
# pragma GCC diagnostic ignored "-Wcast-function-type"
|
|
|
|
|
# endif
|
2023-07-21 13:42:35 +10:00
|
|
|
#endif
|
2025-09-03 19:15:05 +02:00
|
|
|
PyDoc_STRVAR(
|
|
|
|
|
/* Wrap. */
|
2025-09-11 20:22:37 +05:30
|
|
|
bpy_app_memory_usage_undo_doc,
|
|
|
|
|
".. staticmethod:: memory_usage_undo()\n"
|
2025-09-03 19:15:05 +02:00
|
|
|
"\n"
|
|
|
|
|
" Get undo memory usage information.\n"
|
|
|
|
|
"\n"
|
2025-09-11 20:22:37 +05:30
|
|
|
" :return: Memory usage of the undo stack in bytes.\n"
|
2025-09-03 19:15:05 +02:00
|
|
|
" :rtype: int\n");
|
|
|
|
|
|
2025-09-11 20:22:37 +05:30
|
|
|
static PyObject *bpy_app_memory_usage_undo(PyObject * /*self*/, PyObject * /*args*/)
|
2025-09-03 19:15:05 +02:00
|
|
|
{
|
2025-09-11 12:59:32 +10:00
|
|
|
size_t total_memory = 0;
|
|
|
|
|
UndoStack *ustack = ED_undo_stack_get();
|
|
|
|
|
if (ustack) {
|
|
|
|
|
total_memory = ED_undosys_total_memory_calc(ustack);
|
|
|
|
|
}
|
2025-09-03 19:15:05 +02:00
|
|
|
return PyLong_FromSize_t(total_memory);
|
|
|
|
|
}
|
2023-07-21 13:42:35 +10:00
|
|
|
|
2023-06-03 08:36:28 +10:00
|
|
|
static PyMethodDef bpy_app_methods[] = {
|
Expose background job info to Python
Add `bpy.app.is_job_running(job_type)` as high-level indicator. Job
types currently exposed are `WM_JOB_TYPE_RENDER`,
`WM_JOB_TYPE_RENDER_PREVIEW`, and `WM_JOB_TYPE_OBJECT_BAKE`, as strings
with the `WM_JOB_TYPE_` prefix removed. The functions can be polled by
Python code to determine whether such background work is still ongoing
or not.
Furthermore, new app handles are added for
`object_bake_{pre,complete,canceled}`, which are called respectively
before an object baking job starts, completes sucessfully, and stops due
to a cancellation.
Motivation: There are various cases where Python can trigger the
execution of a background job, without getting notification that that
background job is done. As a result, it's hard to do things like
cleanups, or auto-quitting Blender after the work is done.
The approach in this commit can easily be extended with other job types,
when the need arises. The rendering of asset previews is one that's
likely to be added sooner than later, as there have already been
requests about this.
Reviewed By: campbellbarton
Differential Revision: https://developer.blender.org/D14587
2022-06-02 11:20:17 +02:00
|
|
|
{"is_job_running",
|
|
|
|
|
(PyCFunction)bpy_app_is_job_running,
|
|
|
|
|
METH_VARARGS | METH_KEYWORDS | METH_STATIC,
|
|
|
|
|
bpy_app_is_job_running_doc},
|
2023-05-27 16:33:46 +10:00
|
|
|
{"help_text",
|
|
|
|
|
(PyCFunction)bpy_app_help_text,
|
2023-05-27 17:23:19 +10:00
|
|
|
METH_VARARGS | METH_KEYWORDS | METH_STATIC,
|
2023-05-27 16:33:46 +10:00
|
|
|
bpy_app_help_text_doc},
|
2025-09-11 20:22:37 +05:30
|
|
|
{"memory_usage_undo",
|
|
|
|
|
(PyCFunction)bpy_app_memory_usage_undo,
|
2025-09-03 19:15:05 +02:00
|
|
|
METH_NOARGS | METH_STATIC,
|
2025-09-11 20:22:37 +05:30
|
|
|
bpy_app_memory_usage_undo_doc},
|
2023-07-21 02:18:59 +02:00
|
|
|
{nullptr, nullptr, 0, nullptr},
|
Expose background job info to Python
Add `bpy.app.is_job_running(job_type)` as high-level indicator. Job
types currently exposed are `WM_JOB_TYPE_RENDER`,
`WM_JOB_TYPE_RENDER_PREVIEW`, and `WM_JOB_TYPE_OBJECT_BAKE`, as strings
with the `WM_JOB_TYPE_` prefix removed. The functions can be polled by
Python code to determine whether such background work is still ongoing
or not.
Furthermore, new app handles are added for
`object_bake_{pre,complete,canceled}`, which are called respectively
before an object baking job starts, completes sucessfully, and stops due
to a cancellation.
Motivation: There are various cases where Python can trigger the
execution of a background job, without getting notification that that
background job is done. As a result, it's hard to do things like
cleanups, or auto-quitting Blender after the work is done.
The approach in this commit can easily be extended with other job types,
when the need arises. The rendering of asset previews is one that's
likely to be added sooner than later, as there have already been
requests about this.
Reviewed By: campbellbarton
Differential Revision: https://developer.blender.org/D14587
2022-06-02 11:20:17 +02:00
|
|
|
};
|
|
|
|
|
|
2025-04-01 12:06:03 +11:00
|
|
|
#ifdef __GNUC__
|
|
|
|
|
# ifdef __clang__
|
|
|
|
|
# pragma clang diagnostic pop
|
|
|
|
|
# else
|
|
|
|
|
# pragma GCC diagnostic pop
|
|
|
|
|
# endif
|
2023-07-21 13:42:35 +10:00
|
|
|
#endif
|
|
|
|
|
|
2023-07-21 10:59:54 +10:00
|
|
|
static void py_struct_seq_getset_init()
|
2010-10-12 23:47:43 +00:00
|
|
|
{
|
|
|
|
|
/* tricky dynamic members, not to py-spec! */
|
2016-07-14 17:28:28 +10:00
|
|
|
for (PyGetSetDef *getset = bpy_app_getsets; getset->name; getset++) {
|
|
|
|
|
PyObject *item = PyDescr_NewGetSet(&BlenderAppType, getset);
|
2016-07-14 18:27:20 +10:00
|
|
|
PyDict_SetItem(BlenderAppType.tp_dict, PyDescr_NAME(item), item);
|
2016-07-14 17:28:28 +10:00
|
|
|
Py_DECREF(item);
|
2010-11-27 02:39:51 +00:00
|
|
|
}
|
2010-10-12 23:47:43 +00:00
|
|
|
}
|
Expose background job info to Python
Add `bpy.app.is_job_running(job_type)` as high-level indicator. Job
types currently exposed are `WM_JOB_TYPE_RENDER`,
`WM_JOB_TYPE_RENDER_PREVIEW`, and `WM_JOB_TYPE_OBJECT_BAKE`, as strings
with the `WM_JOB_TYPE_` prefix removed. The functions can be polled by
Python code to determine whether such background work is still ongoing
or not.
Furthermore, new app handles are added for
`object_bake_{pre,complete,canceled}`, which are called respectively
before an object baking job starts, completes sucessfully, and stops due
to a cancellation.
Motivation: There are various cases where Python can trigger the
execution of a background job, without getting notification that that
background job is done. As a result, it's hard to do things like
cleanups, or auto-quitting Blender after the work is done.
The approach in this commit can easily be extended with other job types,
when the need arises. The rendering of asset previews is one that's
likely to be added sooner than later, as there have already been
requests about this.
Reviewed By: campbellbarton
Differential Revision: https://developer.blender.org/D14587
2022-06-02 11:20:17 +02:00
|
|
|
|
2023-07-21 10:59:54 +10:00
|
|
|
static void py_struct_seq_method_init()
|
Expose background job info to Python
Add `bpy.app.is_job_running(job_type)` as high-level indicator. Job
types currently exposed are `WM_JOB_TYPE_RENDER`,
`WM_JOB_TYPE_RENDER_PREVIEW`, and `WM_JOB_TYPE_OBJECT_BAKE`, as strings
with the `WM_JOB_TYPE_` prefix removed. The functions can be polled by
Python code to determine whether such background work is still ongoing
or not.
Furthermore, new app handles are added for
`object_bake_{pre,complete,canceled}`, which are called respectively
before an object baking job starts, completes sucessfully, and stops due
to a cancellation.
Motivation: There are various cases where Python can trigger the
execution of a background job, without getting notification that that
background job is done. As a result, it's hard to do things like
cleanups, or auto-quitting Blender after the work is done.
The approach in this commit can easily be extended with other job types,
when the need arises. The rendering of asset previews is one that's
likely to be added sooner than later, as there have already been
requests about this.
Reviewed By: campbellbarton
Differential Revision: https://developer.blender.org/D14587
2022-06-02 11:20:17 +02:00
|
|
|
{
|
|
|
|
|
for (PyMethodDef *method = bpy_app_methods; method->ml_name; method++) {
|
|
|
|
|
BLI_assert_msg(method->ml_flags & METH_STATIC, "Only static methods make sense for 'bpy.app'");
|
2023-07-21 02:18:59 +02:00
|
|
|
PyObject *item = PyCFunction_New(method, nullptr);
|
Expose background job info to Python
Add `bpy.app.is_job_running(job_type)` as high-level indicator. Job
types currently exposed are `WM_JOB_TYPE_RENDER`,
`WM_JOB_TYPE_RENDER_PREVIEW`, and `WM_JOB_TYPE_OBJECT_BAKE`, as strings
with the `WM_JOB_TYPE_` prefix removed. The functions can be polled by
Python code to determine whether such background work is still ongoing
or not.
Furthermore, new app handles are added for
`object_bake_{pre,complete,canceled}`, which are called respectively
before an object baking job starts, completes sucessfully, and stops due
to a cancellation.
Motivation: There are various cases where Python can trigger the
execution of a background job, without getting notification that that
background job is done. As a result, it's hard to do things like
cleanups, or auto-quitting Blender after the work is done.
The approach in this commit can easily be extended with other job types,
when the need arises. The rendering of asset previews is one that's
likely to be added sooner than later, as there have already been
requests about this.
Reviewed By: campbellbarton
Differential Revision: https://developer.blender.org/D14587
2022-06-02 11:20:17 +02:00
|
|
|
PyDict_SetItemString(BlenderAppType.tp_dict, method->ml_name, item);
|
|
|
|
|
Py_DECREF(item);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-12 23:47:43 +00:00
|
|
|
/* end dynamic bpy.app */
|
|
|
|
|
|
2023-07-21 10:59:54 +10:00
|
|
|
PyObject *BPY_app_struct()
|
2010-01-31 23:41:46 +00:00
|
|
|
{
|
|
|
|
|
PyObject *ret;
|
2018-06-04 08:54:17 +02:00
|
|
|
|
2010-01-31 23:41:46 +00:00
|
|
|
PyStructSequence_InitType(&BlenderAppType, &app_info_desc);
|
|
|
|
|
|
2011-12-26 12:26:11 +00:00
|
|
|
ret = make_app_info();
|
2010-01-31 23:41:46 +00:00
|
|
|
|
|
|
|
|
/* prevent user from creating new instances */
|
2023-07-21 02:18:59 +02:00
|
|
|
BlenderAppType.tp_init = nullptr;
|
|
|
|
|
BlenderAppType.tp_new = nullptr;
|
2023-05-24 11:21:18 +10:00
|
|
|
/* Without this we can't do `set(sys.modules)` #29635. */
|
2025-06-20 04:19:35 +00:00
|
|
|
BlenderAppType.tp_hash = (hashfunc)Py_HashPointer;
|
2010-10-12 23:47:43 +00:00
|
|
|
|
2022-09-16 18:13:19 +10:00
|
|
|
/* Kind of a hack on top of #PyStructSequence. */
|
2010-10-12 23:47:43 +00:00
|
|
|
py_struct_seq_getset_init();
|
Expose background job info to Python
Add `bpy.app.is_job_running(job_type)` as high-level indicator. Job
types currently exposed are `WM_JOB_TYPE_RENDER`,
`WM_JOB_TYPE_RENDER_PREVIEW`, and `WM_JOB_TYPE_OBJECT_BAKE`, as strings
with the `WM_JOB_TYPE_` prefix removed. The functions can be polled by
Python code to determine whether such background work is still ongoing
or not.
Furthermore, new app handles are added for
`object_bake_{pre,complete,canceled}`, which are called respectively
before an object baking job starts, completes sucessfully, and stops due
to a cancellation.
Motivation: There are various cases where Python can trigger the
execution of a background job, without getting notification that that
background job is done. As a result, it's hard to do things like
cleanups, or auto-quitting Blender after the work is done.
The approach in this commit can easily be extended with other job types,
when the need arises. The rendering of asset previews is one that's
likely to be added sooner than later, as there have already been
requests about this.
Reviewed By: campbellbarton
Differential Revision: https://developer.blender.org/D14587
2022-06-02 11:20:17 +02:00
|
|
|
py_struct_seq_method_init();
|
2010-10-12 23:47:43 +00:00
|
|
|
|
2010-01-31 23:49:04 +00:00
|
|
|
return ret;
|
2010-01-31 23:41:46 +00:00
|
|
|
}
|