Skip to content

Commit

Permalink
Fixed unregister/disable bug
Browse files Browse the repository at this point in the history
When the addon was disabled there was a part of the unregister function that looped through some keymaps it was not supposed to, trying to unbind things that the user did not want it to unbind! I've revised the unregister function, and no longer get unexpected behaviour
  • Loading branch information
SpectralVectors authored Sep 26, 2021
1 parent 9b1a36f commit ff4a280
Showing 1 changed file with 19 additions and 22 deletions.
41 changes: 19 additions & 22 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
'name': 'Right Mouse Navigation',
'category': 'View 3D',
'author': 'Spectral Vectors',
'version': (0, 1, 5),
'version': (0, 1, 7),
'blender': (2, 90, 0),
'location': '3D Viewport',
"description": "Enables Right Mouse Viewport Navigation"
Expand Down Expand Up @@ -56,7 +56,7 @@ def register_keymaps():
# "Object Mode", "Mesh", "Curve", "Armature", "Metaball", "Lattice",
# "Font", "Pose"
for i in menumodes:
for key in wm.keyconfigs.user.keymaps[i].keymap_items:
for key in kc.keymaps[i].keymap_items:
if (
key.idname == "wm.call_menu"
and key.type == "RIGHTMOUSE"
Expand All @@ -67,7 +67,7 @@ def register_keymaps():
# These Modes call panels instead of menus
# "Vertex Paint", "Weight Paint", "Image Paint", "Sculpt"
for i in panelmodes:
for key in wm.keyconfigs.user.keymaps[i].keymap_items:
for key in kc.keymaps[i].keymap_items:
if (
key.idname == "wm.call_panel"
and key.type == "RIGHTMOUSE"
Expand All @@ -76,14 +76,14 @@ def register_keymaps():
key.active = False

# Changing the Walk Modal Map
for key in wm.keyconfigs.user.keymaps["View3D Walk Modal"].keymap_items:
for key in kc.keymaps["View3D Walk Modal"].keymap_items:
if (
key.propvalue == "CANCEL"
and key.type == "RIGHTMOUSE"
and key.active
):
key.active = False
for key in wm.keyconfigs.user.keymaps["View3D Walk Modal"].keymap_items:
for key in kc.keymaps["View3D Walk Modal"].keymap_items:
if (
key.propvalue == "CONFIRM"
and key.type == "LEFTMOUSE"
Expand All @@ -102,9 +102,6 @@ def unregister():
wm = bpy.context.window_manager
kc = wm.keyconfigs.user

for km, kmi in addon_keymaps:
km.keymap_items.remove(kmi)
wm.keyconfigs.user.keymaps.remove(km)
addon_keymaps.clear()

menumodes = ["Object Mode", "Mesh", "Curve", "Armature", "Metaball", "Lattice", "Font", "Pose"]
Expand All @@ -114,31 +111,31 @@ def unregister():
# "Object Mode", "Mesh", "Curve", "Armature", "Metaball", "Lattice",
# "Font", "Pose"
for i in menumodes:
for key in wm.keyconfigs.user.keymaps[i].keymap_items:
if (
key.idname == "wm.call_menu"
and key.type == "RIGHTMOUSE"
):
key.active = True
for key in kc.keymaps[i].keymap_items:
if (
key.idname == "wm.call_menu"
):
key.type = "RIGHTMOUSE"
key.active = True

# Reactivating panels
# "Vertex Paint", "Weight Paint", "Image Paint", "Sculpt"
for i in panelmodes:
for key in wm.keyconfigs.user.keymaps[i].keymap_items:
if (
key.idname == "wm.call_panel"
and key.type == "RIGHTMOUSE"
):
key.active = True
for key in kc.keymaps[i].keymap_items:
if (
key.idname == "wm.call_panel"
):
key.type = "RIGHTMOUSE"
key.active = True

# Changing the Walk Modal Map back
for key in wm.keyconfigs.user.keymaps["View3D Walk Modal"].keymap_items:
for key in kc.keymaps["View3D Walk Modal"].keymap_items:
if (
key.propvalue == "CANCEL"
and key.type == "RIGHTMOUSE"
):
key.active = True
for key in wm.keyconfigs.user.keymaps["View3D Walk Modal"].keymap_items:
for key in kc.keymaps["View3D Walk Modal"].keymap_items:
if (
key.propvalue == "CONFIRM"
and key.type == "RIGHTMOUSE"
Expand Down

0 comments on commit ff4a280

Please sign in to comment.