Maniphest T59113

Addon's keymaps are not registered at Blender opening if the addon's enable state is saved in user preferences
Closed, ArchivedBUG

Assigned To
Campbell Barton (campbellbarton)
Authored By
domlysz (domlysz)
Dec 10 2018, 9:59 AM
Tags
  • BF Blender
  • Add-ons (BF-Blender)
  • Python API
Subscribers
domlysz (domlysz)
Matthias Pieroth (jayanam)

Description

Blender Version
Broken: 2.80

Short description of error

The code bellow illustrates the issue, it register a new shortcut (here for example the translate operator on numpad asterix key). When the addon is activated for the first time, then the shortcut works correctly. If this activation state is saved in user preferences and then Blender reopenned, the shortcut does not works anymore.

bl_info = {
	'name': 'Test',
	'blender': (2, 80, 0),
	'category': '3D View'
	}

import bpy

def register():
	wm = bpy.context.window_manager
	kc =  wm.keyconfigs.active
	km = kc.keymaps['3D View']
	kmi = km.keymap_items.new(idname='transform.translate', type='NUMPAD_ASTERIX', value='PRESS')


def unregister():
	wm = bpy.context.window_manager
	km = wm.keyconfigs.active.keymaps['3D View']
	kmi = km.keymap_items.remove(km.keymap_items['transform.translate'])

if __name__ == "__main__":
	register()

Event Timeline

domlysz (domlysz) created this task.Dec 10 2018, 9:59 AM
Brecht Van Lommel (brecht) removed a project: BF Blender: 2.8.Dec 11 2018, 3:07 PM
Matthias Pieroth (jayanam) added a subscriber: Matthias Pieroth (jayanam).Jan 18 2019, 10:20 PM

I have the same issue, the keymaps are not persisted.

Sebastian Parborg (zeddb) closed this task as a duplicate of T60766: Modal keymap customization from an addon is not restored properly.Feb 13 2019, 4:39 PM
Campbell Barton (campbellbarton) reopened this task as Needs Triage.Mar 26 2020, 10:41 AM
Campbell Barton (campbellbarton) claimed this task.
Germano Cavalcante (mano-wii) changed the task status from Needs Triage to Confirmed.Mar 27 2020, 2:36 PM
Germano Cavalcante (mano-wii) changed the subtype of this task from "Report" to "Bug".
Germano Cavalcante (mano-wii) added a project: Python API.
Campbell Barton (campbellbarton) closed this task as Archived.Apr 7 2020, 5:48 AM

You need to use wm.keyconfigs.addon for this to work as expected.