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
diff options
context:
space:
mode:
authorSybren A. Stüvel <sybren@blender.org>2022-06-02 12:20:17 +0300
committerSybren A. Stüvel <sybren@blender.org>2022-06-02 12:20:17 +0300
commitf4456a4d3c9767da76041bfa48e623cf6afa59ce (patch)
tree6d489e1244cd6024ac3f9e53d850548e73e51824 /source/blender/makesrna/intern/rna_wm.c
parent40ecf9d606358d773bfe977e6bc85580e5818cc6 (diff)
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
Diffstat (limited to 'source/blender/makesrna/intern/rna_wm.c')
-rw-r--r--source/blender/makesrna/intern/rna_wm.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/source/blender/makesrna/intern/rna_wm.c b/source/blender/makesrna/intern/rna_wm.c
index 1dc2cbe9e69..92be6310716 100644
--- a/source/blender/makesrna/intern/rna_wm.c
+++ b/source/blender/makesrna/intern/rna_wm.c
@@ -24,6 +24,7 @@
#include "rna_internal.h"
+#include "WM_api.h"
#include "WM_types.h"
#ifdef RNA_RUNTIME
@@ -123,6 +124,22 @@ static const EnumPropertyItem event_ndof_type_items[] = {
};
#endif /* RNA_RUNTIME */
+/**
+ * Job types for use in the `bpy.app.is_job_running(job_type)` call.
+ *
+ * This is a subset of the `WM_JOB_TYPE_...` anonymous enum defined in `WM_api.h`. It is
+ * intentionally kept as a subset, such that by default how jobs are handled is kept as an
+ * "internal implementation detail" of Blender, rather than a public, reliable part of the API.
+ *
+ * This array can be expanded on a case-by-case basis, when there is a clear and testable use case.
+ */
+const EnumPropertyItem rna_enum_wm_job_type_items[] = {
+ {WM_JOB_TYPE_RENDER, "RENDER", 0, "Regular rendering", ""},
+ {WM_JOB_TYPE_RENDER_PREVIEW, "RENDER_PREVIEW", 0, "Rendering previews", ""},
+ {WM_JOB_TYPE_OBJECT_BAKE, "OBJECT_BAKE", 0, "Object Baking", ""},
+ {0, NULL, 0, NULL, NULL},
+};
+
const EnumPropertyItem rna_enum_event_type_items[] = {
/* - Note we abuse 'tooltip' message here to store a 'compact' form of some (too) long names.
* - Intentionally excluded: #CAPSLOCKKEY, #UNKNOWNKEY.