-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathpreferences.py
160 lines (125 loc) · 5.06 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import bpy
from rna_keymap_ui import _indented_layout
from .keymap import PREFIX
KEYMAP_NAME = '3D View Generic'
def get_lightpainter_kmi(context):
"""Get all keymap items for Light Painter."""
keymap = context.window_manager.keyconfigs.user.keymaps[KEYMAP_NAME]
return tuple(
item
for item in keymap.keymap_items
if (
item.idname == 'wm.call_menu' and
item.properties and
hasattr(item.properties, 'name') and
item.properties.name.startswith(PREFIX)
)
)
class VIEW3D_AddonPreferences(bpy.types.AddonPreferences):
bl_idname = __package__
keymap_overlay: bpy.props.BoolProperty(
name='Shortcuts Overlay',
default=True,
description='Show keymap in 3D view while using Light Painter tools (if there is enough space)',
)
keymap_header: bpy.props.BoolProperty(
name='Shortcuts in 3D view header',
default=False,
description='Show keymap in 3D view header while using Light Painter tools',
)
keymap_status_bar: bpy.props.BoolProperty(
name='Shortcuts in status bar',
default=True,
description='Show keymap in status bar while using Light Painter tools',
)
overlay_position: bpy.props.EnumProperty(
name='Overlay Position',
description='Position of overlay in the 3D view',
items=(
('LEFT', 'Left', 'Bottom left corner'),
('CENTER', 'Center', 'Bottom center'),
('RIGHT', 'Right', 'Bottom right corner'),
),
default='CENTER',
)
overlay_font_scale: bpy.props.FloatProperty(
name='Overlay Font Scale',
description='Multiplier of font scale used in the overlay',
default=10.0,
min=5.0,
precision=1,
)
def draw(self, context):
layout = self.layout
layout.use_property_split = True
layout.use_property_decorate = False
layout.label(text='Tools Keymap')
col = layout.column(align=True, heading='Display')
col.prop(self, 'keymap_header', text='3D View Header')
col.prop(self, 'keymap_status_bar', text='Status Bar')
col.prop(self, 'keymap_overlay', text='Overlay')
col = layout.column()
col.active = self.keymap_overlay
col.prop(self, 'overlay_position')
col.prop(self, 'overlay_font_scale', text='Scale')
col = layout.column()
keymap = context.window_manager.keyconfigs.user.keymaps[KEYMAP_NAME]
light_painter_kmi = get_lightpainter_kmi(context)
for item in light_painter_kmi:
self.draw_item(context, col, item, keymap)
def draw_item(self, context, layout, item, keymap):
map_type = item.map_type
col = _indented_layout(layout, 0)
if item.show_expanded:
col = col.column(align=True)
box = col.box()
else:
box = col.column()
split = box.split()
# header bar
row = split.row(align=True)
row.prop(item, 'show_expanded', text='', emboss=False)
proper_name = item.properties.name.replace(PREFIX, '').replace('_', ' ').title()
row.label(text=proper_name)
row = split.row()
row.prop(item, 'map_type', text='')
if map_type in {'KEYBOARD', 'MOUSE', 'NDOF'}:
row.prop(item, 'type', text='', full_event=True)
elif map_type == 'TWEAK':
subrow = row.row()
subrow.prop(item, 'type', text='')
subrow.prop(item, 'value', text='')
elif map_type == 'TIMER':
row.prop(item, 'type', text='')
else:
row.label()
if item.is_user_modified:
row.context_pointer_set('keymap', keymap) # for 'keyitem_restore'
row.operator('preferences.keyitem_restore', text='', icon='BACK').item_id = item.id
# Expanded, additional event settings
if not item.show_expanded:
return
box = col.box()
split = box.split(factor=0.4)
sub = split.row()
# sub.prop(item, 'idname', text='')
if map_type not in {'TEXTINPUT', 'TIMER'}:
sub = split.column()
subrow = sub.row(align=True)
if map_type == 'KEYBOARD':
subrow.prop(item, 'type', text='', event=True)
subrow.prop(item, 'value', text='')
elif map_type in {'MOUSE', 'NDOF'}:
subrow.prop(item, 'type', text='')
subrow.prop(item, 'value', text='')
if map_type in {'KEYBOARD', 'MOUSE'} and item.value == 'CLICK_DRAG':
subrow = sub.row()
subrow.prop(item, 'direction')
subrow = sub.row()
subrow.scale_x = 0.75
subrow.prop(item, 'any', toggle=True)
# Use `*_ui` properties as integers aren't practical
subrow.prop(item, 'shift_ui', toggle=True)
subrow.prop(item, 'ctrl_ui', toggle=True)
subrow.prop(item, 'alt_ui', toggle=True)
subrow.prop(item, 'oskey_ui', text='Cmd', toggle=True)