-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathPreferences.py
144 lines (119 loc) · 4.62 KB
/
Preferences.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import bpy
from bpy.props import (
BoolProperty,
FloatProperty,
)
from bpy.types import AddonPreferences
def update_node_keymap(self, context):
wm = context.window_manager
active_kc = wm.keyconfigs.active
for key in active_kc.keymaps["Node Editor"].keymap_items:
if key.idname == "wm.call_menu" and key.type == "RIGHTMOUSE":
key.active = not key.active
addon_kc = wm.keyconfigs.addon
for key in addon_kc.keymaps["Node Editor"].keymap_items:
if key.idname == "rmn.right_mouse_navigation" and key.type == "RIGHTMOUSE":
key.active = not key.active
class RightMouseNavigationPreferences(AddonPreferences):
bl_idname = __package__
time: FloatProperty(
name="Time Threshold",
description="How long you have hold right mouse to open menu",
default=1.0,
min=0.1,
max=10,
)
reset_cursor_on_exit: BoolProperty(
name="Reset Cursor on Exit",
description="After exiting navigation, this determines if the cursor stays "
"where RMB was clicked (if unchecked) or resets to the center (if checked)",
default=False,
)
return_to_ortho_on_exit: BoolProperty(
name="Return to Orthographic on Exit",
description="After exiting navigation, this determines if the Viewport "
"returns to Orthographic view (if checked) or remains in Perspective view (if unchecked)",
default=True,
)
enable_for_node_editors: BoolProperty(
name="Enable for Node Editors",
description="Right Mouse will pan the view / open the Node Add/Search Menu",
default=False,
update=update_node_keymap,
)
disable_camera_navigation: BoolProperty(
name="Disable Navigation for Camera View",
description="Enable if you only want to navigate your scene, and not affect Camera Transform",
default=False,
)
def draw(self, context):
layout = self.layout
row = layout.row()
box = row.box()
box.label(text="Menu / Movement", icon="DRIVER_DISTANCE")
box.prop(self, "time")
box = row.box()
box.label(text="Node Editor", icon="NODETREE")
box.prop(self, "enable_for_node_editors")
row = layout.row()
box = row.box()
box.label(text="Cursor", icon="ORIENTATION_CURSOR")
box.prop(self, "reset_cursor_on_exit")
box = row.box()
box.label(text="View", icon="VIEW3D")
box.prop(self, "return_to_ortho_on_exit")
row = layout.row()
box = row.box()
box.label(text="Camera", icon="CAMERA_DATA")
box.prop(self, "disable_camera_navigation")
# Keymap Customization
import rna_keymap_ui
nav_names = [
"FORWARD",
"FORWARD_STOP",
"BACKWARD",
"BACKWARD_STOP",
"LEFT",
"LEFT_STOP",
"RIGHT",
"RIGHT_STOP",
"UP",
"UP_STOP",
"DOWN",
"DOWN_STOP",
"LOCAL_UP",
"LOCAL_UP_STOP",
"LOCAL_DOWN",
"LOCAL_DOWN_STOP",
]
wm = bpy.context.window_manager
active_kc = wm.keyconfigs.active
addon_keymaps = []
walk_km = active_kc.keymaps["View3D Walk Modal"]
for key in walk_km.keymap_items:
addon_keymaps.append((walk_km, key))
header, panel = layout.panel(idname="keymap", default_closed=True)
header.label(text="Navigation Keymap")
wm = bpy.context.window_manager
kc = wm.keyconfigs.user
old_km_name = ""
get_kmi_l = []
for km_add, kmi_add in addon_keymaps:
for km_con in kc.keymaps:
if km_add.name == km_con.name:
km = km_con
break
for kmi_con in km.keymap_items:
if kmi_add.idname == kmi_con.idname:
if kmi_add.name == kmi_con.name and kmi_con.propvalue in nav_names:
get_kmi_l.append((km, kmi_con))
get_kmi_l = sorted(set(get_kmi_l), key=get_kmi_l.index)
if panel:
col = panel.column(align=True)
for km, kmi in get_kmi_l:
if not km.name == old_km_name:
col.label(text=str(km.name), icon="DOT")
col.context_pointer_set("keymap", km)
rna_keymap_ui.draw_kmi([], kc, km, kmi, col, 0)
col.separator()
old_km_name = km.name