Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorAntonio Vazquez <blendergit@gmail.com>2022-03-07 14:31:36 +0300
committerAntonio Vazquez <blendergit@gmail.com>2022-03-07 14:36:47 +0300
commit4ffe2fec169c67655aad6a866be3a949b4062108 (patch)
tree347e8052ee29561beb70225e65499911df8d494a /source
parent548eabbaa14fb6bcdc927333b7d912eea0c61a59 (diff)
Python: Add new `annotation_pre` & `annotation_post` handlers
Annotation tool is used as a general mark tool for many add-ons. To be able to detect when an annotation is done is very handy to integrate the annotation tool in add-ons and other studio workflows. The new callback names are: `annotation_pre` and `annotation_post` Both callbacks are exposed via the Python module `bpy.app.handlers` Example use: ``` import bpy def annotation_starts(gpd): print("Annotation starts") def annotation_done(gpd): print("Annotation done") bpy.app.handlers.annotation_pre.clear() bpy.app.handlers.annotation_pre.append(annotation_starts) bpy.app.handlers.annotation_post.clear() bpy.app.handlers.annotation_post.append(annotation_done) ``` Note: The handlers are called for any annotation tool, including eraser. Reviewed By: campbellbarton Differential Revision: https://developer.blender.org/D14221
Diffstat (limited to 'source')
-rw-r--r--source/blender/blenkernel/BKE_callbacks.h2
-rw-r--r--source/blender/editors/gpencil/annotate_paint.c7
-rw-r--r--source/blender/python/intern/bpy_app_handlers.c2
3 files changed, 11 insertions, 0 deletions
diff --git a/source/blender/blenkernel/BKE_callbacks.h b/source/blender/blenkernel/BKE_callbacks.h
index 66089d29c45..2cd28c4dfa5 100644
--- a/source/blender/blenkernel/BKE_callbacks.h
+++ b/source/blender/blenkernel/BKE_callbacks.h
@@ -95,6 +95,8 @@ typedef enum {
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_TOT,
} eCbEvent;
diff --git a/source/blender/editors/gpencil/annotate_paint.c b/source/blender/editors/gpencil/annotate_paint.c
index 1a7b034f2f8..b33b676c078 100644
--- a/source/blender/editors/gpencil/annotate_paint.c
+++ b/source/blender/editors/gpencil/annotate_paint.c
@@ -22,6 +22,7 @@
#include "PIL_time.h"
+#include "BKE_callbacks.h"
#include "BKE_colortools.h"
#include "BKE_context.h"
#include "BKE_global.h"
@@ -1509,6 +1510,9 @@ static void annotation_paint_initstroke(tGPsdata *p,
Scene *scene = p->scene;
ToolSettings *ts = scene->toolsettings;
+ /* Call to the annotation pre handler to notify python the annotation starts. */
+ BKE_callback_exec_id_depsgraph(p->bmain, &p->gpd->id, p->depsgraph, BKE_CB_EVT_ANNOTATION_PRE);
+
/* get active layer (or add a new one if non-existent) */
p->gpl = BKE_gpencil_layer_active_get(p->gpd);
if (p->gpl == NULL) {
@@ -1675,6 +1679,9 @@ static void annotation_paint_strokeend(tGPsdata *p)
annotation_stroke_newfrombuffer(p);
}
+ /* Call to the annotation post handler to notify python the annotation is done. */
+ BKE_callback_exec_id_depsgraph(p->bmain, &p->gpd->id, p->depsgraph, BKE_CB_EVT_ANNOTATION_POST);
+
/* clean up buffer now */
annotation_session_validatebuffer(p);
}
diff --git a/source/blender/python/intern/bpy_app_handlers.c b/source/blender/python/intern/bpy_app_handlers.c
index 3155f3a63bd..f2cf4249042 100644
--- a/source/blender/python/intern/bpy_app_handlers.c
+++ b/source/blender/python/intern/bpy_app_handlers.c
@@ -64,6 +64,8 @@ static PyStructSequence_Field app_cb_info_fields[] = {
{"load_factory_preferences_post", "on loading factory preferences (after)"},
{"load_factory_startup_post", "on loading factory startup (after)"},
{"xr_session_start_pre", "on starting an xr session (before)"},
+ {"annotation_pre", "on drawing an annotation (before)"},
+ {"annotation_post", "on drawing an annotation (after)"},
/* sets the permanent tag */
#define APP_CB_OTHER_FIELDS 1