forked from wheybags/freeablo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
proportional_menu.py
160 lines (117 loc) · 5.53 KB
/
proportional_menu.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
from .Utils.core import *
# adds a proportional mode menu
class ProportionalModeOperator(bpy.types.Operator):
bl_label = "Proportional Mode Operator"
bl_idname = "view3d.proportional_menu_operator"
last_mode = ['DISABLED', 'ENABLED']
def init(self, context):
if context.space_data.type == 'DOPESHEET_EDITOR':
if context.tool_settings.use_proportional_action == False:
context.tool_settings.use_proportional_action = True
else:
context.tool_settings.use_proportional_action = False
return {'FINISHED'}
if context.space_data.type == 'GRAPH_EDITOR':
if context.tool_settings.use_proportional_fcurve == False:
context.tool_settings.use_proportional_fcurve = True
else:
context.tool_settings.use_proportional_fcurve = False
return {'FINISHED'}
if context.space_data.type == 'IMAGE_EDITOR':
if context.space_data.show_maskedit:
if context.tool_settings.use_proportional_edit_mask == False:
context.tool_settings.use_proportional_edit_mask = True
else:
context.tool_settings.use_proportional_edit_mask = False
return {'FINISHED'}
if get_mode() == 'OBJECT':
if context.tool_settings.use_proportional_edit_objects == False:
context.tool_settings.use_proportional_edit_objects = True
else:
context.tool_settings.use_proportional_edit_objects = False
return {'FINISHED'}
# populate the list of last modes
if context.tool_settings.proportional_edit not in self.last_mode:
self.last_mode.append(context.tool_settings.proportional_edit)
# keep the list to 2 items
if len(self.last_mode) > 2:
del self.last_mode[1]
def modal(self, context, event):
current_time = time.time()
# if key has been held for more than 0.3 seconds call the menu
if event.value == 'RELEASE' and current_time > self.start_time + 0.3:
bpy.ops.wm.call_menu(name=ProportionalEditingMenu.bl_idname)
return {'FINISHED'}
# else toggle between off and your last used mode
elif event.value == 'RELEASE' and current_time < self.start_time + 0.3:
if context.tool_settings.proportional_edit != self.last_mode[0]:
context.tool_settings.proportional_edit = self.last_mode[0]
else:
context.tool_settings.proportional_edit = self.last_mode[1]
return {'FINISHED'}
return {'RUNNING_MODAL'}
def execute(self, context):
self.init(context)
self.start_time = time.time()
context.window_manager.modal_handler_add(self)
return {'RUNNING_MODAL'}
class ProportionalEditingMenu(bpy.types.Menu):
bl_label = "Proportional"
bl_idname = "VIEW3D_MT_proportional_menu"
@classmethod
def poll(self, context):
if get_mode() in [edit, particle_edit, gpencil_edit]:
return True
else:
return False
def draw(self, context):
menu = Menu(self)
# add the items to the menu
for mode in context.tool_settings.bl_rna.properties['proportional_edit'].enum_items:
menuprop(menu.add_item(), mode.name, mode.identifier, "tool_settings.proportional_edit",
icon=mode.icon, disable=True)
class FalloffMenu(bpy.types.Menu):
bl_label = "Falloff Menu"
bl_idname = "VIEW3D_MT_falloff_menu"
@classmethod
def poll(self, context):
if get_mode() in [object_mode, edit, particle_edit, gpencil_edit]:
return True
else:
return False
def draw(self, context):
menu = Menu(self)
# add the items to the menu
for mode in context.tool_settings.bl_rna.properties['proportional_edit_falloff'].enum_items:
menuprop(menu.add_item(), mode.name, mode.identifier, "tool_settings.proportional_edit_falloff",
icon=mode.icon, disable=True)
### ------------ New hotkeys and registration ------------ ###
addon_keymaps = []
def register():
# create the global menu hotkeys
wm = bpy.context.window_manager
modes = {'Object Mode':'EMPTY',
'Mesh':'EMPTY',
'Curve':'EMPTY',
'Armature':'EMPTY',
'Metaball':'EMPTY',
'Lattice':'EMPTY',
'Particle':'EMPTY',
'Object Non-modal':'EMPTY',
'Graph Editor':'GRAPH_EDITOR',
'Dopesheet':'DOPESHEET_EDITOR',
'UV Editor':'EMPTY',
'Grease Pencil Stroke Edit Mode':'EMPTY',
'Mask Editing':'EMPTY'}
for mode, space in modes.items():
km = wm.keyconfigs.addon.keymaps.new(name=mode, space_type=space)
kmi = km.keymap_items.new('view3d.proportional_menu_operator', 'O', 'PRESS')
addon_keymaps.append((km, kmi))
kmi = km.keymap_items.new('wm.call_menu', 'O', 'PRESS', shift=True)
kmi.properties.name = 'VIEW3D_MT_falloff_menu'
addon_keymaps.append((km, kmi))
def unregister():
# remove keymaps when add-on is deactivated
for km, kmi in addon_keymaps:
km.keymap_items.remove(kmi)
addon_keymaps.clear()