-
Notifications
You must be signed in to change notification settings - Fork 3
/
panels.py
131 lines (104 loc) · 4.51 KB
/
panels.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
import bpy
import bpy.utils.previews
from .functions import (
recurLayerCollection,
preview_collections,
createPreviewCollection,
get_preview_default,
)
from .menus import BONEWIDGET_MT_bw_specials
class BONEWIDGET_PT_bw_panel:
"""BoneWidget Addon UI"""
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_category = "Rigging"
bl_label = "Bone Widget"
class BONEWIDGET_PT_bw_panel_main(BONEWIDGET_PT_bw_panel, bpy.types.Panel):
bl_idname = 'BONEWIDGET_PT_bw_panel_main'
bl_label = "Bone Widget"
createPreviewCollection()
def draw(self, context):
layout = self.layout
# preview toggle checkbox
row = layout.row(align=True)
row.prop(context.window_manager, "toggle_preview")
# preview view
if context.window_manager.toggle_preview:
row = layout.row(align=True)
preview_panel_size = context.preferences.addons[__package__].preferences.preview_panel_size
preview_popup_size = context.preferences.addons[__package__].preferences.preview_popup_size
row.template_icon_view(context.window_manager, "widget_list", show_labels=True,
scale=preview_panel_size, scale_popup=preview_popup_size)
# dropdown list
row = layout.row(align=True)
row.prop(context.window_manager, "widget_list", expand=False, text="")
row = layout.row(align=True)
row.menu("BONEWIDGET_MT_bw_specials", icon='DOWNARROW_HLT', text="")
row.operator("bonewidget.create_widget", icon="OBJECT_DATAMODE")
if bpy.context.mode == "POSE":
row.operator("bonewidget.edit_widget", icon="OUTLINER_DATA_MESH")
else:
row.operator("bonewidget.return_to_armature", icon="LOOP_BACK", text='To bone')
layout = self.layout
layout.separator()
layout.operator("bonewidget.symmetrize_shape", icon='MOD_MIRROR', text="Symmetrize Shape")
layout.operator("bonewidget.match_bone_transforms",
icon='GROUP_BONE', text="Match Bone Transforms")
layout.operator("bonewidget.resync_widget_names",
icon='FILE_REFRESH', text="Resync Widget Names")
layout.separator()
layout.operator("bonewidget.clear_widgets",
icon='X', text="Clear Bone Widget")
layout.operator("bonewidget.delete_unused_widgets",
icon='TRASH', text="Delete Unused Widgets")
if bpy.context.mode == 'POSE':
layout.operator("bonewidget.add_as_widget",
text="Use Selected Object",
icon='RESTRICT_SELECT_OFF')
# if the bw collection exists, show the visibility toggle
if not context.preferences.addons[__package__].preferences.use_rigify_defaults: #rigify
bw_collection_name = context.preferences.addons[__package__].preferences.bonewidget_collection_name
elif context.active_object: # active object
bw_collection_name = 'WGTS_' + context.active_object.name
else: # this is needed because sometimes there is no active object
bw_collection_name = None
bw_collection = recurLayerCollection(bpy.context.view_layer.layer_collection, bw_collection_name)
if bw_collection is not None:
if bw_collection.hide_viewport:
icon = "HIDE_ON"
text = "Show Collection"
else:
icon = "HIDE_OFF"
text = "Hide Collection"
row = layout.row()
row.separator()
row = layout.row()
row.operator("bonewidget.toggle_collection_visibilty",
icon=icon, text=text)
classes = (
BONEWIDGET_PT_bw_panel_main,
)
def register():
bpy.types.WindowManager.toggle_preview = bpy.props.BoolProperty(
name="Preview Panel",
default=get_preview_default(),
description="Show thumbnail previews"
)
from bpy.utils import register_class
for cls in classes:
try:
register_class(cls)
except:
pass
def unregister():
del bpy.types.WindowManager.widget_list
del bpy.types.WindowManager.toggle_preview
for pcoll in preview_collections.values():
bpy.utils.previews.remove(pcoll)
preview_collections.clear()
from bpy.utils import unregister_class
for cls in classes:
try:
unregister_class(cls)
except:
pass