made scripts pass the pep8 test (though not fully pep8 yet)
[blender-staging.git] / release / scripts / ui / properties_data_bone.py
1 # This software is distributable under the terms of the GNU
2 # General Public License (GPL) v2, the text of which can be found at
3 # http://www.gnu.org/copyleft/gpl.html. Installing, importing or otherwise
4 # using this module constitutes acceptance of the terms of this License.
5
6 # <pep8 compliant>
7 import bpy
8
9
10 class BoneButtonsPanel(bpy.types.Panel):
11     bl_space_type = 'PROPERTIES'
12     bl_region_type = 'WINDOW'
13     bl_context = "bone"
14
15     def poll(self, context):
16         return (context.bone or context.edit_bone)
17
18
19 class BONE_PT_context_bone(BoneButtonsPanel):
20     bl_label = ""
21     bl_show_header = False
22
23     def draw(self, context):
24         layout = self.layout
25
26         bone = context.bone
27         if not bone:
28             bone = context.edit_bone
29
30         row = layout.row()
31         row.itemL(text="", icon='ICON_BONE_DATA')
32         row.itemR(bone, "name", text="")
33
34
35 class BONE_PT_transform(BoneButtonsPanel):
36     bl_label = "Transform"
37
38     def draw(self, context):
39         layout = self.layout
40
41         ob = context.object
42         bone = context.bone
43         if not bone:
44             bone = context.edit_bone
45
46             row = layout.row()
47             row.column().itemR(bone, "head")
48             row.column().itemR(bone, "tail")
49
50             col = row.column()
51             sub = col.column(align=True)
52             sub.itemL(text="Roll:")
53             sub.itemR(bone, "roll", text="")
54             sub.itemL()
55             sub.itemR(bone, "locked")
56
57         else:
58             pchan = ob.pose.pose_channels[context.bone.name]
59
60             row = layout.row()
61             col = row.column()
62             col.itemR(pchan, "location")
63             col.active = not (bone.parent and bone.connected)
64
65             col = row.column()
66             if pchan.rotation_mode == 'QUATERNION':
67                 col.itemR(pchan, "rotation_quaternion", text="Rotation")
68             elif pchan.rotation_mode == 'AXIS_ANGLE':
69                 #col.itemL(text="Rotation")
70                 #col.itemR(pchan, "rotation_angle", text="Angle")
71                 #col.itemR(pchan, "rotation_axis", text="Axis")
72                 col.itemR(pchan, "rotation_axis_angle", text="Rotation")
73             else:
74                 col.itemR(pchan, "rotation_euler", text="Rotation")
75
76             row.column().itemR(pchan, "scale")
77
78             layout.itemR(pchan, "rotation_mode")
79
80
81 class BONE_PT_transform_locks(BoneButtonsPanel):
82     bl_label = "Transform Locks"
83     bl_default_closed = True
84
85     def poll(self, context):
86         return context.bone
87
88     def draw(self, context):
89         layout = self.layout
90
91         ob = context.object
92         bone = context.bone
93         pchan = ob.pose.pose_channels[context.bone.name]
94
95         row = layout.row()
96         col = row.column()
97         col.itemR(pchan, "lock_location")
98         col.active = not (bone.parent and bone.connected)
99
100         col = row.column()
101         if pchan.rotation_mode in ('QUATERNION', 'AXIS_ANGLE'):
102             col.itemR(pchan, "lock_rotations_4d", text="Lock Rotation")
103             if pchan.lock_rotations_4d:
104                 col.itemR(pchan, "lock_rotation_w", text="W")
105             col.itemR(pchan, "lock_rotation", text="")
106         else:
107             col.itemR(pchan, "lock_rotation", text="Rotation")
108
109         row.column().itemR(pchan, "lock_scale")
110
111
112 class BONE_PT_relations(BoneButtonsPanel):
113     bl_label = "Relations"
114
115     def draw(self, context):
116         layout = self.layout
117
118         ob = context.object
119         bone = context.bone
120         arm = context.armature
121
122         if not bone:
123             bone = context.edit_bone
124             pchan = None
125         else:
126             pchan = ob.pose.pose_channels[context.bone.name]
127
128         split = layout.split()
129
130         col = split.column()
131         col.itemL(text="Layers:")
132         col.itemR(bone, "layer", text="")
133
134         col.itemS()
135
136         if ob and pchan:
137             col.itemL(text="Bone Group:")
138             col.item_pointerR(pchan, "bone_group", ob.pose, "bone_groups", text="")
139
140         col = split.column()
141         col.itemL(text="Parent:")
142         if context.bone:
143             col.itemR(bone, "parent", text="")
144         else:
145             col.item_pointerR(bone, "parent", arm, "edit_bones", text="")
146
147         sub = col.column()
148         sub.active = bone.parent != None
149         sub.itemR(bone, "connected")
150         sub.itemR(bone, "hinge", text="Inherit Rotation")
151         sub.itemR(bone, "inherit_scale", text="Inherit Scale")
152
153
154 class BONE_PT_display(BoneButtonsPanel):
155     bl_label = "Display"
156
157     def poll(self, context):
158         return context.bone
159
160     def draw(self, context):
161         layout = self.layout
162
163         ob = context.object
164         bone = context.bone
165         arm = context.armature
166
167         if not bone:
168             bone = context.edit_bone
169             pchan = None
170         else:
171             pchan = ob.pose.pose_channels[context.bone.name]
172
173         if ob and pchan:
174
175             split = layout.split()
176
177             col = split.column()
178
179             col.itemR(bone, "draw_wire", text="Wireframe")
180             col.itemR(bone, "hidden", text="Hide")
181
182             col = split.column()
183
184             col.itemL(text="Custom Shape:")
185             col.itemR(pchan, "custom_shape", text="")
186
187
188 class BONE_PT_deform(BoneButtonsPanel):
189     bl_label = "Deform"
190     bl_default_closed = True
191
192     def draw_header(self, context):
193         bone = context.bone
194
195         if not bone:
196             bone = context.edit_bone
197
198         self.layout.itemR(bone, "deform", text="")
199
200     def draw(self, context):
201         layout = self.layout
202
203         bone = context.bone
204
205         if not bone:
206             bone = context.edit_bone
207
208         layout.active = bone.deform
209
210         split = layout.split()
211
212         col = split.column()
213         col.itemL(text="Envelope:")
214
215         sub = col.column(align=True)
216         sub.itemR(bone, "envelope_distance", text="Distance")
217         sub.itemR(bone, "envelope_weight", text="Weight")
218         col.itemR(bone, "multiply_vertexgroup_with_envelope", text="Multiply")
219
220         sub = col.column(align=True)
221         sub.itemL(text="Radius:")
222         sub.itemR(bone, "head_radius", text="Head")
223         sub.itemR(bone, "tail_radius", text="Tail")
224
225         col = split.column()
226         col.itemL(text="Curved Bones:")
227
228         sub = col.column(align=True)
229         sub.itemR(bone, "bbone_segments", text="Segments")
230         sub.itemR(bone, "bbone_in", text="Ease In")
231         sub.itemR(bone, "bbone_out", text="Ease Out")
232
233         col.itemL(text="Offset:")
234         col.itemR(bone, "cyclic_offset")
235
236 bpy.types.register(BONE_PT_context_bone)
237 bpy.types.register(BONE_PT_transform)
238 bpy.types.register(BONE_PT_transform_locks)
239 bpy.types.register(BONE_PT_relations)
240 bpy.types.register(BONE_PT_display)
241 bpy.types.register(BONE_PT_deform)