[Bf-blender-cvs] [868c9ac408f] blender2.8: UI: show active tool in the topbar
Campbell Barton
noreply at git.blender.org
Fri Apr 27 10:51:39 CEST 2018
Commit: 868c9ac408f75634c75bf4bc0b17c87b79d7af73
Author: Campbell Barton
Date: Fri Apr 27 10:49:20 2018 +0200
Branches: blender2.8
https://developer.blender.org/rB868c9ac408f75634c75bf4bc0b17c87b79d7af73
UI: show active tool in the topbar
===================================================================
M release/scripts/startup/bl_ui/space_toolsystem_common.py
M release/scripts/startup/bl_ui/space_topbar.py
===================================================================
diff --git a/release/scripts/startup/bl_ui/space_toolsystem_common.py b/release/scripts/startup/bl_ui/space_toolsystem_common.py
index 0f9d9f7304d..c2ac5d7124f 100644
--- a/release/scripts/startup/bl_ui/space_toolsystem_common.py
+++ b/release/scripts/startup/bl_ui/space_toolsystem_common.py
@@ -283,6 +283,44 @@ class ToolSelectPanelHelper:
return (cls._tools[None], cls._tools.get(context.mode, ()))
+ @staticmethod
+ def _active_tool(context, with_icon=False):
+ """
+ Return the active Python tool definition and icon name.
+ """
+
+ workspace = context.workspace
+ space_type = workspace.tool_space_type
+ cls = next(
+ (cls for cls in ToolSelectPanelHelper.__subclasses__()
+ if cls.bl_space_type == space_type),
+ None
+ )
+ if cls is not None:
+ tool_def_active, index_active = ToolSelectPanelHelper._tool_vars_from_active_with_index(context)
+
+ context_mode = context.mode
+ for tool_items in cls.tools_from_context(context):
+ for item in cls._tools_flatten(tool_items):
+ tool_def, icon_name = cls._tool_vars_from_def(item, context_mode)
+ if (tool_def == tool_def_active):
+ if with_icon:
+ icon_value = ToolSelectPanelHelper._icon_value_from_icon_handle(icon_name)
+ else:
+ icon_value = 0
+ return (item, icon_value)
+ return None, 0
+
+ @staticmethod
+ def draw_active_tool_header(context, layout):
+ item, icon_value = ToolSelectPanelHelper._active_tool(context, with_icon=True)
+ if item is None:
+ layout.label("No Tool Found")
+ return
+ # Indent until we have better icon scaling.
+ layout.label(" " + item["text"], icon_value=icon_value)
+
+
# The purpose of this menu is to be a generic popup to select between tools
# in cases when a single tool allows to select alternative tools.
class WM_MT_toolsystem_submenu(Menu):
diff --git a/release/scripts/startup/bl_ui/space_topbar.py b/release/scripts/startup/bl_ui/space_topbar.py
index b6d88dc5a6e..816f87be687 100644
--- a/release/scripts/startup/bl_ui/space_topbar.py
+++ b/release/scripts/startup/bl_ui/space_topbar.py
@@ -114,12 +114,29 @@ class TOPBAR_HT_lower_bar(Header):
layout = self.layout
layer = context.view_layer
object = layer.objects.active
+
+ # Object Mode
+ # -----------
+
object_mode = 'OBJECT' if object is None else object.mode
act_mode_item = bpy.types.Object.bl_rna.properties['mode'].enum_items[object_mode]
layout.operator_menu_enum("object.mode_set", "mode", text=act_mode_item.name, icon=act_mode_item.icon)
mode = context.mode
+ layout.separator()
+
+ # Active Tool
+ # -----------
+
+ from .space_toolsystem_common import ToolSelectPanelHelper
+ ToolSelectPanelHelper.draw_active_tool_header(context, layout)
+
+ layout.separator()
+
+ # Object Mode Options
+ # -------------------
+
# Example of how toolsettings can be accessed as pop-overs.
# TODO(campbell): editing options should be after active tool options
More information about the Bf-blender-cvs
mailing list