From d09289ff7a8e8fe6d4da6b46dd153033d7cfd426 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 15 May 2019 12:20:13 +1000 Subject: Cleanup: de-duplicate active tool panel --- .../startup/bl_ui/space_toolsystem_common.py | 29 +++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'release/scripts/startup/bl_ui/space_toolsystem_common.py') diff --git a/release/scripts/startup/bl_ui/space_toolsystem_common.py b/release/scripts/startup/bl_ui/space_toolsystem_common.py index 71354f9875d..4e7b5ea22d8 100644 --- a/release/scripts/startup/bl_ui/space_toolsystem_common.py +++ b/release/scripts/startup/bl_ui/space_toolsystem_common.py @@ -147,6 +147,25 @@ ToolDef.from_fn = from_fn del from_dict, from_fn, with_args +class ToolActivePanelHelper: + # Sub-class must define. + # bl_space_type = 'VIEW_3D' + # bl_region_type = 'UI' + bl_label = "Active Tool" + # bl_category = "Tool" + + def draw(self, context): + layout = self.layout + layout.use_property_split = True + layout.use_property_decorate = False + ToolSelectPanelHelper.draw_active_tool_header( + context, + layout, + show_tool_name=True, + tool_key=ToolSelectPanelHelper._tool_key_from_context(context, space_type=self.bl_space_type), + ) + + class ToolSelectPanelHelper: """ Generic Class, can be used for any toolbar. @@ -544,12 +563,16 @@ class ToolSelectPanelHelper: self.draw_cls(self.layout, context) @staticmethod - def _tool_key_from_context(context): - space_data = context.space_data - space_type = space_data.type + def _tool_key_from_context(context, *, space_type=None): + if space_type is None: + space_data = context.space_data + space_type = space_data.type + if space_type == 'VIEW_3D': return space_type, context.mode elif space_type == 'IMAGE_EDITOR': + if space_type is None: + space_data = context.space_data return space_type, space_data.mode elif space_type == 'NODE_EDITOR': return space_type, None -- cgit v1.2.3