[Bf-blender-cvs] [43248164a43] blender2.8: PyAPI: add KeyMapItem.to_string() method

Campbell Barton noreply at git.blender.org
Wed Nov 28 13:26:49 CET 2018


Commit: 43248164a43fcb7e383854da5afc8b1637b54969
Author: Campbell Barton
Date:   Wed Nov 28 23:24:10 2018 +1100
Branches: blender2.8
https://developer.blender.org/rB43248164a43fcb7e383854da5afc8b1637b54969

PyAPI: add KeyMapItem.to_string() method

Useful for generating dynamic tooltips that include shortcuts.

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

M	source/blender/makesrna/intern/rna_wm_api.c

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

diff --git a/source/blender/makesrna/intern/rna_wm_api.c b/source/blender/makesrna/intern/rna_wm_api.c
index ef8607018d7..95c7d1cadf4 100644
--- a/source/blender/makesrna/intern/rna_wm_api.c
+++ b/source/blender/makesrna/intern/rna_wm_api.c
@@ -41,6 +41,8 @@
 #include "DNA_space_types.h"
 #include "DNA_windowmanager_types.h"
 
+#include "UI_interface.h"
+
 #include "wm_cursors.h"
 
 #include "rna_internal.h"  /* own include */
@@ -73,6 +75,11 @@ const EnumPropertyItem rna_enum_window_cursor_items[] = {
 
 #include "WM_types.h"
 
+static void rna_KeyMapItem_to_string(wmKeyMapItem *kmi, bool compact, char *result)
+{
+	WM_keymap_item_to_string(kmi, compact, result, UI_MAX_SHORTCUT_STR);
+}
+
 static wmKeyMap *rna_keymap_active(wmKeyMap *km, bContext *C)
 {
 	wmWindowManager *wm = CTX_wm_manager(C);
@@ -830,6 +837,12 @@ void RNA_api_keymapitem(StructRNA *srna)
 	RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
 	parm = RNA_def_boolean(func, "result", 0, "Comparison result", "");
 	RNA_def_function_return(func, parm);
+
+	func = RNA_def_function(srna, "to_string", "rna_KeyMapItem_to_string");
+	RNA_def_boolean(func, "compact", false, "Compact", "");
+	parm = RNA_def_string(func, "result", NULL, UI_MAX_SHORTCUT_STR, "result", "");
+	RNA_def_parameter_flags(parm, PROP_THICK_WRAP, 0);
+	RNA_def_function_output(func, parm);
 }
 
 void RNA_api_keymapitems(StructRNA *srna)



More information about the Bf-blender-cvs mailing list