Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2018-11-27 09:33:52 +0300
committerCampbell Barton <ideasman42@gmail.com>2018-11-27 09:52:15 +0300
commit1f8360171cd80c0c1918486703926709cb5db7aa (patch)
tree25ce56039ec95d156c4eaddc4134d639f3b900c3 /release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
parenta58f0eea4f1e9b04e519e123eb656009cf718f9e (diff)
Keymap: share annotation tool keymaps between spaces
Not sharing caused duplication in the keymap and required a factory class generator. Simplify tool & keymap definitions by sharing them. It's highly unlikely we will ever want these to use different keys once they're set as the active tool.
Diffstat (limited to 'release/scripts/startup/bl_ui/space_toolsystem_toolbar.py')
-rw-r--r--release/scripts/startup/bl_ui/space_toolsystem_toolbar.py179
1 files changed, 85 insertions, 94 deletions
diff --git a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
index 66cadb635d1..1f2b4ca47ee 100644
--- a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
@@ -108,99 +108,90 @@ class _defs_view3d_generic:
)
-def _defs_annotate_factory():
-
- class _defs_annotate:
-
- def draw_settings_common(context, layout, tool):
- if type(context.gpencil_data_owner) is bpy.types.Object:
- gpd = context.scene.grease_pencil
+class _defs_annotate:
+
+ def draw_settings_common(context, layout, tool):
+ if type(context.gpencil_data_owner) is bpy.types.Object:
+ gpd = context.scene.grease_pencil
+ else:
+ gpd = context.gpencil_data
+
+ if gpd is not None:
+ if gpd.layers.active_note is not None:
+ text = gpd.layers.active_note
+ maxw = 25
+ if len(text) > maxw:
+ text = text[:maxw - 5] + '..' + text[-3:]
else:
- gpd = context.gpencil_data
-
- if gpd is not None:
- if gpd.layers.active_note is not None:
- text = gpd.layers.active_note
- maxw = 25
- if len(text) > maxw:
- text = text[:maxw - 5] + '..' + text[-3:]
- else:
- text = ""
-
- layout.label(text="Annotation:")
- gpl = context.active_gpencil_layer
- if gpl is not None:
- sub = layout.row(align=True)
- sub.ui_units_x = 8
-
- sub.prop(gpl, "color", text="")
- sub.popover(
- panel="TOPBAR_PT_annotation_layers",
- text=text,
- )
-
- tool_settings = context.tool_settings
- space_type = tool.space_type
- if space_type == 'VIEW_3D':
- layout.separator()
-
- row = layout.row(align=True)
- row.prop(tool_settings, "annotation_stroke_placement_view3d", text="Placement")
- if tool_settings.gpencil_stroke_placement_view3d == 'CURSOR':
- row.prop(tool_settings.gpencil_sculpt, "lockaxis")
- elif tool_settings.gpencil_stroke_placement_view3d in {'SURFACE', 'STROKE'}:
- row.prop(tool_settings, "use_gpencil_stroke_endpoints")
-
- @ToolDef.from_fn.with_args(draw_settings=draw_settings_common)
- def scribble(*, draw_settings):
- return dict(
- text="Annotate",
- icon="ops.gpencil.draw",
- cursor='PAINT_BRUSH',
- keymap=(),
- draw_settings=draw_settings,
- )
+ text = ""
+
+ layout.label(text="Annotation:")
+ gpl = context.active_gpencil_layer
+ if gpl is not None:
+ sub = layout.row(align=True)
+ sub.ui_units_x = 8
+
+ sub.prop(gpl, "color", text="")
+ sub.popover(
+ panel="TOPBAR_PT_annotation_layers",
+ text=text,
+ )
- @ToolDef.from_fn.with_args(draw_settings=draw_settings_common)
- def line(*, draw_settings):
- return dict(
- text="Annotate Line",
- icon="ops.gpencil.draw.line",
- cursor='CROSSHAIR',
- keymap=(),
- draw_settings=draw_settings,
- )
+ tool_settings = context.tool_settings
+ space_type = tool.space_type
+ if space_type == 'VIEW_3D':
+ layout.separator()
- @ToolDef.from_fn.with_args(draw_settings=draw_settings_common)
- def poly(*, draw_settings):
- return dict(
- text="Annotate Polygon",
- icon="ops.gpencil.draw.poly",
- cursor='CROSSHAIR',
- keymap=(),
- draw_settings=draw_settings,
- )
+ row = layout.row(align=True)
+ row.prop(tool_settings, "annotation_stroke_placement_view3d", text="Placement")
+ if tool_settings.gpencil_stroke_placement_view3d == 'CURSOR':
+ row.prop(tool_settings.gpencil_sculpt, "lockaxis")
+ elif tool_settings.gpencil_stroke_placement_view3d in {'SURFACE', 'STROKE'}:
+ row.prop(tool_settings, "use_gpencil_stroke_endpoints")
- @ToolDef.from_fn
- def eraser():
- def draw_settings(context, layout, tool):
- # TODO: Move this setting to tool_settings
- user_prefs = context.user_preferences
- layout.prop(user_prefs.edit, "grease_pencil_eraser_radius", text="Radius")
- return dict(
- text="Annotate Eraser",
- icon="ops.gpencil.draw.eraser",
- cursor='CROSSHAIR', # XXX: Always show brush circle when enabled
- keymap=(),
- draw_settings=draw_settings,
- )
+ @ToolDef.from_fn.with_args(draw_settings=draw_settings_common)
+ def scribble(*, draw_settings):
+ return dict(
+ text="Annotate",
+ icon="ops.gpencil.draw",
+ cursor='PAINT_BRUSH',
+ keymap="Generic Tool: Annotate",
+ draw_settings=draw_settings,
+ )
- return _defs_annotate
+ @ToolDef.from_fn.with_args(draw_settings=draw_settings_common)
+ def line(*, draw_settings):
+ return dict(
+ text="Annotate Line",
+ icon="ops.gpencil.draw.line",
+ cursor='CROSSHAIR',
+ keymap="Generic Tool: Annotate Line",
+ draw_settings=draw_settings,
+ )
+ @ToolDef.from_fn.with_args(draw_settings=draw_settings_common)
+ def poly(*, draw_settings):
+ return dict(
+ text="Annotate Polygon",
+ icon="ops.gpencil.draw.poly",
+ cursor='CROSSHAIR',
+ keymap="Generic Tool: Annotate Polygon",
+ 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()
+ @ToolDef.from_fn
+ def eraser():
+ def draw_settings(context, layout, tool):
+ # TODO: Move this setting to tool_settings
+ user_prefs = context.user_preferences
+ layout.prop(user_prefs.edit, "grease_pencil_eraser_radius", text="Radius")
+ return dict(
+ text="Annotate Eraser",
+ icon="ops.gpencil.draw.eraser",
+ cursor='CROSSHAIR', # XXX: Always show brush circle when enabled
+ keymap="Generic Tool: Annotate Eraser",
+ draw_settings=draw_settings,
+ )
class _defs_transform:
@@ -1216,10 +1207,10 @@ class IMAGE_PT_tools_active(ToolSelectPanelHelper, Panel):
_tools_annotate = (
(
- _defs_annotate_image.scribble,
- _defs_annotate_image.line,
- _defs_annotate_image.poly,
- _defs_annotate_image.eraser,
+ _defs_annotate.scribble,
+ _defs_annotate.line,
+ _defs_annotate.poly,
+ _defs_annotate.eraser,
),
)
@@ -1298,10 +1289,10 @@ class VIEW3D_PT_tools_active(ToolSelectPanelHelper, Panel):
_tools_annotate = (
(
- _defs_annotate_view3d.scribble,
- _defs_annotate_view3d.line,
- _defs_annotate_view3d.poly,
- _defs_annotate_view3d.eraser,
+ _defs_annotate.scribble,
+ _defs_annotate.line,
+ _defs_annotate.poly,
+ _defs_annotate.eraser,
),
_defs_view3d_generic.ruler,
)