diff options
author | Campbell Barton <ideasman42@gmail.com> | 2018-11-28 15:52:05 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2018-11-28 15:53:27 +0300 |
commit | 1a8d9988689fe2742c590438a4c844dcb1e584bc (patch) | |
tree | 790758b1550585a30f371ae2afb06741c8c079aa /release/scripts/startup/bl_ui/space_toolsystem_common.py | |
parent | 43248164a43fcb7e383854da5afc8b1637b54969 (diff) |
Tool System: support for dynamic tooltips
Tools can define a function that generates the tooltip using a function,
this takes the tools keymap as an argument which can be used
to extract keys to include in the tip.
Diffstat (limited to 'release/scripts/startup/bl_ui/space_toolsystem_common.py')
-rw-r--r-- | release/scripts/startup/bl_ui/space_toolsystem_common.py | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/release/scripts/startup/bl_ui/space_toolsystem_common.py b/release/scripts/startup/bl_ui/space_toolsystem_common.py index 9349f776c99..a52b9d07c2a 100644 --- a/release/scripts/startup/bl_ui/space_toolsystem_common.py +++ b/release/scripts/startup/bl_ui/space_toolsystem_common.py @@ -64,7 +64,8 @@ ToolDef = namedtuple( ( # The name to display in the interface. "text", - # Description (for tooltip), when not set, use the description of 'operator'. + # Description (for tooltip), when not set, use the description of 'operator', + # may be a string or a 'function(context, item, keymap) -> string'. "description", # The name of the icon to use (found in ``release/datafiles/icons``) or None for no icon. "icon", @@ -685,17 +686,17 @@ def description_from_name(context, space_type, text, *, use_operator=True): # Custom description. description = item.description if description is not None: + if callable(description): + km = _keymap_from_item(context, item) + return description(context, item, km) return description # Extract from the operator. if use_operator: operator = item.operator - if operator is None: if item.keymap is not None: - wm = context.window_manager - keyconf = wm.keyconfigs.active - km = keyconf.keymaps.get(item.keymap[0]) + km = _keymap_from_item(context, item) if km is not None: for kmi in km.keymap_items: if kmi.active: @@ -721,6 +722,14 @@ def keymap_from_name(context, space_type, text): return "" +def _keymap_from_item(context, item): + if item.keymap is not None: + wm = context.window_manager + keyconf = wm.keyconfigs.active + return keyconf.keymaps.get(item.keymap[0]) + return None + + classes = ( WM_MT_toolsystem_submenu, ) |