made scripts pass the pep8 test (though not fully pep8 yet)
[blender.git] / release / scripts / ui / properties_data_mesh.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 DataButtonsPanel(bpy.types.Panel):
11     bl_space_type = 'PROPERTIES'
12     bl_region_type = 'WINDOW'
13     bl_context = "data"
14
15     def poll(self, context):
16         return context.mesh
17
18
19 class DATA_PT_context_mesh(DataButtonsPanel):
20     bl_label = ""
21     bl_show_header = False
22
23     def draw(self, context):
24         layout = self.layout
25
26         ob = context.object
27         mesh = context.mesh
28         space = context.space_data
29
30         split = layout.split(percentage=0.65)
31
32         if ob:
33             split.template_ID(ob, "data")
34             split.itemS()
35         elif mesh:
36             split.template_ID(space, "pin_id")
37             split.itemS()
38
39
40 class DATA_PT_normals(DataButtonsPanel):
41     bl_label = "Normals"
42
43     def draw(self, context):
44         layout = self.layout
45
46         mesh = context.mesh
47
48         split = layout.split()
49
50         col = split.column()
51         col.itemR(mesh, "autosmooth")
52         sub = col.column()
53         sub.active = mesh.autosmooth
54         sub.itemR(mesh, "autosmooth_angle", text="Angle")
55
56         col = split.column()
57         col.itemR(mesh, "vertex_normal_flip")
58         col.itemR(mesh, "double_sided")
59
60
61 class DATA_PT_settings(DataButtonsPanel):
62     bl_label = "Settings"
63
64     def draw(self, context):
65         layout = self.layout
66
67         mesh = context.mesh
68
69         split = layout.split()
70
71         col = split.column()
72         col.itemR(mesh, "texture_mesh")
73
74
75 class DATA_PT_vertex_groups(DataButtonsPanel):
76     bl_label = "Vertex Groups"
77
78     def poll(self, context):
79         return (context.object and context.object.type in ('MESH', 'LATTICE'))
80
81     def draw(self, context):
82         layout = self.layout
83
84         ob = context.object
85         group = ob.active_vertex_group
86
87         rows = 2
88         if group:
89             rows = 5
90
91         row = layout.row()
92         row.template_list(ob, "vertex_groups", ob, "active_vertex_group_index", rows=rows)
93
94         col = row.column(align=True)
95         col.itemO("object.vertex_group_add", icon='ICON_ZOOMIN', text="")
96         col.itemO("object.vertex_group_remove", icon='ICON_ZOOMOUT', text="")
97
98         col.itemO("object.vertex_group_copy", icon='ICON_COPY_ID', text="")
99         if ob.data.users > 1:
100             col.itemO("object.vertex_group_copy_to_linked", icon='ICON_LINK_AREA', text="")
101
102         if group:
103             row = layout.row()
104             row.itemR(group, "name")
105
106         if ob.mode == 'EDIT' and len(ob.vertex_groups) > 0:
107             row = layout.row()
108
109             sub = row.row(align=True)
110             sub.itemO("object.vertex_group_assign", text="Assign")
111             sub.itemO("object.vertex_group_remove_from", text="Remove")
112
113             sub = row.row(align=True)
114             sub.itemO("object.vertex_group_select", text="Select")
115             sub.itemO("object.vertex_group_deselect", text="Deselect")
116
117             layout.itemR(context.tool_settings, "vertex_group_weight", text="Weight")
118
119
120 class DATA_PT_shape_keys(DataButtonsPanel):
121     bl_label = "Shape Keys"
122
123     def poll(self, context):
124         return (context.object and context.object.type in ('MESH', 'LATTICE', 'CURVE', 'SURFACE'))
125
126     def draw(self, context):
127         layout = self.layout
128
129         ob = context.object
130         key = ob.data.shape_keys
131         kb = ob.active_shape_key
132
133         enable_edit = ob.mode != 'EDIT'
134         enable_edit_value = False
135
136         if ob.shape_key_lock == False:
137             if enable_edit or (ob.type == 'MESH' and ob.shape_key_edit_mode):
138                 enable_edit_value = True
139
140         row = layout.row()
141
142         rows = 2
143         if kb:
144             rows = 5
145         row.template_list(key, "keys", ob, "active_shape_key_index", rows=rows)
146
147         col = row.column()
148
149         subcol = col.column(align=True)
150         subcol.itemO("object.shape_key_add", icon='ICON_ZOOMIN', text="")
151         subcol.itemO("object.shape_key_remove", icon='ICON_ZOOMOUT', text="")
152
153         if kb:
154             col.itemS()
155
156             subcol = col.column(align=True)
157             subcol.item_enumO("object.shape_key_move", "type", 'UP', icon='ICON_TRIA_UP', text="")
158             subcol.item_enumO("object.shape_key_move", "type", 'DOWN', icon='ICON_TRIA_DOWN', text="")
159
160             split = layout.split(percentage=0.4)
161             sub = split.row()
162             sub.enabled = enable_edit
163             sub.itemR(key, "relative")
164
165             sub = split.row()
166             sub.alignment = 'RIGHT'
167
168             subrow = sub.row(align=True)
169             subrow.active = enable_edit_value
170             subrow.itemR(ob, "shape_key_lock", icon='ICON_UNPINNED', text="")
171             subrow.itemR(kb, "mute", icon='ICON_MUTE_IPO_OFF', text="")
172             subrow.itemO("object.shape_key_clear", icon='ICON_X', text="")
173
174             sub.itemO("object.shape_key_mirror", icon='ICON_MOD_MIRROR', text="")
175
176             sub.itemR(ob, "shape_key_edit_mode", text="")
177
178             row = layout.row()
179             row.itemR(kb, "name")
180
181             if key.relative:
182                 if ob.active_shape_key_index != 0:
183                     row = layout.row()
184                     row.active = enable_edit_value
185                     row.itemR(kb, "value")
186
187                     split = layout.split()
188                     sub = split.column(align=True)
189                     sub.active = enable_edit_value
190                     sub.itemL(text="Range:")
191                     sub.itemR(kb, "slider_min", text="Min")
192                     sub.itemR(kb, "slider_max", text="Max")
193
194                     sub = split.column(align=True)
195                     sub.active = enable_edit_value
196                     sub.itemL(text="Blend:")
197                     sub.item_pointerR(kb, "vertex_group", ob, "vertex_groups", text="")
198                     sub.item_pointerR(kb, "relative_key", key, "keys", text="")
199
200             else:
201                 row = layout.row()
202                 row.active = enable_edit_value
203                 row.itemR(key, "slurph")
204
205
206 class DATA_PT_uv_texture(DataButtonsPanel):
207     bl_label = "UV Texture"
208
209     def draw(self, context):
210         layout = self.layout
211
212         me = context.mesh
213
214         row = layout.row()
215         col = row.column()
216
217         col.template_list(me, "uv_textures", me, "active_uv_texture_index", rows=2)
218
219         col = row.column(align=True)
220         col.itemO("mesh.uv_texture_add", icon='ICON_ZOOMIN', text="")
221         col.itemO("mesh.uv_texture_remove", icon='ICON_ZOOMOUT', text="")
222
223         lay = me.active_uv_texture
224         if lay:
225             layout.itemR(lay, "name")
226
227
228 class DATA_PT_vertex_colors(DataButtonsPanel):
229     bl_label = "Vertex Colors"
230
231     def draw(self, context):
232         layout = self.layout
233
234         me = context.mesh
235
236         row = layout.row()
237         col = row.column()
238
239         col.template_list(me, "vertex_colors", me, "active_vertex_color_index", rows=2)
240
241         col = row.column(align=True)
242         col.itemO("mesh.vertex_color_add", icon='ICON_ZOOMIN', text="")
243         col.itemO("mesh.vertex_color_remove", icon='ICON_ZOOMOUT', text="")
244
245         lay = me.active_vertex_color
246         if lay:
247             layout.itemR(lay, "name")
248
249 bpy.types.register(DATA_PT_context_mesh)
250 bpy.types.register(DATA_PT_normals)
251 bpy.types.register(DATA_PT_settings)
252 bpy.types.register(DATA_PT_vertex_groups)
253 bpy.types.register(DATA_PT_shape_keys)
254 bpy.types.register(DATA_PT_uv_texture)
255 bpy.types.register(DATA_PT_vertex_colors)