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 */
|
2007-12-24 18:53:37 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup python
|
2011-02-21 06:58:46 +00:00
|
|
|
*/
|
|
|
|
|
|
2012-02-17 18:59:41 +00:00
|
|
|
#pragma once
|
2007-12-24 18:53:37 +00:00
|
|
|
|
2025-01-07 12:39:13 +01:00
|
|
|
#include "BLI_sys_types.h"
|
|
|
|
|
|
2025-02-06 17:47:52 +01:00
|
|
|
#ifdef WITH_INTERNATIONAL
|
|
|
|
|
|
|
|
|
|
# include <optional>
|
|
|
|
|
|
|
|
|
|
# include "BLI_string_ref.hh"
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
2021-02-24 11:57:29 -03:00
|
|
|
struct ARegionType;
|
2021-07-16 11:48:54 +10:00
|
|
|
struct AnimationEvalContext;
|
2009-02-15 23:28:30 +00:00
|
|
|
struct ChannelDriver; /* DNA_anim_types.h */
|
2019-01-28 21:08:24 +11:00
|
|
|
struct ID; /* DNA_ID.h */
|
2007-12-24 18:53:37 +00:00
|
|
|
struct ListBase; /* DNA_listBase.h */
|
2019-01-28 21:08:24 +11:00
|
|
|
struct Object; /* DNA_object_types.h */
|
|
|
|
|
struct PathResolvedRNA;
|
|
|
|
|
struct Text; /* defined in DNA_text_types.h */
|
2007-12-24 18:53:37 +00:00
|
|
|
struct bConstraint; /* DNA_constraint_types.h */
|
|
|
|
|
struct bConstraintOb; /* DNA_constraint_types.h */
|
2021-07-23 16:56:00 +10:00
|
|
|
struct bConstraintTarget; /* DNA_constraint_types.h */
|
2008-12-21 10:36:29 +00:00
|
|
|
struct bContext;
|
2009-11-10 16:18:54 +00:00
|
|
|
struct bContextDataResult;
|
2024-10-11 18:33:29 +02:00
|
|
|
struct StructRNA;
|
2021-02-24 11:57:29 -03:00
|
|
|
struct wmWindowManager;
|
2009-06-22 18:19:18 +00:00
|
|
|
|
2013-12-17 18:44:56 +11:00
|
|
|
/* global interpreter lock */
|
|
|
|
|
|
2025-01-26 20:08:04 +01:00
|
|
|
using BPy_ThreadStatePtr = void *;
|
2013-12-17 18:44:56 +11:00
|
|
|
|
2021-12-02 17:24:04 +11:00
|
|
|
/**
|
|
|
|
|
* Analogue of #PyEval_SaveThread()
|
|
|
|
|
*/
|
2024-09-24 17:07:49 +02:00
|
|
|
BPy_ThreadStatePtr BPY_thread_save();
|
2021-12-02 17:24:04 +11:00
|
|
|
/**
|
|
|
|
|
* Analogue of #PyEval_RestoreThread()
|
|
|
|
|
*/
|
2013-12-17 18:44:56 +11:00
|
|
|
void BPY_thread_restore(BPy_ThreadStatePtr tstate);
|
|
|
|
|
|
2022-03-15 15:27:52 +11:00
|
|
|
/** Our own wrappers to #Py_BEGIN_ALLOW_THREADS / #Py_END_ALLOW_THREADS */
|
2013-12-17 18:44:56 +11:00
|
|
|
#define BPy_BEGIN_ALLOW_THREADS \
|
|
|
|
|
{ \
|
|
|
|
|
BPy_ThreadStatePtr _bpy_saved_tstate = BPY_thread_save(); \
|
|
|
|
|
(void)0
|
|
|
|
|
#define BPy_END_ALLOW_THREADS \
|
|
|
|
|
BPY_thread_restore(_bpy_saved_tstate); \
|
|
|
|
|
} \
|
2019-04-17 06:17:24 +02:00
|
|
|
(void)0
|
|
|
|
|
|
2024-10-11 14:17:50 +02:00
|
|
|
/**
|
|
|
|
|
* Print the Python backtrace of the current thread state.
|
|
|
|
|
*
|
|
|
|
|
* Should be safe to call from anywhere at any point, may not output anything if there is no valid
|
|
|
|
|
* python thread state available.
|
|
|
|
|
*/
|
|
|
|
|
void BPY_thread_backtrace_print();
|
|
|
|
|
|
2024-09-24 17:07:49 +02:00
|
|
|
void BPY_text_free_code(Text *text);
|
2021-12-10 21:40:53 +11:00
|
|
|
/**
|
|
|
|
|
* Needed so the #Main pointer in `bpy.data` doesn't become out of date.
|
|
|
|
|
*/
|
2024-09-24 17:07:49 +02:00
|
|
|
void BPY_modules_update();
|
|
|
|
|
void BPY_modules_load_user(bContext *C);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-04-26 14:25:58 +10:00
|
|
|
void BPY_app_handlers_reset(bool do_all);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-07-07 12:30:45 +10:00
|
|
|
/**
|
|
|
|
|
* Run on exit to free any cached data.
|
|
|
|
|
*/
|
2024-09-24 17:07:49 +02:00
|
|
|
void BPY_driver_exit();
|
2022-07-07 12:30:45 +10:00
|
|
|
|
2021-12-02 17:24:04 +11:00
|
|
|
/**
|
2022-03-15 15:27:52 +11:00
|
|
|
* Update function, it gets rid of python-drivers global dictionary: `bpy.app.driver_namespace`,
|
|
|
|
|
* forcing #BPY_driver_exec to recreate it. Use this when loading a new `.blend` file
|
|
|
|
|
* so any variables setup by the previous blend file are cleared.
|
2021-12-02 17:24:04 +11:00
|
|
|
*/
|
2024-09-24 17:07:49 +02:00
|
|
|
void BPY_driver_reset();
|
2021-12-02 17:24:04 +11:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This evaluates Python driver expressions, `driver_orig->expression`
|
|
|
|
|
* is a Python expression that should evaluate to a float number, which is returned.
|
|
|
|
|
*/
|
2024-09-24 17:07:49 +02:00
|
|
|
float BPY_driver_exec(PathResolvedRNA *anim_rna,
|
|
|
|
|
ChannelDriver *driver,
|
|
|
|
|
ChannelDriver *driver_orig,
|
|
|
|
|
const AnimationEvalContext *anim_eval_context);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-03-15 15:27:52 +11:00
|
|
|
/**
|
|
|
|
|
* Acquire the global-interpreter-lock (GIL) and wrap `Py_DECREF`.
|
|
|
|
|
* as there are some cases when this needs to be called outside the Python API code.
|
|
|
|
|
*/
|
|
|
|
|
void BPY_DECREF(void *pyob_ptr);
|
|
|
|
|
|
2012-10-26 10:54:02 +00:00
|
|
|
void BPY_DECREF_RNA_INVALIDATE(void *pyob_ptr);
|
2024-09-24 17:07:49 +02:00
|
|
|
int BPY_context_member_get(bContext *C, const char *member, bContextDataResult *result);
|
|
|
|
|
void BPY_context_set(bContext *C);
|
2021-12-10 21:40:53 +11:00
|
|
|
/**
|
|
|
|
|
* Use for updating while a python script runs - in case of file load.
|
|
|
|
|
*/
|
2024-09-24 17:07:49 +02:00
|
|
|
void BPY_context_update(bContext *C);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-12-02 17:24:04 +11:00
|
|
|
/**
|
|
|
|
|
* Use for `CTX_*_set(..)` functions need to set values which are later read back as expected.
|
|
|
|
|
* In this case we don't want the Python context to override the values as it causes problems
|
2023-02-12 14:37:16 +11:00
|
|
|
* see #66256.
|
2021-12-02 17:24:04 +11:00
|
|
|
*
|
|
|
|
|
* \param dict_p: A pointer to #bContext.data.py_context so we can assign a new value.
|
|
|
|
|
* \param dict_orig: The value of #bContext.data.py_context_orig to check if we need to copy.
|
|
|
|
|
*/
|
2020-09-17 18:23:12 +10:00
|
|
|
void BPY_context_dict_clear_members_array(void **dict_p,
|
|
|
|
|
void *dict_orig,
|
|
|
|
|
const char *context_members[],
|
|
|
|
|
uint context_members_len);
|
|
|
|
|
|
2024-09-24 17:07:49 +02:00
|
|
|
void BPY_id_release(ID *id);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2024-10-11 18:33:29 +02:00
|
|
|
/**
|
|
|
|
|
* Free (actually dereference) the Python type object representing the given #StrucRNA type,
|
|
|
|
|
* if it is defined.
|
|
|
|
|
*/
|
|
|
|
|
void BPY_free_srna_pytype(StructRNA *srna);
|
|
|
|
|
|
2021-12-10 21:40:53 +11:00
|
|
|
/**
|
|
|
|
|
* Avoids duplicating keyword list.
|
|
|
|
|
*/
|
2016-04-01 09:43:11 +11:00
|
|
|
bool BPY_string_is_keyword(const char *str);
|
|
|
|
|
|
2023-07-31 11:50:54 +10:00
|
|
|
/* `bpy_rna_callback.cc` */
|
2022-03-15 15:27:52 +11:00
|
|
|
|
2024-09-24 17:07:49 +02:00
|
|
|
void BPY_callback_screen_free(ARegionType *art);
|
|
|
|
|
void BPY_callback_wm_free(wmWindowManager *wm);
|
2021-02-24 11:57:29 -03:00
|
|
|
|
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
|
|
|
/* I18n for addons */
|
|
|
|
|
#ifdef WITH_INTERNATIONAL
|
2025-02-06 17:47:52 +01:00
|
|
|
std::optional<blender::StringRefNull> BPY_app_translations_py_pgettext(blender::StringRef msgctxt,
|
|
|
|
|
blender::StringRef msgid);
|
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
|
|
|
#endif
|