rna function api was overwriting useful errors with keyword errors.
[blender.git] / release / ui / buttons_data_mesh.py
1
2 import bpy
3
4 class DataButtonsPanel(bpy.types.Panel):
5         __space_type__ = 'PROPERTIES'
6         __region_type__ = 'WINDOW'
7         __context__ = "data"
8         
9         def poll(self, context):
10                 return (context.mesh)
11
12 class DATA_PT_context_mesh(DataButtonsPanel):
13         __show_header__ = False
14         
15         def draw(self, context):
16                 layout = self.layout
17                 
18                 ob = context.object
19                 mesh = context.mesh
20                 space = context.space_data
21
22                 split = layout.split(percentage=0.65)
23
24                 if ob:
25                         split.template_ID(ob, "data")
26                         split.itemS()
27                 elif mesh:
28                         split.template_ID(space, "pin_id")
29                         split.itemS()
30
31 class DATA_PT_normals(DataButtonsPanel):
32         __label__ = "Normals"
33
34         def draw(self, context):
35                 layout = self.layout
36                 
37                 mesh = context.mesh
38                 
39                 split = layout.split()
40                 
41                 col = split.column()
42                 col.itemR(mesh, "autosmooth")
43                 sub = col.column()
44                 sub.active = mesh.autosmooth
45                 sub.itemR(mesh, "autosmooth_angle", text="Angle")
46                 
47                 col = split.column()
48                 col.itemR(mesh, "vertex_normal_flip")
49                 col.itemR(mesh, "double_sided")
50
51 class DATA_PT_vertex_groups(DataButtonsPanel):
52         __label__ = "Vertex Groups"
53         
54         def poll(self, context):
55                 return (context.object and context.object.type in ('MESH', 'LATTICE'))
56
57         def draw(self, context):
58                 layout = self.layout
59                 
60                 ob = context.object
61
62                 row = layout.row()
63                 row.template_list(ob, "vertex_groups", ob, "active_vertex_group_index")
64
65                 col = row.column(align=True)
66                 col.itemO("object.vertex_group_add", icon='ICON_ZOOMIN', text="")
67                 col.itemO("object.vertex_group_remove", icon='ICON_ZOOMOUT', text="")
68
69                 col.itemO("object.vertex_group_copy", icon='ICON_BLANK1', text="")
70                 if ob.data.users > 1:
71                         col.itemO("object.vertex_group_copy_to_linked", icon='ICON_BLANK1', text="")
72
73                 group = ob.active_vertex_group
74                 if group:
75                         row = layout.row()
76                         row.itemR(group, "name")
77
78                 if ob.mode == 'EDIT':
79                         row = layout.row()
80                         
81                         sub = row.row(align=True)
82                         sub.itemO("object.vertex_group_assign", text="Assign")
83                         sub.itemO("object.vertex_group_remove_from", text="Remove")
84                         
85                         sub = row.row(align=True)
86                         sub.itemO("object.vertex_group_select", text="Select")
87                         sub.itemO("object.vertex_group_deselect", text="Deselect")
88
89                         layout.itemR(context.tool_settings, "vertex_group_weight", text="Weight")
90
91 class DATA_PT_shape_keys(DataButtonsPanel):
92         __label__ = "Shape Keys"
93         
94         def poll(self, context):
95                 return (context.object and context.object.type in ('MESH', 'LATTICE'))
96
97         def draw(self, context):
98                 layout = self.layout
99                 
100                 ob = context.object
101                 key = ob.data.shape_keys
102                 kb = ob.active_shape_key
103
104                 row = layout.row()
105                 if key: # XXX - looks crappy
106                         row.template_list(key, "keys", ob, "active_shape_key_index", rows=2)
107
108                 col = row.column()
109
110                 subcol = col.column(align=True)
111                 subcol.itemO("object.shape_key_add", icon='ICON_ZOOMIN', text="")
112                 subcol.itemO("object.shape_key_remove", icon='ICON_ZOOMOUT', text="")
113
114                 if kb:
115                         col.itemS()
116
117                         subcol = col.column(align=True)
118                         subcol.itemR(ob, "shape_key_lock", icon='ICON_UNPINNED', text="")
119                         subcol.itemR(kb, "mute", icon='ICON_MUTE_IPO_ON', text="")
120
121                         if key.relative:
122                                 row = layout.row()
123                                 row.itemR(key, "relative")
124                                 row.itemL()
125
126                                 row = layout.row()
127                                 row.itemR(kb, "name")
128
129                                 if ob.active_shape_key_index != 0:
130                                         
131                                         row = layout.row()
132                                         row.enabled = ob.shape_key_lock == False
133                                         row.itemR(kb, "value", slider=True)
134                                         
135                                         split = layout.split()
136                                         sub = split.column(align=True)
137                                         sub.enabled = ob.shape_key_lock == False
138                                         sub.itemL(text="Range:")
139                                         sub.itemR(kb, "slider_min", text="Min")
140                                         sub.itemR(kb, "slider_max", text="Max")
141                                         
142                                         sub = split.column()
143                                         sub.itemL(text="Blend:")
144                                         sub.item_pointerR(kb, "vertex_group", ob, "vertex_groups", text="")
145                                         sub.item_pointerR(kb, "relative_key", key, "keys", text="")
146                                         
147                         else:
148                                 row = layout.row()
149                                 row.itemR(key, "relative")
150                                 row.itemR(key, "slurph")
151
152                                 layout.itemR(kb, "name")
153
154                 if ob.mode == 'EDIT':
155                         layout.enabled = False
156
157 class DATA_PT_uv_texture(DataButtonsPanel):
158         __label__ = "UV Texture"
159         
160         def draw(self, context):
161                 layout = self.layout
162                 
163                 me = context.mesh
164
165                 row = layout.row()
166                 col = row.column()
167                 
168                 col.template_list(me, "uv_textures", me, "active_uv_texture_index", rows=2)
169
170                 col = row.column(align=True)
171                 col.itemO("mesh.uv_texture_add", icon='ICON_ZOOMIN', text="")
172                 col.itemO("mesh.uv_texture_remove", icon='ICON_ZOOMOUT', text="")
173
174                 lay = me.active_uv_texture
175                 if lay:
176                         layout.itemR(lay, "name")
177
178 class DATA_PT_vertex_colors(DataButtonsPanel):
179         __label__ = "Vertex Colors"
180         
181         def draw(self, context):
182                 layout = self.layout
183                 
184                 me = context.mesh
185
186                 row = layout.row()
187                 col = row.column()
188
189                 col.template_list(me, "vertex_colors", me, "active_vertex_color_index", rows=2)
190
191                 col = row.column(align=True)
192                 col.itemO("mesh.vertex_color_add", icon='ICON_ZOOMIN', text="")
193                 col.itemO("mesh.vertex_color_remove", icon='ICON_ZOOMOUT', text="")
194
195                 lay = me.active_vertex_color
196                 if lay:
197                         layout.itemR(lay, "name")
198
199 bpy.types.register(DATA_PT_context_mesh)
200 bpy.types.register(DATA_PT_normals)
201 bpy.types.register(DATA_PT_vertex_groups)
202 bpy.types.register(DATA_PT_shape_keys)
203 bpy.types.register(DATA_PT_uv_texture)
204 bpy.types.register(DATA_PT_vertex_colors)