made scripts pass the pep8 test (though not fully pep8 yet)
[blender-staging.git] / release / scripts / ui / space_image.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 IMAGE_MT_view(bpy.types.Menu):
11     bl_label = "View"
12
13     def draw(self, context):
14         layout = self.layout
15
16         sima = context.space_data
17         uv = sima.uv_editor
18         settings = context.tool_settings
19
20         show_uvedit = sima.show_uvedit
21
22         layout.itemO("image.properties", icon='ICON_MENU_PANEL')
23
24         layout.itemS()
25
26         layout.itemR(sima, "update_automatically")
27         if show_uvedit:
28             layout.itemR(settings, "uv_local_view") # Numpad /
29
30         layout.itemS()
31
32         layout.itemO("image.view_zoom_in")
33         layout.itemO("image.view_zoom_out")
34
35         layout.itemS()
36
37         ratios = [[1, 8], [1, 4], [1, 2], [1, 1], [2, 1], [4, 1], [8, 1]]
38
39         for a, b in ratios:
40             text = "Zoom %d:%d" % (a, b)
41             layout.item_floatO("image.view_zoom_ratio", "ratio", a / b, text=text)
42
43         layout.itemS()
44
45         if show_uvedit:
46             layout.itemO("image.view_selected")
47
48         layout.itemO("image.view_all")
49         layout.itemO("screen.screen_full_area")
50
51
52 class IMAGE_MT_select(bpy.types.Menu):
53     bl_label = "Select"
54
55     def draw(self, context):
56         layout = self.layout
57
58         layout.itemO("uv.select_border")
59         layout.item_booleanO("uv.select_border", "pinned", True)
60
61         layout.itemS()
62
63         layout.itemO("uv.select_all_toggle")
64         layout.itemO("uv.select_inverse")
65         layout.itemO("uv.unlink_selection")
66
67         layout.itemS()
68
69         layout.itemO("uv.select_pinned")
70         layout.itemO("uv.select_linked")
71
72
73 class IMAGE_MT_image(bpy.types.Menu):
74     bl_label = "Image"
75
76     def draw(self, context):
77         layout = self.layout
78
79         sima = context.space_data
80         ima = sima.image
81
82         layout.itemO("image.new")
83         layout.itemO("image.open")
84
85         show_render = sima.show_render
86
87         if ima:
88             if not show_render:
89                 layout.itemO("image.replace")
90                 layout.itemO("image.reload")
91
92             layout.itemO("image.save")
93             layout.itemO("image.save_as")
94
95             if ima.source == 'SEQUENCE':
96                 layout.itemO("image.save_sequence")
97
98             if not show_render:
99                 layout.itemS()
100
101                 if ima.packed_file:
102                     layout.itemO("image.unpack")
103                 else:
104                     layout.itemO("image.pack")
105
106                 # only for dirty && specific image types, perhaps
107                 # this could be done in operator poll too
108                 if ima.dirty:
109                     if ima.source in ('FILE', 'GENERATED') and ima.type != 'MULTILAYER':
110                         layout.item_booleanO("image.pack", "as_png", True, text="Pack As PNG")
111
112             layout.itemS()
113
114             layout.itemR(sima, "image_painting")
115
116
117 class IMAGE_MT_uvs_showhide(bpy.types.Menu):
118     bl_label = "Show/Hide Faces"
119
120     def draw(self, context):
121         layout = self.layout
122
123         layout.itemO("uv.reveal")
124         layout.itemO("uv.hide")
125         layout.item_booleanO("uv.hide", "unselected", True)
126
127
128 class IMAGE_MT_uvs_transform(bpy.types.Menu):
129     bl_label = "Transform"
130
131     def draw(self, context):
132         layout = self.layout
133
134         layout.itemO("tfm.translate")
135         layout.itemO("tfm.rotate")
136         layout.itemO("tfm.resize")
137
138
139 class IMAGE_MT_uvs_mirror(bpy.types.Menu):
140     bl_label = "Mirror"
141
142     def draw(self, context):
143         layout = self.layout
144         layout.operator_context = "EXEC_REGION_WIN"
145
146         props = layout.itemO("tfm.mirror", text="X Axis", properties=True)
147         props.constraint_axis[0] = True
148
149         props = layout.itemO("tfm.mirror", text="Y Axis", properties=True)
150         props.constraint_axis[1] = True
151
152
153 class IMAGE_MT_uvs_weldalign(bpy.types.Menu):
154     bl_label = "Weld/Align"
155
156     def draw(self, context):
157         layout = self.layout
158
159         layout.itemO("uv.weld") # W, 1
160         layout.items_enumO("uv.align", "axis") # W, 2/3/4
161
162
163 class IMAGE_MT_uvs(bpy.types.Menu):
164     bl_label = "UVs"
165
166     def draw(self, context):
167         layout = self.layout
168
169         sima = context.space_data
170         uv = sima.uv_editor
171         settings = context.tool_settings
172
173         layout.itemR(uv, "snap_to_pixels")
174         layout.itemR(uv, "constrain_to_image_bounds")
175
176         layout.itemS()
177
178         layout.itemR(uv, "live_unwrap")
179         layout.itemO("uv.unwrap")
180         layout.item_booleanO("uv.pin", "clear", True, text="Unpin")
181         layout.itemO("uv.pin")
182
183         layout.itemS()
184
185         layout.itemO("uv.pack_islands")
186         layout.itemO("uv.average_islands_scale")
187         layout.itemO("uv.minimize_stretch")
188         layout.itemO("uv.stitch")
189
190         layout.itemS()
191
192         layout.itemM("IMAGE_MT_uvs_transform")
193         layout.itemM("IMAGE_MT_uvs_mirror")
194         layout.itemM("IMAGE_MT_uvs_weldalign")
195
196         layout.itemS()
197
198         layout.itemR(settings, "proportional_editing")
199         layout.item_menu_enumR(settings, "proportional_editing_falloff")
200
201         layout.itemS()
202
203         layout.itemM("IMAGE_MT_uvs_showhide")
204
205
206 class IMAGE_HT_header(bpy.types.Header):
207     bl_space_type = 'IMAGE_EDITOR'
208
209     def draw(self, context):
210         layout = self.layout
211
212         sima = context.space_data
213         ima = sima.image
214         iuser = sima.image_user
215         settings = context.tool_settings
216
217         show_render = sima.show_render
218         show_paint = sima.show_paint
219         show_uvedit = sima.show_uvedit
220
221         row = layout.row(align=True)
222         row.template_header()
223
224         # menus
225         if context.area.show_menus:
226             sub = row.row(align=True)
227             sub.itemM("IMAGE_MT_view")
228
229             if show_uvedit:
230                 sub.itemM("IMAGE_MT_select")
231
232             if ima and ima.dirty:
233                 sub.itemM("IMAGE_MT_image", text="Image*")
234             else:
235                 sub.itemM("IMAGE_MT_image", text="Image")
236
237             if show_uvedit:
238                 sub.itemM("IMAGE_MT_uvs")
239
240         layout.template_ID(sima, "image", new="image.new")
241
242         # uv editing
243         if show_uvedit:
244             uvedit = sima.uv_editor
245
246             layout.itemR(uvedit, "pivot", text="", icon_only=True)
247             layout.itemR(settings, "uv_sync_selection", text="")
248
249             if settings.uv_sync_selection:
250                 layout.itemR(settings, "mesh_selection_mode", text="", expand=True)
251             else:
252                 layout.itemR(settings, "uv_selection_mode", text="", expand=True)
253                 layout.itemR(uvedit, "sticky_selection_mode", text="", icon_only=True)
254             pass
255
256             row = layout.row(align=True)
257             row.itemR(settings, "snap", text="")
258             if settings.snap:
259                 row.itemR(settings, "snap_mode", text="")
260
261             """
262             mesh = context.edit_object.data
263             row.item_pointerR(mesh, "active_uv_layer", mesh, "uv_textures")
264             """
265
266         if ima:
267             # layers
268             layout.template_image_layers(ima, iuser)
269
270             # painting
271             layout.itemR(sima, "image_painting", text="")
272
273             # draw options
274             row = layout.row(align=True)
275             row.itemR(sima, "draw_channels", text="", expand=True)
276
277             row = layout.row(align=True)
278             if ima.type == 'COMPOSITE':
279                 row.itemO("image.record_composite", icon='ICON_REC')
280             if ima.type == 'COMPOSITE' and ima.source in ('MOVIE', 'SEQUENCE'):
281                 row.itemO("image.play_composite", icon='ICON_PLAY')
282
283         if show_uvedit or sima.image_painting:
284             layout.itemR(sima, "update_automatically", text="")
285
286
287 class IMAGE_PT_image_properties(bpy.types.Panel):
288     bl_space_type = 'IMAGE_EDITOR'
289     bl_region_type = 'UI'
290     bl_label = "Image"
291
292     def poll(self, context):
293         sima = context.space_data
294         return (sima.image)
295
296     def draw(self, context):
297         layout = self.layout
298
299         sima = context.space_data
300         ima = sima.image
301         iuser = sima.image_user
302
303         layout.template_image(sima, "image", iuser, compact=True)
304
305
306 class IMAGE_PT_game_properties(bpy.types.Panel):
307     bl_space_type = 'IMAGE_EDITOR'
308     bl_region_type = 'UI'
309     bl_label = "Game Properties"
310
311     def poll(self, context):
312         rd = context.scene.render_data
313         sima = context.space_data
314         return (sima and sima.image) and (rd.engine == 'BLENDER_GAME')
315
316     def draw(self, context):
317         layout = self.layout
318
319         sima = context.space_data
320         ima = sima.image
321
322         split = layout.split()
323
324         col = split.column()
325
326         sub = col.column(align=True)
327         sub.itemR(ima, "animated")
328
329         subsub = sub.column()
330         subsub.active = ima.animated
331         subsub.itemR(ima, "animation_start", text="Start")
332         subsub.itemR(ima, "animation_end", text="End")
333         subsub.itemR(ima, "animation_speed", text="Speed")
334
335         col.itemR(ima, "tiles")
336         sub = col.column(align=True)
337         sub.active = ima.tiles or ima.animated
338         sub.itemR(ima, "tiles_x", text="X")
339         sub.itemR(ima, "tiles_y", text="Y")
340
341         col = split.column()
342         col.itemL(text="Clamp:")
343         col.itemR(ima, "clamp_x", text="X")
344         col.itemR(ima, "clamp_y", text="Y")
345         col.itemS()
346         col.itemR(ima, "mapping", expand=True)
347
348
349 class IMAGE_PT_view_properties(bpy.types.Panel):
350     bl_space_type = 'IMAGE_EDITOR'
351     bl_region_type = 'UI'
352     bl_label = "Display"
353
354     def poll(self, context):
355         sima = context.space_data
356         return (sima and (sima.image or sima.show_uvedit))
357
358     def draw(self, context):
359         layout = self.layout
360
361         sima = context.space_data
362         ima = sima.image
363         show_uvedit = sima.show_uvedit
364         uvedit = sima.uv_editor
365
366         split = layout.split()
367
368         col = split.column()
369         if ima:
370             col.itemR(ima, "display_aspect", text="Aspect Ratio")
371
372             col = split.column()
373             col.itemL(text="Coordinates:")
374             col.itemR(sima, "draw_repeated", text="Repeat")
375             if show_uvedit:
376                 col.itemR(uvedit, "normalized_coordinates", text="Normalized")
377         elif show_uvedit:
378             col.itemL(text="Coordinates:")
379             col.itemR(uvedit, "normalized_coordinates", text="Normalized")
380
381         if show_uvedit:
382
383             col = layout.column()
384             col.itemL(text="UVs:")
385             row = col.row()
386             row.itemR(uvedit, "edge_draw_type", expand=True)
387
388             split = layout.split()
389
390             col = split.column()
391             col.itemR(uvedit, "draw_stretch", text="Stretch")
392             sub = col.column()
393             sub.active = uvedit.draw_stretch
394             sub.row().itemR(uvedit, "draw_stretch_type", expand=True)
395
396             col = split.column()
397             col.itemR(uvedit, "draw_smooth_edges", text="Smooth")
398             col.itemR(uvedit, "draw_modified_edges", text="Modified")
399             #col.itemR(uvedit, "draw_edges")
400             #col.itemR(uvedit, "draw_faces")
401
402
403 class IMAGE_PT_paint(bpy.types.Panel):
404     bl_space_type = 'IMAGE_EDITOR'
405     bl_region_type = 'UI'
406     bl_label = "Paint"
407
408     def poll(self, context):
409         sima = context.space_data
410         return sima.show_paint
411
412     def draw(self, context):
413         layout = self.layout
414
415         settings = context.tool_settings.image_paint
416         brush = settings.brush
417
418         col = layout.split().column()
419         row = col.row()
420         row.template_list(settings, "brushes", settings, "active_brush_index", rows=2)
421
422         col.template_ID(settings, "brush", new="brush.add")
423
424         row = layout.row(align=True)
425         row.item_enumR(settings, "tool", 'DRAW')
426         row.item_enumR(settings, "tool", 'SOFTEN')
427         row.item_enumR(settings, "tool", 'CLONE')
428         row.item_enumR(settings, "tool", 'SMEAR')
429
430         if brush:
431             col = layout.column()
432             col.itemR(brush, "color", text="")
433
434             row = col.row(align=True)
435             row.itemR(brush, "size", slider=True)
436             row.itemR(brush, "use_size_pressure", toggle=True, text="")
437
438             row = col.row(align=True)
439             row.itemR(brush, "strength", slider=True)
440             row.itemR(brush, "use_strength_pressure", toggle=True, text="")
441
442             row = col.row(align=True)
443             row.itemR(brush, "jitter", slider=True)
444             row.itemR(brush, "use_jitter_pressure", toggle=True, text="")
445
446             col.itemR(brush, "blend", text="Blend")
447
448
449 class IMAGE_PT_paint_stroke(bpy.types.Panel):
450     bl_space_type = 'IMAGE_EDITOR'
451     bl_region_type = 'UI'
452     bl_label = "Paint Stroke"
453     bl_default_closed = True
454
455     def poll(self, context):
456         sima = context.space_data
457         settings = context.tool_settings.image_paint
458         return sima.show_paint and settings.brush
459
460     def draw(self, context):
461         layout = self.layout
462
463         settings = context.tool_settings.image_paint
464         brush = settings.brush
465
466         layout.itemR(brush, "use_airbrush")
467         col = layout.column()
468         col.active = brush.use_airbrush
469         col.itemR(brush, "rate", slider=True)
470
471         layout.itemR(brush, "use_space")
472         row = layout.row(align=True)
473         row.active = brush.use_space
474         row.itemR(brush, "spacing", text="Distance", slider=True)
475         row.itemR(brush, "use_spacing_pressure", toggle=True, text="")
476
477
478 class IMAGE_PT_paint_curve(bpy.types.Panel):
479     bl_space_type = 'IMAGE_EDITOR'
480     bl_region_type = 'UI'
481     bl_label = "Paint Curve"
482     bl_default_closed = True
483
484     def poll(self, context):
485         sima = context.space_data
486         settings = context.tool_settings.image_paint
487         return sima.show_paint and settings.brush
488
489     def draw(self, context):
490         layout = self.layout
491
492         settings = context.tool_settings.image_paint
493         brush = settings.brush
494
495         layout.template_curve_mapping(brush, "curve")
496         layout.item_menu_enumO("brush.curve_preset", property="shape")
497
498 bpy.types.register(IMAGE_MT_view)
499 bpy.types.register(IMAGE_MT_select)
500 bpy.types.register(IMAGE_MT_image)
501 bpy.types.register(IMAGE_MT_uvs_showhide)
502 bpy.types.register(IMAGE_MT_uvs_transform)
503 bpy.types.register(IMAGE_MT_uvs_mirror)
504 bpy.types.register(IMAGE_MT_uvs_weldalign)
505 bpy.types.register(IMAGE_MT_uvs)
506 bpy.types.register(IMAGE_HT_header)
507 bpy.types.register(IMAGE_PT_image_properties)
508 bpy.types.register(IMAGE_PT_paint)
509 bpy.types.register(IMAGE_PT_paint_stroke)
510 bpy.types.register(IMAGE_PT_paint_curve)
511 bpy.types.register(IMAGE_PT_game_properties)
512 bpy.types.register(IMAGE_PT_view_properties)