2022-02-11 09:07:11 +11:00
|
|
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
2018-11-20 11:15:37 +11:00
|
|
|
|
|
|
|
# Dynamically create a keymap which is used by the popup toolbar
|
|
|
|
# for accelerator key access.
|
|
|
|
|
|
|
|
__all__ = (
|
|
|
|
"generate",
|
|
|
|
)
|
|
|
|
|
2020-10-02 10:10:01 +10:00
|
|
|
|
PyAPI: use keyword only arguments
Use keyword only arguments for the following functions.
- addon_utils.module_bl_info 2nd arg `info_basis`.
- addon_utils.modules 1st `module_cache`, 2nd arg `refresh`.
- addon_utils.modules_refresh 1st arg `module_cache`.
- bl_app_template_utils.activate 1nd arg `template_id`.
- bl_app_template_utils.import_from_id 2nd arg `ignore_not_found`.
- bl_app_template_utils.import_from_path 2nd arg `ignore_not_found`.
- bl_keymap_utils.keymap_from_toolbar.generate 2nd & 3rd args `use_fallback_keys` & `use_reset`.
- bl_keymap_utils.platform_helpers.keyconfig_data_oskey_from_ctrl 2nd arg `filter_fn`.
- bl_ui_utils.bug_report_url.url_prefill_from_blender 1st arg `addon_info`.
- bmesh.types.BMFace.copy 1st & 2nd args `verts`, `edges`.
- bmesh.types.BMesh.calc_volume 1st arg `signed`.
- bmesh.types.BMesh.from_mesh 2nd..4th args `face_normals`, `use_shape_key`, `shape_key_index`.
- bmesh.types.BMesh.from_object 3rd & 4th args `cage`, `face_normals`.
- bmesh.types.BMesh.transform 2nd arg `filter`.
- bmesh.types.BMesh.update_edit_mesh 2nd & 3rd args `loop_triangles`, `destructive`.
- bmesh.types.{BMVertSeq,BMEdgeSeq,BMFaceSeq}.sort 1st & 2nd arg `key`, `reverse`.
- bmesh.utils.face_split 4th..6th args `coords`, `use_exist`, `example`.
- bpy.data.libraries.load 2nd..4th args `link`, `relative`, `assets_only`.
- bpy.data.user_map 1st..3rd args `subset`, `key_types, `value_types`.
- bpy.msgbus.subscribe_rna 5th arg `options`.
- bpy.path.abspath 2nd & 3rd args `start` & `library`.
- bpy.path.clean_name 2nd arg `replace`.
- bpy.path.ensure_ext 3rd arg `case_sensitive`.
- bpy.path.module_names 2nd arg `recursive`.
- bpy.path.relpath 2nd arg `start`.
- bpy.types.EditBone.transform 2nd & 3rd arg `scale`, `roll`.
- bpy.types.Operator.as_keywords 1st arg `ignore`.
- bpy.types.Struct.{keyframe_insert,keyframe_delete} 2nd..5th args `index`, `frame`, `group`, `options`.
- bpy.types.WindowManager.popup_menu 2nd & 3rd arg `title`, `icon`.
- bpy.types.WindowManager.popup_menu_pie 3rd & 4th arg `title`, `icon`.
- bpy.utils.app_template_paths 1st arg `subdir`.
- bpy.utils.app_template_paths 1st arg `subdir`.
- bpy.utils.blend_paths 1st..3rd args `absolute`, `packed`, `local`.
- bpy.utils.execfile 2nd arg `mod`.
- bpy.utils.keyconfig_set 2nd arg `report`.
- bpy.utils.load_scripts 1st & 2nd `reload_scripts` & `refresh_scripts`.
- bpy.utils.preset_find 3rd & 4th args `display_name`, `ext`.
- bpy.utils.resource_path 2nd & 3rd arg `major`, `minor`.
- bpy.utils.script_paths 1st..4th args `subdir`, `user_pref`, `check_all`, `use_user`.
- bpy.utils.smpte_from_frame 2nd & 3rd args `fps`, `fps_base`.
- bpy.utils.smpte_from_seconds 2nd & 3rd args `fps`, `fps_base`.
- bpy.utils.system_resource 2nd arg `subdir`.
- bpy.utils.time_from_frame 2nd & 3rd args `fps`, `fps_base`.
- bpy.utils.time_to_frame 2nd & 3rd args `fps`, `fps_base`.
- bpy.utils.units.to_string 4th..6th `precision`, `split_unit`, `compatible_unit`.
- bpy.utils.units.to_value 4th arg `str_ref_unit`.
- bpy.utils.user_resource 2nd & 3rd args `subdir`, `create`
- bpy_extras.view3d_utils.location_3d_to_region_2d 4th arg `default`.
- bpy_extras.view3d_utils.region_2d_to_origin_3d 4th arg `clamp`.
- gpu.offscreen.unbind 1st arg `restore`.
- gpu_extras.batch.batch_for_shader 4th arg `indices`.
- gpu_extras.batch.presets.draw_circle_2d 4th arg `segments`.
- gpu_extras.presets.draw_circle_2d 4th arg `segments`.
- imbuf.types.ImBuf.resize 2nd arg `resize`.
- imbuf.write 2nd arg `filepath`.
- mathutils.kdtree.KDTree.find 2nd arg `filter`.
- nodeitems_utils.NodeCategory 3rd & 4th arg `descriptions`, `items`.
- nodeitems_utils.NodeItem 2nd..4th args `label`, `settings`, `poll`.
- nodeitems_utils.NodeItemCustom 1st & 2nd arg `poll`, `draw`.
- rna_prop_ui.draw 5th arg `use_edit`.
- rna_prop_ui.rna_idprop_ui_get 2nd arg `create`.
- rna_prop_ui.rna_idprop_ui_prop_clear 3rd arg `remove`.
- rna_prop_ui.rna_idprop_ui_prop_get 3rd arg `create`.
- rna_xml.xml2rna 2nd arg `root_rna`.
- rna_xml.xml_file_write 4th arg `skip_typemap`.
2021-06-08 18:03:14 +10:00
|
|
|
def generate(context, space_type, *, use_fallback_keys=True, use_reset=True):
|
2018-11-20 11:15:37 +11:00
|
|
|
"""
|
|
|
|
Keymap for popup toolbar, currently generated each time.
|
|
|
|
"""
|
|
|
|
from bl_ui.space_toolsystem_common import ToolSelectPanelHelper
|
|
|
|
|
|
|
|
def modifier_keywords_from_item(kmi):
|
|
|
|
kw = {}
|
|
|
|
for (attr, default) in (
|
|
|
|
("any", False),
|
|
|
|
("shift", False),
|
|
|
|
("ctrl", False),
|
|
|
|
("alt", False),
|
|
|
|
("oskey", False),
|
|
|
|
("key_modifier", 'NONE'),
|
|
|
|
):
|
|
|
|
val = getattr(kmi, attr)
|
|
|
|
if val != default:
|
|
|
|
kw[attr] = val
|
|
|
|
return kw
|
|
|
|
|
|
|
|
def dict_as_tuple(d):
|
|
|
|
return tuple((k, v) for (k, v) in sorted(d.items()))
|
|
|
|
|
2018-11-23 15:41:35 +11:00
|
|
|
cls = ToolSelectPanelHelper._tool_class_from_space_type(space_type)
|
|
|
|
|
|
|
|
items_all = [
|
|
|
|
# 0: tool
|
|
|
|
# 1: keymap item (direct access)
|
|
|
|
# 2: keymap item (newly calculated for toolbar)
|
|
|
|
[item, None, None]
|
|
|
|
for item in ToolSelectPanelHelper._tools_flatten(cls.tools_from_context(context))
|
|
|
|
if item is not None
|
|
|
|
]
|
2019-03-15 12:45:41 +11:00
|
|
|
items_all_id = {item_container[0].idname for item_container in items_all}
|
2018-11-20 11:15:37 +11:00
|
|
|
|
|
|
|
# Press the toolbar popup key again to set the default tool,
|
|
|
|
# this is useful because the select box tool is useful as a way
|
|
|
|
# to 'drop' currently active tools (it's basically a 'none' tool).
|
|
|
|
# so this allows us to quickly go back to a state that allows
|
|
|
|
# a shortcut based workflow (before the tool system was added).
|
2019-10-28 22:43:15 +11:00
|
|
|
use_tap_reset = use_reset
|
2018-11-20 11:15:37 +11:00
|
|
|
# TODO: support other tools for modes which don't use this tool.
|
2019-03-15 14:18:21 +11:00
|
|
|
tap_reset_tool = "builtin.cursor"
|
2018-11-20 11:15:37 +11:00
|
|
|
# Check the tool is available in the current context.
|
2019-03-15 12:45:41 +11:00
|
|
|
if tap_reset_tool not in items_all_id:
|
2018-11-20 11:15:37 +11:00
|
|
|
use_tap_reset = False
|
|
|
|
|
|
|
|
# Pie-menu style release to activate.
|
2019-10-28 22:43:15 +11:00
|
|
|
use_release_confirm = use_reset
|
2018-11-20 11:15:37 +11:00
|
|
|
|
|
|
|
# Generate items when no keys are mapped.
|
2019-08-11 22:41:04 +10:00
|
|
|
use_auto_keymap_alpha = False # Map manually in the default key-map.
|
2019-10-28 22:43:15 +11:00
|
|
|
use_auto_keymap_num = use_fallback_keys
|
2018-11-20 11:15:37 +11:00
|
|
|
|
|
|
|
# Temporary, only create so we can pass 'properties' to find_item_from_operator.
|
|
|
|
use_hack_properties = True
|
|
|
|
|
2018-11-23 15:16:45 +11:00
|
|
|
km_name_default = "Toolbar Popup"
|
|
|
|
km_name = km_name_default + " <temp>"
|
2018-11-20 11:15:37 +11:00
|
|
|
wm = context.window_manager
|
2019-01-14 18:59:26 +11:00
|
|
|
keyconf_user = wm.keyconfigs.user
|
|
|
|
keyconf_active = wm.keyconfigs.active
|
|
|
|
|
|
|
|
keymap = keyconf_active.keymaps.get(km_name)
|
2018-11-20 11:15:37 +11:00
|
|
|
if keymap is None:
|
2019-01-14 18:59:26 +11:00
|
|
|
keymap = keyconf_active.keymaps.new(km_name, space_type='EMPTY', region_type='TEMPORARY')
|
2018-11-23 15:16:45 +11:00
|
|
|
for kmi in keymap.keymap_items:
|
|
|
|
keymap.keymap_items.remove(kmi)
|
|
|
|
|
2019-01-14 18:59:26 +11:00
|
|
|
keymap_src = keyconf_user.keymaps.get(km_name_default)
|
2018-11-23 15:16:45 +11:00
|
|
|
if keymap_src is not None:
|
|
|
|
for kmi_src in keymap_src.keymap_items:
|
2018-11-23 15:41:35 +11:00
|
|
|
# Skip tools that aren't currently shown.
|
|
|
|
if (
|
2019-03-15 12:45:41 +11:00
|
|
|
(kmi_src.idname == "wm.tool_set_by_id") and
|
|
|
|
(kmi_src.properties.name not in items_all_id)
|
2018-11-23 15:41:35 +11:00
|
|
|
):
|
|
|
|
continue
|
2018-11-23 15:16:45 +11:00
|
|
|
keymap.keymap_items.new_from_item(kmi_src)
|
|
|
|
del keymap_src
|
2019-03-15 12:45:41 +11:00
|
|
|
del items_all_id
|
2018-11-23 15:16:45 +11:00
|
|
|
|
2018-11-20 11:15:37 +11:00
|
|
|
kmi_unique_args = set()
|
|
|
|
|
2018-11-22 11:54:17 +11:00
|
|
|
def kmi_unique_or_pass(kmi_args):
|
|
|
|
kmi_unique_len = len(kmi_unique_args)
|
|
|
|
kmi_unique_args.add(dict_as_tuple(kmi_args))
|
|
|
|
return kmi_unique_len != len(kmi_unique_args)
|
|
|
|
|
2018-11-20 11:15:37 +11:00
|
|
|
cls = ToolSelectPanelHelper._tool_class_from_space_type(space_type)
|
|
|
|
|
|
|
|
if use_hack_properties:
|
2019-03-15 12:45:41 +11:00
|
|
|
kmi_hack = keymap.keymap_items.new("wm.tool_set_by_id", 'NONE', 'PRESS')
|
2018-11-20 11:15:37 +11:00
|
|
|
kmi_hack_properties = kmi_hack.properties
|
2018-11-22 11:33:10 +11:00
|
|
|
kmi_hack.active = False
|
2018-11-20 11:15:37 +11:00
|
|
|
|
2018-11-22 11:33:10 +11:00
|
|
|
kmi_hack_brush_select = keymap.keymap_items.new("paint.brush_select", 'NONE', 'PRESS')
|
2018-11-20 11:15:37 +11:00
|
|
|
kmi_hack_brush_select_properties = kmi_hack_brush_select.properties
|
2018-11-22 11:33:10 +11:00
|
|
|
kmi_hack_brush_select.active = False
|
2018-11-20 11:15:37 +11:00
|
|
|
|
|
|
|
if use_release_confirm or use_tap_reset:
|
2018-12-12 09:39:36 +11:00
|
|
|
kmi_toolbar = wm.keyconfigs.find_item_from_operator(
|
|
|
|
idname="wm.toolbar",
|
|
|
|
)[1]
|
2018-11-20 11:15:37 +11:00
|
|
|
kmi_toolbar_type = None if not kmi_toolbar else kmi_toolbar.type
|
|
|
|
if use_tap_reset and kmi_toolbar_type is not None:
|
|
|
|
kmi_toolbar_args_type_only = {"type": kmi_toolbar_type}
|
|
|
|
kmi_toolbar_args = {**kmi_toolbar_args_type_only, **modifier_keywords_from_item(kmi_toolbar)}
|
|
|
|
else:
|
|
|
|
use_tap_reset = False
|
|
|
|
del kmi_toolbar
|
|
|
|
|
|
|
|
if use_tap_reset:
|
|
|
|
kmi_found = None
|
|
|
|
if use_hack_properties:
|
|
|
|
# First check for direct assignment, if this tool already has a key, no need to add a new one.
|
|
|
|
kmi_hack_properties.name = tap_reset_tool
|
|
|
|
kmi_found = wm.keyconfigs.find_item_from_operator(
|
2019-03-15 12:45:41 +11:00
|
|
|
idname="wm.tool_set_by_id",
|
2018-11-20 11:15:37 +11:00
|
|
|
context='INVOKE_REGION_WIN',
|
2019-03-15 12:45:41 +11:00
|
|
|
# properties={"name": item.idname},
|
2018-11-20 11:15:37 +11:00
|
|
|
properties=kmi_hack_properties,
|
2018-12-12 21:39:55 +11:00
|
|
|
include={'KEYBOARD'},
|
2018-11-20 11:15:37 +11:00
|
|
|
)[1]
|
|
|
|
if kmi_found:
|
|
|
|
use_tap_reset = False
|
|
|
|
del kmi_found
|
|
|
|
|
|
|
|
if use_tap_reset:
|
2018-11-22 11:54:17 +11:00
|
|
|
use_tap_reset = kmi_unique_or_pass(kmi_toolbar_args)
|
2018-11-20 11:15:37 +11:00
|
|
|
|
|
|
|
if use_tap_reset:
|
2018-11-23 15:41:35 +11:00
|
|
|
items_all[:] = [
|
|
|
|
item_container
|
|
|
|
for item_container in items_all
|
2019-03-15 12:45:41 +11:00
|
|
|
if item_container[0].idname != tap_reset_tool
|
2018-11-23 15:41:35 +11:00
|
|
|
]
|
2018-11-20 11:15:37 +11:00
|
|
|
|
2018-11-26 16:07:03 +11:00
|
|
|
# -----------------------
|
|
|
|
# Begin Keymap Generation
|
2018-11-20 11:15:37 +11:00
|
|
|
|
2018-11-26 16:07:03 +11:00
|
|
|
# -------------------------------------------------------------------------
|
|
|
|
# Direct Tool Assignment & Brushes
|
2018-11-20 11:15:37 +11:00
|
|
|
|
2018-11-26 16:07:03 +11:00
|
|
|
for item_container in items_all:
|
|
|
|
item = item_container[0]
|
|
|
|
# Only check the first item in the tools key-map (a little arbitrary).
|
|
|
|
if use_hack_properties:
|
|
|
|
# First check for direct assignment.
|
2019-03-15 12:45:41 +11:00
|
|
|
kmi_hack_properties.name = item.idname
|
2018-11-26 16:07:03 +11:00
|
|
|
kmi_found = wm.keyconfigs.find_item_from_operator(
|
2019-03-15 12:45:41 +11:00
|
|
|
idname="wm.tool_set_by_id",
|
2018-11-26 16:07:03 +11:00
|
|
|
context='INVOKE_REGION_WIN',
|
2019-03-15 12:45:41 +11:00
|
|
|
# properties={"name": item.idname},
|
2018-11-26 16:07:03 +11:00
|
|
|
properties=kmi_hack_properties,
|
2018-12-12 21:39:55 +11:00
|
|
|
include={'KEYBOARD'},
|
2018-11-26 16:07:03 +11:00
|
|
|
)[1]
|
|
|
|
|
|
|
|
if kmi_found is None:
|
|
|
|
if item.data_block:
|
|
|
|
# PAINT_OT_brush_select
|
|
|
|
mode = context.active_object.mode
|
|
|
|
# See: BKE_paint_get_tool_prop_id_from_paintmode
|
2020-10-26 21:03:25 +11:00
|
|
|
if space_type == 'IMAGE_EDITOR':
|
2022-09-21 09:34:11 +12:00
|
|
|
if context.space_data.mode == 'PAINT':
|
2020-10-26 21:03:25 +11:00
|
|
|
attr = "image_tool"
|
|
|
|
else:
|
|
|
|
attr = None
|
|
|
|
elif space_type == 'VIEW_3D':
|
|
|
|
attr = {
|
|
|
|
'SCULPT': "sculpt_tool",
|
|
|
|
'VERTEX_PAINT': "vertex_tool",
|
|
|
|
'WEIGHT_PAINT': "weight_tool",
|
|
|
|
'TEXTURE_PAINT': "image_tool",
|
|
|
|
'PAINT_GPENCIL': "gpencil_tool",
|
|
|
|
'VERTEX_GPENCIL': "gpencil_vertex_tool",
|
|
|
|
'SCULPT_GPENCIL': "gpencil_sculpt_tool",
|
|
|
|
'WEIGHT_GPENCIL': "gpencil_weight_tool",
|
2022-02-18 09:12:41 +01:00
|
|
|
'SCULPT_CURVES': "curves_sculpt_tool",
|
2020-10-26 21:03:25 +11:00
|
|
|
}.get(mode, None)
|
|
|
|
else:
|
|
|
|
attr = None
|
|
|
|
|
2018-11-26 16:07:03 +11:00
|
|
|
if attr is not None:
|
|
|
|
setattr(kmi_hack_brush_select_properties, attr, item.data_block)
|
2018-11-22 11:13:22 +11:00
|
|
|
kmi_found = wm.keyconfigs.find_item_from_operator(
|
2018-11-26 16:07:03 +11:00
|
|
|
idname="paint.brush_select",
|
2018-11-22 11:13:22 +11:00
|
|
|
context='INVOKE_REGION_WIN',
|
2018-11-26 16:07:03 +11:00
|
|
|
properties=kmi_hack_brush_select_properties,
|
2018-12-12 21:39:55 +11:00
|
|
|
include={'KEYBOARD'},
|
2018-11-22 11:13:22 +11:00
|
|
|
)[1]
|
2022-09-21 09:34:11 +12:00
|
|
|
elif mode in {'EDIT', 'PARTICLE_EDIT', 'SCULPT_GPENCIL'}:
|
2019-03-06 00:28:06 +11:00
|
|
|
# Doesn't use brushes
|
|
|
|
pass
|
2018-11-22 11:13:22 +11:00
|
|
|
else:
|
2018-11-26 16:07:03 +11:00
|
|
|
print("Unsupported mode:", mode)
|
|
|
|
del mode, attr
|
2018-11-20 11:15:37 +11:00
|
|
|
|
2018-11-26 16:07:03 +11:00
|
|
|
else:
|
|
|
|
kmi_found = None
|
2018-11-20 11:15:37 +11:00
|
|
|
|
2018-11-26 16:07:03 +11:00
|
|
|
if kmi_found is not None:
|
|
|
|
pass
|
|
|
|
elif item.operator is not None:
|
|
|
|
kmi_found = wm.keyconfigs.find_item_from_operator(
|
|
|
|
idname=item.operator,
|
|
|
|
context='INVOKE_REGION_WIN',
|
2018-12-12 21:39:55 +11:00
|
|
|
include={'KEYBOARD'},
|
2018-11-26 16:07:03 +11:00
|
|
|
)[1]
|
|
|
|
elif item.keymap is not None:
|
2019-01-14 18:59:26 +11:00
|
|
|
km = keyconf_user.keymaps.get(item.keymap[0])
|
2018-11-26 16:07:03 +11:00
|
|
|
if km is None:
|
2019-03-15 12:45:41 +11:00
|
|
|
print("Keymap", repr(item.keymap[0]), "not found for tool", item.idname)
|
2018-11-26 16:07:03 +11:00
|
|
|
kmi_found = None
|
|
|
|
else:
|
|
|
|
kmi_first = km.keymap_items
|
|
|
|
kmi_first = kmi_first[0] if kmi_first else None
|
|
|
|
if kmi_first is not None:
|
2019-01-07 11:16:11 +11:00
|
|
|
kmi_found = wm.keyconfigs.find_item_from_operator(
|
|
|
|
idname=kmi_first.idname,
|
|
|
|
# properties=kmi_first.properties, # prevents matches, don't use.
|
|
|
|
context='INVOKE_REGION_WIN',
|
|
|
|
include={'KEYBOARD'},
|
|
|
|
)[1]
|
|
|
|
if kmi_found is None:
|
|
|
|
# We need non-keyboard events so keys with 'key_modifier' key is found.
|
2019-01-07 11:00:46 +11:00
|
|
|
kmi_found = wm.keyconfigs.find_item_from_operator(
|
|
|
|
idname=kmi_first.idname,
|
|
|
|
# properties=kmi_first.properties, # prevents matches, don't use.
|
|
|
|
context='INVOKE_REGION_WIN',
|
2019-01-07 11:16:11 +11:00
|
|
|
exclude={'KEYBOARD'},
|
2019-01-07 11:00:46 +11:00
|
|
|
)[1]
|
|
|
|
if kmi_found is not None:
|
2019-01-07 11:16:11 +11:00
|
|
|
if kmi_found.key_modifier == 'NONE':
|
2019-01-07 11:00:46 +11:00
|
|
|
kmi_found = None
|
2018-11-26 16:07:03 +11:00
|
|
|
else:
|
|
|
|
kmi_found = None
|
|
|
|
del kmi_first
|
|
|
|
del km
|
|
|
|
else:
|
|
|
|
kmi_found = None
|
|
|
|
item_container[1] = kmi_found
|
|
|
|
|
|
|
|
# -------------------------------------------------------------------------
|
|
|
|
# Single Key Access
|
|
|
|
|
|
|
|
# More complex multi-pass test.
|
|
|
|
for item_container in items_all:
|
|
|
|
item, kmi_found = item_container[:2]
|
|
|
|
if kmi_found is None:
|
|
|
|
continue
|
|
|
|
kmi_found_type = kmi_found.type
|
|
|
|
|
|
|
|
# Only for single keys.
|
|
|
|
if (
|
|
|
|
(len(kmi_found_type) == 1) or
|
|
|
|
# When a tool is being activated instead of running an operator, just copy the shortcut.
|
2019-03-15 12:45:41 +11:00
|
|
|
(kmi_found.idname in {"wm.tool_set_by_id", "WM_OT_tool_set_by_id"})
|
2018-11-26 16:07:03 +11:00
|
|
|
):
|
|
|
|
kmi_args = {"type": kmi_found_type, **modifier_keywords_from_item(kmi_found)}
|
|
|
|
if kmi_unique_or_pass(kmi_args):
|
2019-03-15 12:45:41 +11:00
|
|
|
kmi = keymap.keymap_items.new(idname="wm.tool_set_by_id", value='PRESS', **kmi_args)
|
|
|
|
kmi.properties.name = item.idname
|
2018-11-26 16:07:03 +11:00
|
|
|
item_container[2] = kmi
|
|
|
|
|
|
|
|
# -------------------------------------------------------------------------
|
|
|
|
# Single Key Modifier
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# Test for key_modifier, where alpha key is used as a 'key_modifier'
|
|
|
|
# (grease pencil holding 'D' for example).
|
|
|
|
|
|
|
|
for item_container in items_all:
|
|
|
|
item, kmi_found, kmi_exist = item_container
|
|
|
|
if kmi_found is None or kmi_exist:
|
|
|
|
continue
|
|
|
|
|
|
|
|
kmi_found_type = kmi_found.type
|
|
|
|
if kmi_found_type in {
|
|
|
|
'LEFTMOUSE',
|
|
|
|
'RIGHTMOUSE',
|
|
|
|
'MIDDLEMOUSE',
|
|
|
|
'BUTTON4MOUSE',
|
|
|
|
'BUTTON5MOUSE',
|
|
|
|
'BUTTON6MOUSE',
|
|
|
|
'BUTTON7MOUSE',
|
|
|
|
}:
|
|
|
|
kmi_found_type = kmi_found.key_modifier
|
|
|
|
# excludes 'NONE'
|
|
|
|
if len(kmi_found_type) == 1:
|
2018-11-20 11:15:37 +11:00
|
|
|
kmi_args = {"type": kmi_found_type, **modifier_keywords_from_item(kmi_found)}
|
2018-11-26 16:07:03 +11:00
|
|
|
del kmi_args["key_modifier"]
|
2018-11-22 11:54:17 +11:00
|
|
|
if kmi_unique_or_pass(kmi_args):
|
2019-03-15 12:45:41 +11:00
|
|
|
kmi = keymap.keymap_items.new(idname="wm.tool_set_by_id", value='PRESS', **kmi_args)
|
|
|
|
kmi.properties.name = item.idname
|
2018-11-22 11:54:17 +11:00
|
|
|
item_container[2] = kmi
|
2018-11-20 11:15:37 +11:00
|
|
|
|
2018-11-26 16:07:03 +11:00
|
|
|
# -------------------------------------------------------------------------
|
|
|
|
# Assign A-Z to Keys
|
|
|
|
#
|
2019-03-15 14:18:21 +11:00
|
|
|
# When the keys are free.
|
2018-11-26 16:07:03 +11:00
|
|
|
|
|
|
|
if use_auto_keymap_alpha:
|
|
|
|
# Map all unmapped keys to numbers,
|
|
|
|
# while this is a bit strange it means users will not confuse regular key bindings to ordered bindings.
|
|
|
|
|
|
|
|
# First map A-Z.
|
|
|
|
kmi_type_alpha_char = [chr(i) for i in range(65, 91)]
|
|
|
|
kmi_type_alpha_args = {c: {"type": c} for c in kmi_type_alpha_char}
|
|
|
|
kmi_type_alpha_args_tuple = {c: dict_as_tuple(kmi_type_alpha_args[c]) for c in kmi_type_alpha_char}
|
2018-11-20 11:15:37 +11:00
|
|
|
for item_container in items_all:
|
|
|
|
item, kmi_found, kmi_exist = item_container
|
2018-11-26 16:07:03 +11:00
|
|
|
if kmi_exist:
|
2018-11-20 11:15:37 +11:00
|
|
|
continue
|
2019-03-15 12:45:41 +11:00
|
|
|
kmi_type = item.label[0].upper()
|
2018-11-26 16:07:03 +11:00
|
|
|
kmi_tuple = kmi_type_alpha_args_tuple.get(kmi_type)
|
|
|
|
if kmi_tuple and kmi_tuple not in kmi_unique_args:
|
|
|
|
kmi_unique_args.add(kmi_tuple)
|
|
|
|
kmi = keymap.keymap_items.new(
|
2019-03-15 12:45:41 +11:00
|
|
|
idname="wm.tool_set_by_id",
|
2018-11-26 16:07:03 +11:00
|
|
|
value='PRESS',
|
|
|
|
**kmi_type_alpha_args[kmi_type],
|
|
|
|
)
|
2019-03-15 12:45:41 +11:00
|
|
|
kmi.properties.name = item.idname
|
2018-11-26 16:07:03 +11:00
|
|
|
item_container[2] = kmi
|
|
|
|
del kmi_type_alpha_char, kmi_type_alpha_args, kmi_type_alpha_args_tuple
|
|
|
|
|
|
|
|
# -------------------------------------------------------------------------
|
|
|
|
# Assign Numbers to Keys
|
|
|
|
|
|
|
|
if use_auto_keymap_num:
|
|
|
|
# Free events (last used first).
|
|
|
|
kmi_type_auto = ('ONE', 'TWO', 'THREE', 'FOUR', 'FIVE', 'SIX', 'SEVEN', 'EIGHT', 'NINE', 'ZERO')
|
|
|
|
# Map both numbers and num-pad.
|
|
|
|
kmi_type_dupe = {
|
|
|
|
'ONE': 'NUMPAD_1',
|
|
|
|
'TWO': 'NUMPAD_2',
|
|
|
|
'THREE': 'NUMPAD_3',
|
|
|
|
'FOUR': 'NUMPAD_4',
|
|
|
|
'FIVE': 'NUMPAD_5',
|
|
|
|
'SIX': 'NUMPAD_6',
|
|
|
|
'SEVEN': 'NUMPAD_7',
|
|
|
|
'EIGHT': 'NUMPAD_8',
|
|
|
|
'NINE': 'NUMPAD_9',
|
|
|
|
'ZERO': 'NUMPAD_0',
|
|
|
|
}
|
|
|
|
|
|
|
|
def iter_free_events():
|
|
|
|
for mod in ({}, {"shift": True}, {"ctrl": True}, {"alt": True}):
|
|
|
|
for e in kmi_type_auto:
|
|
|
|
yield (e, mod)
|
|
|
|
|
|
|
|
iter_events = iter(iter_free_events())
|
2018-11-20 11:15:37 +11:00
|
|
|
|
2018-11-26 16:07:03 +11:00
|
|
|
for item_container in items_all:
|
|
|
|
item, kmi_found, kmi_exist = item_container
|
|
|
|
if kmi_exist:
|
|
|
|
continue
|
|
|
|
kmi_args = None
|
|
|
|
while True:
|
|
|
|
key, mod = next(iter_events, (None, None))
|
|
|
|
if key is None:
|
|
|
|
break
|
|
|
|
kmi_args = {"type": key, **mod}
|
|
|
|
kmi_tuple = dict_as_tuple(kmi_args)
|
|
|
|
if kmi_tuple in kmi_unique_args:
|
|
|
|
kmi_args = None
|
|
|
|
else:
|
|
|
|
break
|
|
|
|
|
|
|
|
if kmi_args is not None:
|
2019-03-15 12:45:41 +11:00
|
|
|
kmi = keymap.keymap_items.new(idname="wm.tool_set_by_id", value='PRESS', **kmi_args)
|
|
|
|
kmi.properties.name = item.idname
|
2018-11-26 16:07:03 +11:00
|
|
|
item_container[2] = kmi
|
|
|
|
kmi_unique_args.add(kmi_tuple)
|
|
|
|
|
|
|
|
key = kmi_type_dupe.get(kmi_args["type"])
|
|
|
|
if key is not None:
|
|
|
|
kmi_args["type"] = key
|
|
|
|
kmi_tuple = dict_as_tuple(kmi_args)
|
2022-04-26 15:03:04 +10:00
|
|
|
if kmi_tuple not in kmi_unique_args:
|
2019-03-15 12:45:41 +11:00
|
|
|
kmi = keymap.keymap_items.new(idname="wm.tool_set_by_id", value='PRESS', **kmi_args)
|
|
|
|
kmi.properties.name = item.idname
|
2018-11-26 16:07:03 +11:00
|
|
|
kmi_unique_args.add(kmi_tuple)
|
2018-11-20 11:15:37 +11:00
|
|
|
|
2018-11-26 16:07:03 +11:00
|
|
|
# ---------------------
|
|
|
|
# End Keymap Generation
|
2018-11-20 11:15:37 +11:00
|
|
|
|
|
|
|
if use_hack_properties:
|
|
|
|
keymap.keymap_items.remove(kmi_hack)
|
2018-11-26 16:07:03 +11:00
|
|
|
keymap.keymap_items.remove(kmi_hack_brush_select)
|
2018-11-20 11:15:37 +11:00
|
|
|
|
2018-11-26 16:07:03 +11:00
|
|
|
# Keep last so we can try add a key without any modifiers
|
2018-11-20 11:15:37 +11:00
|
|
|
# in the case this toolbar was activated with modifiers.
|
|
|
|
if use_tap_reset:
|
|
|
|
if len(kmi_toolbar_args_type_only) == len(kmi_toolbar_args):
|
|
|
|
kmi_toolbar_args_available = kmi_toolbar_args
|
|
|
|
else:
|
|
|
|
# We have modifiers, see if we have a free key w/o modifiers.
|
|
|
|
kmi_toolbar_tuple = dict_as_tuple(kmi_toolbar_args_type_only)
|
|
|
|
if kmi_toolbar_tuple not in kmi_unique_args:
|
|
|
|
kmi_toolbar_args_available = kmi_toolbar_args_type_only
|
|
|
|
kmi_unique_args.add(kmi_toolbar_tuple)
|
|
|
|
else:
|
|
|
|
kmi_toolbar_args_available = kmi_toolbar_args
|
|
|
|
del kmi_toolbar_tuple
|
|
|
|
|
|
|
|
kmi = keymap.keymap_items.new(
|
2019-03-15 12:45:41 +11:00
|
|
|
"wm.tool_set_by_id",
|
2021-01-24 15:51:05 +11:00
|
|
|
value='DOUBLE_CLICK',
|
2018-11-20 11:15:37 +11:00
|
|
|
**kmi_toolbar_args_available,
|
|
|
|
)
|
|
|
|
kmi.properties.name = tap_reset_tool
|
|
|
|
|
2019-07-25 13:35:01 +10:00
|
|
|
if use_release_confirm and (kmi_toolbar_type is not None):
|
2018-11-20 11:15:37 +11:00
|
|
|
kmi = keymap.keymap_items.new(
|
|
|
|
"ui.button_execute",
|
|
|
|
type=kmi_toolbar_type,
|
|
|
|
value='RELEASE',
|
|
|
|
any=True,
|
|
|
|
)
|
|
|
|
kmi.properties.skip_depressed = True
|
|
|
|
|
|
|
|
wm.keyconfigs.update()
|
|
|
|
return keymap
|