77from .preferences import RightMouseNavigationPreferences
88
99addon_keymaps = []
10+ menumodes = [
11+ "Object Mode" ,
12+ "Mesh" ,
13+ "Curve" ,
14+ "Armature" ,
15+ "Metaball" ,
16+ "Lattice" ,
17+ "Font" ,
18+ "Pose" ,
19+ ]
20+ panelmodes = [
21+ "Vertex Paint" ,
22+ "Weight Paint" ,
23+ "Image Paint" ,
24+ "Sculpt" ,
25+ ]
1026classes = [
1127 RightMouseNavigationPreferences ,
1228 RMN_OT_right_mouse_navigation ,
1329 RMN_OT_toggle_cam_navigation ,
1430]
1531
1632
33+ def register_keymaps (menumodes , panelmodes , keyconfig ):
34+ # These Modes all call standard menus
35+ # "Object Mode", "Mesh", "Curve", "Armature", "Metaball", "Lattice",
36+ # "Font", "Pose"
37+ for i in menumodes :
38+ for key in keyconfig .keymaps [i ].keymap_items :
39+ if (
40+ # key.idname == "wm.call_menu"
41+ key .type == "RIGHTMOUSE"
42+ and key .active
43+ ):
44+ key .active = False
45+
46+ # These Modes call panels instead of menus
47+ # "Vertex Paint", "Weight Paint", "Image Paint", "Sculpt"
48+ for i in panelmodes :
49+ for key in keyconfig .keymaps [i ].keymap_items :
50+ if key .idname == "wm.call_panel" and key .type == "RIGHTMOUSE" and key .active :
51+ key .active = False
52+
53+ # Changing the Walk Modal Map
54+ for key in keyconfig .keymaps ["View3D Walk Modal" ].keymap_items :
55+ if key .propvalue == "CANCEL" and key .type == "RIGHTMOUSE" and key .active :
56+ key .active = False
57+ for key in keyconfig .keymaps ["View3D Walk Modal" ].keymap_items :
58+ if key .propvalue == "CONFIRM" and key .type == "LEFTMOUSE" and key .active :
59+ key .type = "RIGHTMOUSE"
60+ key .value = "RELEASE"
61+
62+
63+ def unregister_keymaps (menumodes , panelmodes , keyconfig ):
64+ # Reactivating menus
65+ # "Object Mode", "Mesh", "Curve", "Armature", "Metaball", "Lattice",
66+ # "Font", "Pose"
67+ for i in menumodes :
68+ for key in keyconfig .keymaps [i ].keymap_items :
69+ if key .idname == "wm.call_menu" and key .type == "RIGHTMOUSE" :
70+ key .active = True
71+
72+ # Reactivating panels
73+ # "Vertex Paint", "Weight Paint", "Image Paint", "Sculpt"
74+ for i in panelmodes :
75+ for key in keyconfig .keymaps [i ].keymap_items :
76+ if key .idname == "wm.call_panel" and key .type == "RIGHTMOUSE" :
77+ key .active = True
78+
79+ # Changing the Walk Modal Map back
80+ for key in keyconfig .keymaps ["View3D Walk Modal" ].keymap_items :
81+ if key .propvalue == "CANCEL" and key .type == "RIGHTMOUSE" :
82+ key .active = True
83+ for key in keyconfig .keymaps ["View3D Walk Modal" ].keymap_items :
84+ if key .propvalue == "CONFIRM" and key .type == "RIGHTMOUSE" :
85+ key .type = "LEFTMOUSE"
86+ key .value = "PRESS"
87+
88+
1789def register ():
1890 if not bpy .app .background :
1991 for cls in classes :
@@ -47,56 +119,28 @@ def register():
47119 addon_keymaps .append ((km , kmi ))
48120 addon_keymaps .append ((km2 , kmi2 ))
49121
50- active_kc = wm .keyconfigs .active
51-
52- menumodes = [
53- "Object Mode" ,
54- "Mesh" ,
55- "Curve" ,
56- "Armature" ,
57- "Metaball" ,
58- "Lattice" ,
59- "Font" ,
60- "Pose" ,
61- ]
62- panelmodes = [
63- "Vertex Paint" ,
64- "Weight Paint" ,
65- "Image Paint" ,
66- "Sculpt" ,
67- ]
68-
69- # These Modes all call standard menus
70- # "Object Mode", "Mesh", "Curve", "Armature", "Metaball", "Lattice",
71- # "Font", "Pose"
72- for i in menumodes :
73- for key in active_kc .keymaps [i ].keymap_items :
74- if (
75- # key.idname == "wm.call_menu"
76- key .type == "RIGHTMOUSE"
77- and key .active
78- ):
79- key .active = False
80-
81- # These Modes call panels instead of menus
82- # "Vertex Paint", "Weight Paint", "Image Paint", "Sculpt"
83- for i in panelmodes :
84- for key in active_kc .keymaps [i ].keymap_items :
85- if (
86- key .idname == "wm.call_panel"
87- and key .type == "RIGHTMOUSE"
88- and key .active
89- ):
90- key .active = False
91-
92- # Changing the Walk Modal Map
93- for key in active_kc .keymaps ["View3D Walk Modal" ].keymap_items :
94- if key .propvalue == "CANCEL" and key .type == "RIGHTMOUSE" and key .active :
95- key .active = False
96- for key in active_kc .keymaps ["View3D Walk Modal" ].keymap_items :
97- if key .propvalue == "CONFIRM" and key .type == "LEFTMOUSE" and key .active :
98- key .type = "RIGHTMOUSE"
99- key .value = "RELEASE"
122+ active_keyconfig = wm .keyconfigs .active
123+ blender_keyconfig = wm .keyconfigs ["Blender" ]
124+ user_keyconfig = wm .keyconfigs ["Blender user" ]
125+
126+ try :
127+ register_keymaps (
128+ menumodes = menumodes ,
129+ panelmodes = panelmodes ,
130+ keyconfig = active_keyconfig ,
131+ )
132+ except :
133+ register_keymaps (
134+ menumodes = menumodes ,
135+ panelmodes = panelmodes ,
136+ keyconfig = blender_keyconfig ,
137+ )
138+ finally :
139+ register_keymaps (
140+ menumodes = menumodes ,
141+ panelmodes = panelmodes ,
142+ keyconfig = user_keyconfig ,
143+ )
100144
101145
102146def unregister ():
@@ -105,51 +149,31 @@ def unregister():
105149 bpy .utils .unregister_class (cls )
106150
107151 wm = bpy .context .window_manager
108- active_kc = wm .keyconfigs .active
109- addon_kc = wm .keyconfigs .addon
110152
111- menumodes = [
112- "Object Mode" ,
113- "Mesh" ,
114- "Curve" ,
115- "Armature" ,
116- "Metaball" ,
117- "Lattice" ,
118- "Font" ,
119- "Pose" ,
120- "Node Editor" ,
121- ]
122- panelmodes = [
123- "Vertex Paint" ,
124- "Weight Paint" ,
125- "Image Paint" ,
126- "Sculpt" ,
127- ]
128-
129- # Reactivating menus
130- # "Object Mode", "Mesh", "Curve", "Armature", "Metaball", "Lattice",
131- # "Font", "Pose"
132- for i in menumodes :
133- for key in active_kc .keymaps [i ].keymap_items :
134- if key .idname == "wm.call_menu" and key .type == "RIGHTMOUSE" :
135- key .active = True
136-
137- # Reactivating panels
138- # "Vertex Paint", "Weight Paint", "Image Paint", "Sculpt"
139- for i in panelmodes :
140- for key in active_kc .keymaps [i ].keymap_items :
141- if key .idname == "wm.call_panel" and key .type == "RIGHTMOUSE" :
142- key .active = True
143-
144- # Changing the Walk Modal Map back
145- for key in active_kc .keymaps ["View3D Walk Modal" ].keymap_items :
146- if key .propvalue == "CANCEL" and key .type == "RIGHTMOUSE" :
147- key .active = True
148- for key in active_kc .keymaps ["View3D Walk Modal" ].keymap_items :
149- if key .propvalue == "CONFIRM" and key .type == "RIGHTMOUSE" :
150- key .type = "LEFTMOUSE"
151- key .value = "PRESS"
153+ active_keyconfig = wm .keyconfigs .active
154+ blender_keyconfig = wm .keyconfigs ["Blender" ]
155+ user_keyconfig = wm .keyconfigs ["Blender user" ]
156+
157+ try :
158+ unregister_keymaps (
159+ menumodes = menumodes ,
160+ panelmodes = panelmodes ,
161+ keyconfig = active_keyconfig ,
162+ )
163+ except :
164+ unregister_keymaps (
165+ menumodes = menumodes ,
166+ panelmodes = panelmodes ,
167+ keyconfig = blender_keyconfig ,
168+ )
169+ finally :
170+ unregister_keymaps (
171+ menumodes = menumodes ,
172+ panelmodes = panelmodes ,
173+ keyconfig = user_keyconfig ,
174+ )
152175
176+ addon_kc = wm .keyconfigs .addon
153177 # Remove only the keymap items that this addon registered
154178 for km , kmi_orig in addon_keymaps :
155179 try :
0 commit comments