Expose keymaps

1.7.6

- ui: expose (almost) all keymap added by the addon to allow user for customize/disable as needed
- ui: changed some names
This commit is contained in:
Pullusb
2021-10-29 16:49:38 +02:00
parent 44ccb3d146
commit 204553ed47
7 changed files with 107 additions and 43 deletions
+91 -32
View File
@@ -15,7 +15,7 @@ bl_info = {
"name": "GP toolbox",
"description": "Set of tools for Grease Pencil in animation production",
"author": "Samuel Bernou, Christophe Seux",
"version": (1, 7, 5),
"version": (1, 7, 6),
"blender": (2, 91, 0),
"location": "Sidebar (N menu) > Gpencil > Toolbox / Gpencil properties",
"warning": "",
@@ -125,7 +125,8 @@ class GPTB_prefs(bpy.types.AddonPreferences):
pref_tabs : EnumProperty(
items=(('PREF', "Preferences", "Change some preferences of the modal"),
('MAN_OPS', "Operator", "Operator to add Manually"),
('KEYS', "Shortcuts", "Customize addon shortcuts"),
('MAN_OPS', "Operators", "Operator to add Manually"),
('CHECKS', "Check List", "Customise what should happend when hitting 'check fix' button"),
# ('UPDATE', "Update", "Check and apply updates"),
# ('TUTO', "Tutorial", "How to use the tool"),
@@ -375,44 +376,102 @@ class GPTB_prefs(bpy.types.AddonPreferences):
box.prop(self, 'playblast_auto_open_folder')
# box.separator()## Keyframe jumper
box = layout.box()
box.label(text='Keyframe Jump options:')
box.prop(self, "kfj_use_shortcut", text='Bind shortcuts')
if self.kfj_use_shortcut:
prompt = '[TYPE SHORTCUT TO USE (can be with modifiers)]'
if self.kfj_prev_keycode:
mods = '+'.join([m for m, b in [('Ctrl', self.kfj_prev_ctrl), ('Shift', self.kfj_prev_shift), ('Alt', self.kfj_prev_alt)] if b])
text = f'{mods}+{self.kfj_prev_keycode}' if mods else self.kfj_prev_keycode
text = f'Jump Keyframe Prev: {text} (Click to change)'
else:
text = prompt
ops = box.operator('prefs.shortcut_rebinder', text=text, icon='FILE_REFRESH')
ops.s_keycode = 'kfj_prev_keycode'
ops.s_ctrl = 'kfj_prev_ctrl'
ops.s_shift = 'kfj_prev_shift'
ops.s_alt = 'kfj_prev_alt'
## Keyframe jump now displayed in Shortcut Tab
# box = layout.box()
# box.label(text='Keyframe Jump options:')
if self.kfj_next_keycode:
mods = '+'.join([m for m, b in [('Ctrl', self.kfj_next_ctrl), ('Shift', self.kfj_next_shift), ('Alt', self.kfj_next_alt)] if b])
text = f'{mods}+{self.kfj_next_keycode}' if mods else self.kfj_next_keycode
text = f'Jump Keyframe Next: {text} (Click to change)'
else:
text = prompt
ops = box.operator('prefs.shortcut_rebinder', text=text, icon='FILE_REFRESH')
ops.s_keycode = 'kfj_next_keycode'
ops.s_ctrl = 'kfj_next_ctrl'
ops.s_shift = 'kfj_next_shift'
ops.s_alt = 'kfj_next_alt'
# box.prop(self, "kfj_use_shortcut", text='Bind shortcuts')
# if self.kfj_use_shortcut:
# prompt = '[TYPE SHORTCUT TO USE (can be with modifiers)]'
# if self.kfj_prev_keycode:
# mods = '+'.join([m for m, b in [('Ctrl', self.kfj_prev_ctrl), ('Shift', self.kfj_prev_shift), ('Alt', self.kfj_prev_alt)] if b])
# text = f'{mods}+{self.kfj_prev_keycode}' if mods else self.kfj_prev_keycode
# text = f'Jump Keyframe Prev: {text} (Click to change)'
# else:
# text = prompt
# ops = box.operator('prefs.shortcut_rebinder', text=text, icon='FILE_REFRESH')
# ops.s_keycode = 'kfj_prev_keycode'
# ops.s_ctrl = 'kfj_prev_ctrl'
# ops.s_shift = 'kfj_prev_shift'
# ops.s_alt = 'kfj_prev_alt'
# if self.kfj_next_keycode:
# mods = '+'.join([m for m, b in [('Ctrl', self.kfj_next_ctrl), ('Shift', self.kfj_next_shift), ('Alt', self.kfj_next_alt)] if b])
# text = f'{mods}+{self.kfj_next_keycode}' if mods else self.kfj_next_keycode
# text = f'Jump Keyframe Next: {text} (Click to change)'
# else:
# text = prompt
# ops = box.operator('prefs.shortcut_rebinder', text=text, icon='FILE_REFRESH')
# ops.s_keycode = 'kfj_next_keycode'
# ops.s_ctrl = 'kfj_next_ctrl'
# ops.s_shift = 'kfj_next_shift'
# ops.s_alt = 'kfj_next_alt'
else:
box.label(text="No Jump hotkey auto set. Following operators needs to be set manually", icon="ERROR")
box.label(text="screen.gp_keyframe_jump - preferably in 'screen' category to jump from any editor")
# else:
# box.label(text="No Jump hotkey auto set. Following operators needs to be set manually", icon="ERROR")
# box.label(text="screen.gp_keyframe_jump - preferably in 'screen' category to jump from any editor")
box = layout.box()
box.label(text='Tools options:')
box.prop(self, 'use_precise_eraser')
if self.pref_tabs == 'KEYS':
# layout.label(text='Shortcuts :')
box = layout.box()
box.label(text='Shortcuts added by GP toolbox with context scope:')
## not available directly :
## keymaps.addon_keymaps <<- one two three on sculpt, not exposed
## OP_temp_cutter # not active by defaut
## TOOL_eraser_brush.addon_keymaps # has a checkbox in
prev_key_category = ''
kmi_see_list = []
for kms in [
OP_keyframe_jump.addon_keymaps,
OP_copy_paste.addon_keymaps,
OP_breakdowner.breakdowner_addon_keymaps,
OP_key_duplicate_send.addon_keymaps,
OP_layer_picker.addon_keymaps,
OP_material_picker.addon_keymaps,
]:
ct = 0
for akm, akmi in kms:
km = bpy.context.window_manager.keyconfigs.user.keymaps.get(akm.name)
if not km:
continue
key_category = km.name
# kmi = km.keymap_items.get(akmi.idname) # get only first idname when multiple entry
kmi = None
## numbering hack, need a better way to find multi idname user keymaps
id_ct = 0
for km_item in km.keymap_items:
if km_item.idname == akmi.idname:
if ct > id_ct:
id_ct +=1
continue
kmi = km_item
ct += 1
break
if not kmi:
continue
## show keymap category (ideally grouped by category)
if not prev_key_category:
if key_category:
box.label(text=key_category)
elif key_category and key_category != prev_key_category: # check if has changed singe
box.label(text=key_category)
draw_kmi(km, kmi, box)
prev_key_category = key_category
box.separator()
if self.pref_tabs == 'MAN_OPS':
# layout.separator()## notes
# layout.label(text='Notes:')