Page MenuHome

Changing keymap with a script doesn't trigger the "is_user_modified" flag
Closed, ArchivedPublic

Description

System Information
Operating system: Solus Gnome 4.1
Graphics card: GTX 1050

Blender Version
Broken: 2.83.4, 2.90

Short description of error
I use the Dvorak keyboard layout. I found and modified a script to change all keymaps from QWERTY to DVORAK. When I run the script all keymaps do change, but the ones from addons (both official and 3rd party) don't register as being modified by the user (I believe it's the "is_user_modified" flag, not sure tho).

Here is a screenshot of the Blender keymap before running the script:

Heres is a screenshot of the Blender keymap after running the script:

The red arrows point to a keymap added by Power Sequencer official addon. The green arrows point to a user non-addon keymap. The icon on the right suggesting to restore the keymap doesn't change in the red arrows.

Here's a link to the script: GitHub Link
I also uploaded the script file in case it helps.

Exact steps for others to reproduce the error
To be certain that the problem was caused by 3rd party addons I removed the .config/blender/2.83 folder, started up Blender 2.83.4, activated Power Sequencer addon, pasted the script in a text editor and ran the script.

Event Timeline

Philipp Oeser (lichtwerk) changed the task status from Needs Triage to Confirmed.Aug 10 2020, 5:44 PM

Can confirm, will check on this...

Philipp Oeser (lichtwerk) changed the task status from Confirmed to Needs Information from User.Aug 11 2020, 12:06 AM

After some digging - when dealing with Addon keymaps - it looks like you have to get the active version of the keymap prior to changing the keymapitem.
The above is the User configuration stored in userconf of the wmWindowManager.
Otherwise you are altering the Addon keymap stored in addonconf of the wmWindowManager.
[This is the "original" config which you actually want to go back to when you restore a keymap or keymap item]

https://docs.blender.org/api/master/bpy.types.KeyMap.html#bpy.types.KeyMap.active

So this is how it would look, if i do this, I am getting the keymap entry properly tagged is_user_modified / KMI_USER_MODIFIED

# Transform the addon keys using the conversion_map
for km in wm.keyconfigs.addon.keymaps:
    # get the active version of the keymap, dont alter the oiginal Addon keymap
    km = km.active()
    for kmi in km.keymap_items:
        ...

Does this work for you?

Brecht Van Lommel (brecht) claimed this task.

Please see the descriptions of the addons and user keymaps:
https://docs.blender.org/api/current/bpy.types.KeyConfigurations.html

Any user configuration should go to the user keymap, which contains items from both builtin functionality and add-ons. Editing the add-ons keymap is not supposed to show up as user modified. Just remove the part of the script that modifies the addons keymap.

I apologize for the late reply.

Thank you @Philipp Oeser (lichtwerk) ! That line actually changed everything, but it did require a bit more work.

I added the km = km.active, but it caused another problem. My user shortcuts were changed and marked as such (as expected); The add-on shortcuts, however, were changed twice (but were properly marked as modified).

I tried reading what @Brecht Van Lommel (brecht) linked, but my python skills are not very good yet. After removing the part that modifies the add-ons keymap it worked fine. (I believe this is what you meant).

In the end I managed to follow a few tutorials to make my own add-on and uploaded it to Github. Added another functionality to allow users to restore all the keymaps to default. Like I said, my python and add-on scripting skills are not very good, but if you have any suggestions to the code here's the link:

https://github.com/AlienTux/blenderScripts

I wanted to add buttons to the preferences window in the add-on manager, but I couldn't figure out how to do it... I also want to add text inputs so anyone can change the layout to anything they want (like AZERTY, QWERTZ, Coleman, etc).

Thank you both for all your help <3