[Bf-blender-cvs] [f9a266a2262] master: UI: support passing a function to WorkSpace.status_text_set()

Campbell Barton noreply at git.blender.org
Tue Oct 8 05:35:26 CEST 2019


Commit: f9a266a22629afee11a5b9abd04a28dcc1cdc277
Author: Campbell Barton
Date:   Tue Oct 8 14:21:41 2019 +1100
Branches: master
https://developer.blender.org/rBf9a266a22629afee11a5b9abd04a28dcc1cdc277

UI: support passing a function to WorkSpace.status_text_set()

This allows Python operators to draw icons and other UI elements
into the status bar.

===================================================================

M	release/scripts/modules/bpy_types.py
M	source/blender/makesrna/intern/rna_workspace_api.c

===================================================================

diff --git a/release/scripts/modules/bpy_types.py b/release/scripts/modules/bpy_types.py
index 29470895079..1a2eb12cd9f 100644
--- a/release/scripts/modules/bpy_types.py
+++ b/release/scripts/modules/bpy_types.py
@@ -184,6 +184,27 @@ class WindowManager(bpy_types.ID):
                 self.piemenu_end__internal(pie)
 
 
+class WorkSpace(bpy_types.ID):
+    __slots__ = ()
+
+    def status_text_set(self, text):
+        """
+        Set the status text or None to clear,
+        When text is a function, this will be called with the (header, context) arguments.
+        """
+        from bl_ui.space_statusbar import STATUSBAR_HT_header
+        draw_fn = getattr(STATUSBAR_HT_header, "_draw_orig", None)
+        if draw_fn is None:
+            draw_fn = STATUSBAR_HT_header._draw_orig = STATUSBAR_HT_header.draw
+
+        if not (text is None or isinstance(text, str)):
+            draw_fn = text
+            text = None
+
+        self.status_text_set_internal(text)
+        STATUSBAR_HT_header.draw = draw_fn
+
+
 class _GenericBone:
     """
     functions for bones, common between Armature/Pose/Edit bones.
diff --git a/source/blender/makesrna/intern/rna_workspace_api.c b/source/blender/makesrna/intern/rna_workspace_api.c
index b8c6a25ace8..f22c86b3ff2 100644
--- a/source/blender/makesrna/intern/rna_workspace_api.c
+++ b/source/blender/makesrna/intern/rna_workspace_api.c
@@ -110,7 +110,7 @@ void RNA_api_workspace(StructRNA *srna)
   FunctionRNA *func;
   PropertyRNA *parm;
 
-  func = RNA_def_function(srna, "status_text_set", "ED_workspace_status_text");
+  func = RNA_def_function(srna, "status_text_set_internal", "ED_workspace_status_text");
   RNA_def_function_flag(func, FUNC_NO_SELF | FUNC_USE_CONTEXT);
   RNA_def_function_ui_description(
       func, "Set the status bar text, typically key shortcuts for modal operators");



More information about the Bf-blender-cvs mailing list