diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-05-15 05:20:13 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-05-15 05:20:13 +0300 |
commit | d09289ff7a8e8fe6d4da6b46dd153033d7cfd426 (patch) | |
tree | 3c66fb599c3ffa9ee7449cc37b6fd190130c7bd6 | |
parent | 6eacb626e043a584b0ec6cf97902ed40464ad5d3 (diff) |
Cleanup: de-duplicate active tool panel
-rw-r--r-- | release/scripts/startup/bl_ui/space_image.py | 19 | ||||
-rw-r--r-- | release/scripts/startup/bl_ui/space_toolsystem_common.py | 29 | ||||
-rw-r--r-- | release/scripts/startup/bl_ui/space_topbar.py | 28 | ||||
-rw-r--r-- | release/scripts/startup/bl_ui/space_view3d.py | 25 |
4 files changed, 35 insertions, 66 deletions
diff --git a/release/scripts/startup/bl_ui/space_image.py b/release/scripts/startup/bl_ui/space_image.py index af357a8cc12..a3e8ae851f8 100644 --- a/release/scripts/startup/bl_ui/space_image.py +++ b/release/scripts/startup/bl_ui/space_image.py @@ -37,6 +37,10 @@ from .properties_paint_common import ( from .properties_grease_pencil_common import ( AnnotationDataPanel, ) +from .space_toolsystem_common import ( + ToolActivePanelHelper, +) + from bpy.app.translations import pgettext_iface as iface_ @@ -55,24 +59,11 @@ class BrushButtonsPanel(UnifiedPaintPanel): return tool_settings.brush -class IMAGE_PT_active_tool(Panel): +class IMAGE_PT_active_tool(ToolActivePanelHelper, Panel): bl_space_type = 'IMAGE_EDITOR' bl_region_type = 'UI' - bl_label = "Active Tool" bl_category = "Tool" - def draw(self, context): - layout = self.layout - - # Panel display of topbar tool settings. - # currently displays in tool settings, keep here since the same functionality is used for the topbar. - - layout.use_property_split = True - layout.use_property_decorate = False - - from .space_toolsystem_common import ToolSelectPanelHelper - ToolSelectPanelHelper.draw_active_tool_header(context, layout, show_tool_name=True) - class IMAGE_MT_view(Menu): bl_label = "View" 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 diff --git a/release/scripts/startup/bl_ui/space_topbar.py b/release/scripts/startup/bl_ui/space_topbar.py index 6da08a15db1..509c5bae355 100644 --- a/release/scripts/startup/bl_ui/space_topbar.py +++ b/release/scripts/startup/bl_ui/space_topbar.py @@ -608,33 +608,6 @@ class TOPBAR_MT_workspace_menu(Menu): props.direction = 'NEXT' -class TOPBAR_PT_active_tool(Panel): - bl_space_type = 'PROPERTIES' - bl_region_type = 'WINDOW' - bl_category = "" - bl_context = ".active_tool" # dot on purpose (access from tool settings) - bl_label = "Active Tool" - bl_options = {'HIDE_HEADER'} - - def draw(self, context): - layout = self.layout - tool_mode = context.mode - - # Panel display of topbar tool settings. - # currently displays in tool settings, keep here since the same functionality is used for the topbar. - - layout.use_property_split = True - layout.use_property_decorate = False - - from .space_toolsystem_common import ToolSelectPanelHelper - ToolSelectPanelHelper.draw_active_tool_header( - context, - layout, - show_tool_name=True, - tool_key=('VIEW_3D', tool_mode), - ) - - # Grease Pencil Object - Primitive curve class TOPBAR_PT_gpencil_primitive(Panel): bl_space_type = 'VIEW_3D' @@ -751,7 +724,6 @@ classes = ( TOPBAR_MT_render, TOPBAR_MT_window, TOPBAR_MT_help, - TOPBAR_PT_active_tool, TOPBAR_PT_gpencil_layers, TOPBAR_PT_gpencil_primitive, TOPBAR_PT_gpencil_fill, diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py index 66e6d0402c4..88a6f0b9b9a 100644 --- a/release/scripts/startup/bl_ui/space_view3d.py +++ b/release/scripts/startup/bl_ui/space_view3d.py @@ -31,6 +31,9 @@ from .properties_grease_pencil_common import ( AnnotationOnionSkin, GreasePencilMaterialsPanel, ) +from .space_toolsystem_common import ( + ToolActivePanelHelper, +) from bpy.app.translations import contexts as i18n_contexts @@ -4712,30 +4715,10 @@ class VIEW3D_MT_proportional_editing_falloff_pie(Menu): # ********** Panel ********** -class VIEW3D_PT_active_tool(Panel): +class VIEW3D_PT_active_tool(Panel, ToolActivePanelHelper): bl_space_type = 'VIEW_3D' bl_region_type = 'UI' - bl_label = "Active Tool" bl_category = "Tool" - # bl_context = ".active_tool" # dot on purpose (access from tool settings) - - def draw(self, context): - layout = self.layout - tool_mode = context.mode - - # Panel display of topbar tool settings. - # currently displays in tool settings, keep here since the same functionality is used for the topbar. - - layout.use_property_split = True - layout.use_property_decorate = False - - from .space_toolsystem_common import ToolSelectPanelHelper - ToolSelectPanelHelper.draw_active_tool_header( - context, - layout, - show_tool_name=True, - tool_key=('VIEW_3D', tool_mode), - ) class VIEW3D_PT_view3d_properties(Panel): |