diff options
author | Campbell Barton <ideasman42@gmail.com> | 2018-08-23 13:25:25 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2018-08-23 13:25:25 +0300 |
commit | 73f90b250551566c576588ed4fae88d6ad9d1162 (patch) | |
tree | 13a69135e70b2f2cd70e89b59a6be7f71770c454 /release/scripts/startup | |
parent | 32f3ecf70112e53ab4ff2770663976ad4e25cea6 (diff) |
Fix annotate tool in the 3D view
We can't share tools between space-types since they contain keymaps
that store the space type.
Diffstat (limited to 'release/scripts/startup')
-rw-r--r-- | release/scripts/startup/bl_ui/space_toolsystem_toolbar.py | 180 |
1 files changed, 93 insertions, 87 deletions
diff --git a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py index f8992094c43..8f7fec387ff 100644 --- a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py +++ b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py @@ -196,92 +196,98 @@ class _defs_view3d_generic: ), ) +def _defs_annotate_factory(): -class _defs_annotate: - @staticmethod - def draw_settings_common(context, layout, tool): - ts = context.tool_settings - - space_type = tool.space_type - if space_type == 'VIEW_3D': - layout.separator() - - row = layout.row(align=True) - row.prop(ts, "annotation_stroke_placement_view3d", text="Placement") - if ts.gpencil_stroke_placement_view3d == 'CURSOR': - row.prop(ts.gpencil_sculpt, "lockaxis") - elif ts.gpencil_stroke_placement_view3d in {'SURFACE', 'STROKE'}: - row.prop(ts, "use_gpencil_stroke_endpoints") - - @ToolDef.from_fn - def scribble(): - def draw_settings(context, layout, tool): - _defs_annotate.draw_settings_common(context, layout, tool) - - return dict( - text="Annotate", - icon="ops.gpencil.draw", - cursor='PAINT_BRUSH', - keymap=( - ("gpencil.annotate", - dict(mode='DRAW', wait_for_input=False), - dict(type='EVT_TWEAK_A', value='ANY')), - ), - draw_settings=draw_settings, - ) + class _defs_annotate: + @staticmethod + def draw_settings_common(context, layout, tool): + ts = context.tool_settings - @ToolDef.from_fn - def line(): - def draw_settings(context, layout, tool): - _defs_annotate.draw_settings_common(context, layout, tool) + space_type = tool.space_type + if space_type == 'VIEW_3D': + layout.separator() - return dict( - text="Draw Line", - icon="ops.gpencil.draw.line", - cursor='CROSSHAIR', - keymap=( - ("gpencil.annotate", - dict(mode='DRAW_STRAIGHT', wait_for_input=False), - dict(type='EVT_TWEAK_A', value='ANY')), - ), - draw_settings=draw_settings, - ) + row = layout.row(align=True) + row.prop(ts, "annotation_stroke_placement_view3d", text="Placement") + if ts.gpencil_stroke_placement_view3d == 'CURSOR': + row.prop(ts.gpencil_sculpt, "lockaxis") + elif ts.gpencil_stroke_placement_view3d in {'SURFACE', 'STROKE'}: + row.prop(ts, "use_gpencil_stroke_endpoints") + + @ToolDef.from_fn + def scribble(): + def draw_settings(context, layout, tool): + _defs_annotate.draw_settings_common(context, layout, tool) + + return dict( + text="Annotate", + icon="ops.gpencil.draw", + cursor='PAINT_BRUSH', + keymap=( + ("gpencil.annotate", + dict(mode='DRAW', wait_for_input=False), + dict(type='EVT_TWEAK_A', value='ANY')), + ), + draw_settings=draw_settings, + ) - @ToolDef.from_fn - def poly(): - def draw_settings(context, layout, tool): - _defs_annotate.draw_settings_common(context, layout, tool) + @ToolDef.from_fn + def line(): + def draw_settings(context, layout, tool): + _defs_annotate.draw_settings_common(context, layout, tool) + + return dict( + text="Draw Line", + icon="ops.gpencil.draw.line", + cursor='CROSSHAIR', + keymap=( + ("gpencil.annotate", + dict(mode='DRAW_STRAIGHT', wait_for_input=False), + dict(type='EVT_TWEAK_A', value='ANY')), + ), + draw_settings=draw_settings, + ) - return dict( - text="Draw Polygon", - icon="ops.gpencil.draw.poly", - cursor='CROSSHAIR', - keymap=( - ("gpencil.annotate", - dict(mode='DRAW_POLY', wait_for_input=False), - dict(type='ACTIONMOUSE', value='PRESS')), - ), - draw_settings=draw_settings, - ) + @ToolDef.from_fn + def poly(): + def draw_settings(context, layout, tool): + _defs_annotate.draw_settings_common(context, layout, tool) + + return dict( + text="Draw Polygon", + icon="ops.gpencil.draw.poly", + cursor='CROSSHAIR', + keymap=( + ("gpencil.annotate", + dict(mode='DRAW_POLY', wait_for_input=False), + dict(type='ACTIONMOUSE', value='PRESS')), + ), + draw_settings=draw_settings, + ) - @ToolDef.from_fn - def eraser(): - def draw_settings(context, layout, tool): - # TODO: Move this setting to toolsettings - user_prefs = context.user_preferences - layout.prop(user_prefs.edit, "grease_pencil_eraser_radius", text="Radius") + @ToolDef.from_fn + def eraser(): + def draw_settings(context, layout, tool): + # TODO: Move this setting to toolsettings + user_prefs = context.user_preferences + layout.prop(user_prefs.edit, "grease_pencil_eraser_radius", text="Radius") + + return dict( + text="Eraser", + icon="ops.gpencil.draw.eraser", + cursor='CROSSHAIR', # XXX: Always show brush circle when enabled + keymap=( + ("gpencil.annotate", + dict(mode='ERASER', wait_for_input=False), + dict(type='ACTIONMOUSE', value='PRESS')), + ), + draw_settings=draw_settings, + ) + return _defs_annotate - return dict( - text="Eraser", - icon="ops.gpencil.draw.eraser", - cursor='CROSSHAIR', # XXX: Always show brush circle when enabled - keymap=( - ("gpencil.annotate", - dict(mode='ERASER', wait_for_input=False), - dict(type='ACTIONMOUSE', value='PRESS')), - ), - draw_settings=draw_settings, - ) +# Needed so annotation gets a keymap per space type. +_defs_annotate_image = _defs_annotate_factory() +_defs_annotate_view3d = _defs_annotate_factory() class _defs_transform: @@ -1473,10 +1479,10 @@ class IMAGE_PT_tools_active(ToolSelectPanelHelper, Panel): _tools_annotate = ( ( - _defs_annotate.scribble, - _defs_annotate.line, - _defs_annotate.poly, - _defs_annotate.eraser, + _defs_annotate_image.scribble, + _defs_annotate_image.line, + _defs_annotate_image.poly, + _defs_annotate_image.eraser, ), ) @@ -1543,10 +1549,10 @@ class VIEW3D_PT_tools_active(ToolSelectPanelHelper, Panel): _tools_annotate = ( ( - _defs_annotate.scribble, - _defs_annotate.line, - _defs_annotate.poly, - _defs_annotate.eraser, + _defs_annotate_view3d.scribble, + _defs_annotate_view3d.line, + _defs_annotate_view3d.poly, + _defs_annotate_view3d.eraser, ), _defs_view3d_generic.ruler, ) |