Support name-spaced add-ons, exposed via user configurable extension
repositories.
Directories for add-ons can be added at run-time and are name-spaced to
avoid name-collisions with Python modules or add-ons from other
repositories.
This is exposed as an experimental feature "Extension Repositories".
Details:
- A `bUserExtensionRepo` type which represents a repository which is
listed in the add-ons repository.
- `JunctionModuleHandle` class to manage a package with sub-modules
which can point to arbitrary locations.
- `bpy.app.handlers._extension_repos_update_{pre/post}` internal
callbacks run before/after changes to extension repositories,
callbacks are used to sync the changes to the Python package that
exposes these to add-ons.
- The size of an add-on name has been increased so a user-defined package
prefix can be included without enforcing shorter add-on names.
- Functionality relating to package management has been left out of this
change and will be developed separately.
Further work:
- While a repository can be renamed, enabled add-ons aren't renamed.
Eventually we might want to support this although we could also
disallow renaming repositories with add-ons enabled as the name isn't
all that significant.
- Removing a repository should remove all the add-ons located in this
repository.
- Sub-module names are currently restricted to `[A-Za-z]+[A-Za-z0-9_]*`
we might want to relax this to allow unicode characters (we might
still want to disallow `-` or any characters that would prevent
attribute access in code).
Ref !110869.
Reviewed By: brecht
147 lines
4.5 KiB
C
147 lines
4.5 KiB
C
/* SPDX-FileCopyrightText: 2023 Blender Foundation
|
|
*
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
|
|
/** \file
|
|
* \ingroup bke
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
struct Depsgraph;
|
|
struct ID;
|
|
struct Main;
|
|
struct PointerRNA;
|
|
|
|
/**
|
|
* Callbacks for One Off Actions
|
|
* =============================
|
|
*
|
|
* - `{ACTION}` use in cases where only a single callback is required,
|
|
* `VERSION_UPDATE` and `RENDER_STATS` for example.
|
|
*
|
|
* \note avoid single callbacks if there is a chance `PRE/POST` are useful to differentiate
|
|
* since renaming callbacks may break Python scripts.
|
|
*
|
|
* Callbacks for Common Actions
|
|
* ============================
|
|
*
|
|
* - `{ACTION}_PRE` run before the action.
|
|
* - `{ACTION}_POST` run after the action.
|
|
*
|
|
* Optional Additional Callbacks
|
|
* -----------------------------
|
|
*
|
|
* - `{ACTION}_INIT` when the handler may manipulate the context used to run the action.
|
|
*
|
|
* Examples where `INIT` functions may be useful are:
|
|
*
|
|
* - When rendering, an `INIT` function may change the camera or render settings,
|
|
* things which a `PRE` function can't support as this information has already been used.
|
|
* - When saving an `INIT` function could temporarily change the preferences.
|
|
*
|
|
* - `{ACTION}_POST_FAIL` should be included if the action may fail.
|
|
*
|
|
* Use this so a call to the `PRE` callback always has a matching call to `POST` or `POST_FAIL`.
|
|
*
|
|
* \note in most cases only `PRE/POST` are required.
|
|
*
|
|
* Callbacks for Background/Modal Tasks
|
|
* ====================================
|
|
*
|
|
* - `{ACTION}_INIT`
|
|
* - `{ACTION}_COMPLETE` when a background job has finished.
|
|
* - `{ACTION}_CANCEL` When a background job is canceled partway through.
|
|
*
|
|
* While cancellation may be caused by any number of reasons, common causes may include:
|
|
*
|
|
* - Explicit user cancellation.
|
|
* - Exiting Blender.
|
|
* - Failure to acquire resources (such as disk-full, out of memory ... etc).
|
|
*
|
|
* \note `PRE/POST` handlers may be used along side modal task handlers
|
|
* as is the case for rendering, where rendering an animation uses modal task handlers,
|
|
* rendering a single frame has `PRE/POST` handlers.
|
|
*
|
|
* Python Access
|
|
* =============
|
|
*
|
|
* All callbacks here must be exposed via the Python module `bpy.app.handlers`,
|
|
* see `bpy_app_handlers.cc`.
|
|
*/
|
|
typedef enum {
|
|
BKE_CB_EVT_FRAME_CHANGE_PRE,
|
|
BKE_CB_EVT_FRAME_CHANGE_POST,
|
|
BKE_CB_EVT_RENDER_PRE,
|
|
BKE_CB_EVT_RENDER_POST,
|
|
BKE_CB_EVT_RENDER_WRITE,
|
|
BKE_CB_EVT_RENDER_STATS,
|
|
BKE_CB_EVT_RENDER_INIT,
|
|
BKE_CB_EVT_RENDER_COMPLETE,
|
|
BKE_CB_EVT_RENDER_CANCEL,
|
|
BKE_CB_EVT_LOAD_PRE,
|
|
BKE_CB_EVT_LOAD_POST,
|
|
BKE_CB_EVT_LOAD_POST_FAIL,
|
|
BKE_CB_EVT_SAVE_PRE,
|
|
BKE_CB_EVT_SAVE_POST,
|
|
BKE_CB_EVT_SAVE_POST_FAIL,
|
|
BKE_CB_EVT_UNDO_PRE,
|
|
BKE_CB_EVT_UNDO_POST,
|
|
BKE_CB_EVT_REDO_PRE,
|
|
BKE_CB_EVT_REDO_POST,
|
|
BKE_CB_EVT_DEPSGRAPH_UPDATE_PRE,
|
|
BKE_CB_EVT_DEPSGRAPH_UPDATE_POST,
|
|
BKE_CB_EVT_VERSION_UPDATE,
|
|
BKE_CB_EVT_LOAD_FACTORY_USERDEF_POST,
|
|
BKE_CB_EVT_LOAD_FACTORY_STARTUP_POST,
|
|
BKE_CB_EVT_XR_SESSION_START_PRE,
|
|
BKE_CB_EVT_ANNOTATION_PRE,
|
|
BKE_CB_EVT_ANNOTATION_POST,
|
|
BKE_CB_EVT_OBJECT_BAKE_PRE,
|
|
BKE_CB_EVT_OBJECT_BAKE_COMPLETE,
|
|
BKE_CB_EVT_OBJECT_BAKE_CANCEL,
|
|
BKE_CB_EVT_COMPOSITE_PRE,
|
|
BKE_CB_EVT_COMPOSITE_POST,
|
|
BKE_CB_EVT_COMPOSITE_CANCEL,
|
|
BKE_CB_EVT_ANIMATION_PLAYBACK_PRE,
|
|
BKE_CB_EVT_ANIMATION_PLAYBACK_POST,
|
|
BKE_CB_EVT_EXTENSION_REPOS_UPDATE_PRE,
|
|
BKE_CB_EVT_EXTENSION_REPOS_UPDATE_POST,
|
|
BKE_CB_EVT_TOT,
|
|
} eCbEvent;
|
|
|
|
typedef struct bCallbackFuncStore {
|
|
struct bCallbackFuncStore *next, *prev;
|
|
void (*func)(struct Main *, struct PointerRNA **, int num_pointers, void *arg);
|
|
void *arg;
|
|
short alloc;
|
|
} bCallbackFuncStore;
|
|
|
|
void BKE_callback_exec(struct Main *bmain,
|
|
struct PointerRNA **pointers,
|
|
int num_pointers,
|
|
eCbEvent evt);
|
|
void BKE_callback_exec_null(struct Main *bmain, eCbEvent evt);
|
|
void BKE_callback_exec_id(struct Main *bmain, struct ID *id, eCbEvent evt);
|
|
void BKE_callback_exec_id_depsgraph(struct Main *bmain,
|
|
struct ID *id,
|
|
struct Depsgraph *depsgraph,
|
|
eCbEvent evt);
|
|
void BKE_callback_exec_string(struct Main *bmain, eCbEvent evt, const char *str);
|
|
void BKE_callback_add(bCallbackFuncStore *funcstore, eCbEvent evt);
|
|
void BKE_callback_remove(bCallbackFuncStore *funcstore, eCbEvent evt);
|
|
|
|
void BKE_callback_global_init(void);
|
|
/**
|
|
* Call on application exit.
|
|
*/
|
|
void BKE_callback_global_finalize(void);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|