Tool System: add paint brush shortcut

This commit is contained in:
Campbell Barton
2018-09-03 23:12:53 +10:00
parent 0a26c122ed
commit e152483a32
2 changed files with 84 additions and 3 deletions

View File

@@ -734,6 +734,9 @@ def keymap_from_context(context, space_type):
kmi_hack = keymap.keymap_items.new("wm.tool_set_by_name", 'A', 'PRESS')
kmi_hack_properties = kmi_hack.properties
kmi_hack_brush_select = keymap.keymap_items.new("paint.brush_select", 'A', 'PRESS')
kmi_hack_brush_select_properties = kmi_hack_brush_select.properties
if use_simple_keymap:
# Simply assign a key from A-Z.
for i, (item, _, _) in enumerate(items_all):
@@ -754,6 +757,29 @@ def keymap_from_context(context, space_type):
# properties={"name": item.text},
properties=kmi_hack_properties,
)[1]
if kmi_found is None:
if item.data_block:
# PAINT_OT_brush_select
brush = bpy.data.brushes.get(item.data_block)
if brush is not None:
# print(dir(brush))
mode = context.mode
attr = {
'SCULPT': "sculpt_tool",
'VERTEX_PAINT': "vertex_paint_tool",
'WEIGHT_PAINT': "weight_paint_tool",
'TEXTURE_PAINT': "texture_paint_tool",
}[mode]
kmi_hack_brush_select_properties.paint_mode = mode
setattr(kmi_hack_brush_select_properties, attr, getattr(brush, attr))
kmi_found = wm.keyconfigs.find_item_from_operator(
idname="paint.brush_select",
context='INVOKE_REGION_WIN',
properties=kmi_hack_brush_select_properties,
)[1]
del mode, attr
else:
kmi_found = None