Changing keymap with a script doesn't trigger the "is_user_modified" flag #79657

Closed
opened 2020-08-09 02:38:11 +02:00 by Kurt Kellner · 11 comments

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:

beforeRunningScript.png

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

afterRunningScript.png

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.dvorak_script.py

**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: ![beforeRunningScript.png](https://archive.blender.org/developer/F8760914/beforeRunningScript.png) Heres is a screenshot of the Blender keymap after running the script: ![afterRunningScript.png](https://archive.blender.org/developer/F8760916/afterRunningScript.png) 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 ](https://github.com/AlienTux/blenderScripts/blob/master/dvorak_script.py) 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.[dvorak_script.py](https://archive.blender.org/developer/F8760948/dvorak_script.py)
Author

Added subscriber: @AlienTux

Added subscriber: @AlienTux

This issue was referenced by blender/blender@ada98869df

This issue was referenced by blender/blender@ada98869dfa16272cd7db1c01d33a7002dc38195
Member

Added subscriber: @lichtwerk

Added subscriber: @lichtwerk
Member

Changed status from 'Needs Triage' to: 'Confirmed'

Changed status from 'Needs Triage' to: 'Confirmed'
Member

Can confirm, will check on this...

Can confirm, will check on this...
Member

Changed status from 'Confirmed' to: 'Needs User Info'

Changed status from 'Confirmed' to: 'Needs User Info'
Member

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?

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?

Added subscriber: @brecht

Added subscriber: @brecht

Changed status from 'Needs User Info' to: 'Archived'

Changed status from 'Needs User Info' to: 'Archived'
Brecht Van Lommel self-assigned this 2020-08-12 16:59:13 +02:00

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.

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.
Author

I apologize for the late reply.

Thank you @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 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

I apologize for the late reply. Thank you @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 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
Sign in to join this conversation.
No Milestone
No project
No Assignees
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender-addons#79657
No description provided.