|
Blender V5.0
|
#include <Python.h>#include <frameobject.h>#include <optional>#include "../generic/python_compat.hh"#include "CLG_log.h"#include "BLI_path_utils.hh"#include "BLI_string.h"#include "BLI_string_utf8.h"#include "BLI_threads.h"#include "BLI_utildefines.h"#include "BLT_translation.hh"#include "RNA_types.hh"#include "bpy.hh"#include "bpy_capi_utils.hh"#include "bpy_intern_string.hh"#include "bpy_path.hh"#include "bpy_props.hh"#include "bpy_rna.hh"#include "bpy_app_translations.hh"#include "DNA_text_types.h"#include "BKE_appdir.hh"#include "BKE_context.hh"#include "BKE_global.hh"#include "BKE_main.hh"#include "BKE_text.h"#include "BPY_extern.hh"#include "BPY_extern_python.hh"#include "BPY_extern_run.hh"#include "../generic/py_capi_utils.hh"#include "../bmesh/bmesh_py_api.hh"#include "../generic/bl_math_py_api.hh"#include "../generic/blf_py_api.hh"#include "../generic/idprop_py_api.hh"#include "../generic/imbuf_py_api.hh"#include "../gpu/gpu_py_api.hh"#include "../mathutils/mathutils.hh"Go to the source code of this file.
Functions | |
| CLG_LOGREF_DECLARE_GLOBAL (BPY_LOG_INTERFACE, "bpy.interface") | |
| CLG_LOGREF_DECLARE_GLOBAL (BPY_LOG_RNA, "bpy.rna") | |
| void | BPY_context_update (bContext *C) |
| void | bpy_context_set (bContext *C, PyGILState_STATE *gilstate) |
| void | bpy_context_clear (bContext *, const PyGILState_STATE *gilstate) |
| static void | bpy_context_end (bContext *C) |
| void | BPY_context_dict_clear_members_array (void **dict_p, void *dict_orig, const char *context_members[], uint context_members_len) |
| void | BPY_text_free_code (Text *text) |
| void | BPY_modules_update () |
| bContext * | BPY_context_get () |
| void | BPY_context_set (bContext *C) |
| static void | pystatus_exit_on_error (const PyStatus &status) |
| void | BPY_python_start (bContext *C, int argc, const char **argv) |
| void | BPY_python_end (const bool do_python_exit) |
| void | BPY_python_reset (bContext *C) |
| void | BPY_python_use_system_env () |
| bool | BPY_python_use_system_env_get () |
| void | BPY_python_backtrace (FILE *fp) |
| void | BPY_DECREF (void *pyob_ptr) |
| void | BPY_DECREF_RNA_INVALIDATE (void *pyob_ptr) |
| void | BPY_modules_load_user (bContext *C) |
| static void | bpy_context_log_member_error (const bContext *C, const char *message) |
| bool | BPY_context_member_get (bContext *C, const char *member, bContextDataResult *result) |
| std::optional< std::string > | BPY_python_current_file_and_line () |
| bool | BPY_string_is_keyword (const char *str) |
Character Classification | |
Define text.cc functions here (declared in BKE_text.h), This could be removed if Blender gets its own unicode library. | |
| int | text_check_identifier_unicode (const uint ch) |
| int | text_check_identifier_nodigit_unicode (const uint ch) |
Variables | |
| CLG_LogRef * | BKE_LOG_CONTEXT |
| static int | py_call_level = 0 |
| static bool | py_use_system_env = false |
| static _inittab | bpy_internal_modules [] |
This file deals with embedding the python interpreter within blender, starting and stopping python and exposing blender/python modules so they can be accesses from scripts.
Definition in file bpy_interface.cc.
| void bpy_context_clear | ( | struct bContext * | C, |
| const PyGILState_STATE * | gilstate ) |
Context should be used but not now because it causes some bugs.
Definition at line 141 of file bpy_interface.cc.
References BLI_time_now_seconds(), BPY_context_set(), and py_call_level.
Referenced by bpy_class_call(), bpy_cli_command_exec(), BPY_modules_load_user(), bpy_msgbus_notify(), bpy_prop_enum_itemf_fn(), bpy_prop_string_visit_for_search_fn(), bpy_prop_update_fn(), BPY_run_string_as_intptr(), BPY_run_string_as_number(), BPY_run_string_as_string_and_len(), BPY_run_string_as_string_and_len_or_none(), bpy_run_string_impl(), cb_region_draw(), cb_wm_cursor_draw(), and python_script_exec().
| void BPY_context_dict_clear_members_array | ( | void ** | dict_p, |
| void * | dict_orig, | ||
| const char * | context_members[], | ||
| uint | context_members_len ) |
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 see #66256.
| dict_p | A pointer to #bContext.data.py_context so we can assign a new value. |
| dict_orig | The value of #bContext.data.py_context_orig to check if we need to copy. |
Definition at line 174 of file bpy_interface.cc.
References BLI_assert, i, Py_DECREF(), and PyC_IsInterpreterActive().
Referenced by CTX_data_scene_set(), CTX_wm_area_set(), CTX_wm_region_set(), CTX_wm_screen_set(), and CTX_wm_window_set().
|
static |
Definition at line 166 of file bpy_interface.cc.
References C, CTX_wm_operator_poll_msg_clear(), and UNLIKELY.
Referenced by BPY_python_end().
| bContext * BPY_context_get | ( | ) |
Definition at line 258 of file bpy_interface.cc.
References bpy_context_module.
Referenced by bpy_atexit(), bpy_class_call(), bpy_gizmo_target_set_value(), bpy_lib_load(), bpy_msgbus_clear_by_owner(), bpy_msgbus_publish_rna(), bpy_msgbus_subscribe_rna(), BPY_python_end(), BPY_rna_operator_poll_message_set(), foreach_getset(), mathutils_rna_matrix_set(), mathutils_rna_vector_set(), mathutils_rna_vector_set_index(), pyop_as_string(), pyop_call(), pyop_poll(), pyrna_enum_as_string(), pyrna_enum_to_py(), pyrna_func_vectorcall(), pyrna_prop_array_ass_subscript(), pyrna_prop_to_enum_bitfield(), pyrna_prop_update(), pyrna_py_to_prop(), pyrna_py_to_prop_array_index(), pyrna_register_class(), pyrna_string_to_enum(), pyrna_struct_driver_add(), pyrna_struct_driver_remove(), pyrna_struct_keyframe_insert(), pyrna_struct_keyframe_parse(), and pyrna_unregister_class().
|
static |
Helper function for logging context member access errors with both CLI and Python support
Definition at line 778 of file bpy_interface.cc.
References BKE_LOG_CONTEXT, BLI_assert_unreachable, BPY_python_current_file_and_line(), C, CLG_LEVEL_INFO, CLOG_AT_LEVEL_NOCHECK, CLOG_CHECK, CLOG_INFO, and CTX_member_logging_get().
Referenced by BPY_context_member_get().
|
nodiscard |
Definition at line 800 of file bpy_interface.cc.
References bpy_context_log_member_error(), BPy_StructRNA_Check, C, Collection, CTX_data_list_add_ptr(), CTX_data_pointer_set_ptr(), CTX_data_type_set(), CTX_py_dict_get(), i, len, Pointer, ptr, Py_DECREF(), PyC_IsInterpreterActive(), and result.
Referenced by ctx_data_get(), and ctx_wm_python_context_get().
| void BPY_context_set | ( | bContext * | C | ) |
Definition at line 263 of file bpy_interface.cc.
References bpy_context_module, and C.
Referenced by bpy_context_clear(), and BPY_context_update().
| void bpy_context_set | ( | bContext * | C, |
| PyGILState_STATE * | gilstate ) |
Definition at line 117 of file bpy_interface.cc.
References BLI_time_now_seconds(), BPY_context_update(), C, and py_call_level.
Referenced by bpy_class_call(), bpy_cli_command_exec(), BPY_modules_load_user(), bpy_msgbus_notify(), bpy_prop_enum_itemf_fn(), bpy_prop_string_visit_for_search_fn(), bpy_prop_update_fn(), BPY_run_string_as_intptr(), BPY_run_string_as_number(), BPY_run_string_as_string_and_len(), BPY_run_string_as_string_and_len_or_none(), bpy_run_string_impl(), cb_region_draw(), cb_wm_cursor_draw(), and python_script_exec().
| void BPY_context_update | ( | bContext * | C | ) |
Use for updating while a python script runs - in case of file load.
Definition at line 102 of file bpy_interface.cc.
References BLI_thread_is_main(), BPY_context_set(), BPY_modules_update(), and C.
Referenced by bpy_context_set(), BPY_modules_load_user(), and setup_app_data().
| void BPY_DECREF | ( | void * | pyob_ptr | ) |
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.
Definition at line 714 of file bpy_interface.cc.
References Py_DECREF().
Referenced by fcurve_free_driver(), pyop_poll_message_free_fn(), and RNA_struct_free_extension().
| void BPY_DECREF_RNA_INVALIDATE | ( | void * | pyob_ptr | ) |
Definition at line 721 of file bpy_interface.cc.
References Py_DECREF(), and pyrna_invalidate().
Referenced by BKE_libblock_free_data_py(), RE_engine_free(), WM_gizmo_free(), wm_gizmogroup_free(), and WM_operator_free().
| void BPY_modules_load_user | ( | bContext * | C | ) |
Definition at line 732 of file bpy_interface.cc.
References BKE_main_blendfile_path(), bpy_context_clear(), bpy_context_set(), BPY_context_update(), BPY_run_text(), C, CTX_data_main(), ListBase::first, Text::flags, G, G_FLAG_SCRIPT_AUTOEXEC, G_FLAG_SCRIPT_AUTOEXEC_FAIL, G_FLAG_SCRIPT_AUTOEXEC_FAIL_QUIET, Text::id, ID::name, ID::next, printf, py_call_level, RPT_, SNPRINTF_UTF8, Main::texts, and TXT_ISSCRIPT.
Referenced by BPY_python_reset().
| void BPY_modules_update | ( | ) |
Needed so the Main pointer in bpy.data doesn't become out of date.
Definition at line 244 of file bpy_interface.cc.
References BPY_rna_module(), BPY_rna_types(), BPY_update_rna_module(), and mod.
Referenced by BPY_context_update(), and pyop_call().
| void BPY_python_backtrace | ( | FILE * | fp | ) |
Definition at line 693 of file bpy_interface.cc.
References PyThreadState_GetUnchecked.
Referenced by crashlog_file_generate().
|
nodiscard |
Get current Python stack location. Returns a string like filename.py:123 if available, #std::nullopt otherwise.
Definition at line 876 of file bpy_interface.cc.
References PyC_FileAndNum_Safe(), PyC_IsInterpreterActive(), and result.
Referenced by bpy_context_log_member_error(), and ctx_member_log_access().
| void BPY_python_end | ( | const bool | do_python_exit | ) |
Definition at line 607 of file bpy_interface.cc.
References BLI_assert_msg, BLI_time_now_seconds(), BPY_app_translations_end(), BPY_atexit_unregister(), bpy_context_end(), BPY_context_get(), BPY_driver_exit(), bpy_intern_string_exit(), BPY_rna_exit(), BPY_rna_props_clear_all(), printf, and RNA_bpy_exit().
Referenced by WM_exit_ex().
| void BPY_python_reset | ( | bContext * | C | ) |
Definition at line 669 of file bpy_interface.cc.
References BLI_assert_msg, BPY_app_handlers_reset(), BPY_driver_reset(), BPY_modules_load_user(), C, G, G_FLAG_SCRIPT_AUTOEXEC_FAIL, and G_FLAG_SCRIPT_AUTOEXEC_FAIL_QUIET.
Referenced by wm_file_read_post(), and WM_init().
| void BPY_python_start | ( | bContext * | C, |
| int | argc, | ||
| const char ** | argv ) |
Call BPY_context_set first.
Definition at line 345 of file bpy_interface.cc.
References BKE_appdir_folder_id(), BKE_appdir_program_path(), BKE_appdir_program_python_search(), BLENDER_SYSTEM_PYTHON, BLI_assert, BLI_assert_msg, BLI_getenv(), BLI_path_join, BLI_setenv(), BPY_atexit_register(), BPy_init_modules(), bpy_intern_string_init(), bpy_internal_modules, BPY_LOG_INTERFACE, BPY_rna_init(), BPY_run_string_eval(), C, CLOG_DEBUG, FILE_MAX, G, G_DEBUG_PYTHON, L, mod, Py_DECREF(), py_use_system_env, pyrna_alloc_types(), pystatus_exit_on_error(), and status.
Referenced by WM_init().
| void BPY_python_use_system_env | ( | ) |
Definition at line 682 of file bpy_interface.cc.
References BLI_assert, and py_use_system_env.
Referenced by arg_handle_python_use_system_env_set().
|
nodiscard |
Definition at line 688 of file bpy_interface.cc.
References py_use_system_env.
Referenced by bpy_app_python_args_get().
|
nodiscard |
Avoids duplicating keyword list.
Definition at line 1135 of file bpy_interface.cc.
Referenced by driver_variable_name_validate().
| void BPY_text_free_code | ( | Text * | text | ) |
Definition at line 225 of file bpy_interface.cc.
References Text::compiled, Py_DECREF(), and PyC_IsInterpreterActive().
Referenced by text_free_data(), text_reload_exec(), and txt_make_dirty().
| CLG_LOGREF_DECLARE_GLOBAL | ( | BPY_LOG_INTERFACE | , |
| "bpy.interface" | ) |
References BPY_LOG_INTERFACE.
| CLG_LOGREF_DECLARE_GLOBAL | ( | BPY_LOG_RNA | , |
| "bpy.rna" | ) |
References BKE_LOG_CONTEXT, and BPY_LOG_RNA.
|
static |
Convenience function for BPY_python_start.
These should happen so rarely that having comprehensive errors isn't needed. For example if sys.argv fails to allocate memory.
Show an error just to avoid silent failure in the unlikely event something goes wrong, in this case a developer will need to track down the root cause.
Definition at line 335 of file bpy_interface.cc.
References status, and UNLIKELY.
Referenced by BPY_python_start().
| int text_check_identifier_nodigit_unicode | ( | const uint | ch | ) |
Definition at line 1166 of file bpy_interface.cc.
References text_check_identifier_nodigit(), and text_check_identifier_nodigit().
Referenced by text_autocomplete_build(), and txt_calc_tab_right().
| int text_check_identifier_unicode | ( | const uint | ch | ) |
Definition at line 1161 of file bpy_interface.cc.
References text_check_identifier(), and text_check_identifier().
Referenced by text_autocomplete_build(), and txt_calc_tab_right().
|
extern |
|
static |
Definition at line 291 of file bpy_interface.cc.
Referenced by BPY_python_start().
|
static |
Definition at line 84 of file bpy_interface.cc.
Referenced by bpy_context_clear(), bpy_context_set(), and BPY_modules_load_user().
|
static |
Definition at line 87 of file bpy_interface.cc.
Referenced by BPY_python_start(), BPY_python_use_system_env(), and BPY_python_use_system_env_get().