[Bf-blender-cvs] [73f90b25055] blender2.8: Fix annotate tool in the 3D view

Campbell Barton noreply at git.blender.org
Thu Aug 23 12:21:48 CEST 2018


Commit: 73f90b250551566c576588ed4fae88d6ad9d1162
Author: Campbell Barton
Date:   Thu Aug 23 20:25:25 2018 +1000
Branches: blender2.8
https://developer.blender.org/rB73f90b250551566c576588ed4fae88d6ad9d1162

Fix annotate tool in the 3D view

We can't share tools between space-types since they contain keymaps
that store the space type.

===================================================================

M	release/scripts/startup/bl_ui/space_toolsystem_toolbar.py

===================================================================

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,
     )



More information about the Bf-blender-cvs mailing list