svn merge -r40222:40344 ^/trunk/blender
[blender.git] / release / scripts / startup / bl_ui / space_node.py
1 # ##### BEGIN GPL LICENSE BLOCK #####
2 #
3 #  This program is free software; you can redistribute it and/or
4 #  modify it under the terms of the GNU General Public License
5 #  as published by the Free Software Foundation; either version 2
6 #  of the License, or (at your option) any later version.
7 #
8 #  This program is distributed in the hope that it will be useful,
9 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 #  GNU General Public License for more details.
12 #
13 #  You should have received a copy of the GNU General Public License
14 #  along with this program; if not, write to the Free Software Foundation,
15 #  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 #
17 # ##### END GPL LICENSE BLOCK #####
18
19 # <pep8 compliant>
20 import bpy
21 from bpy.types import Header, Menu, Panel
22 from blf import gettext as _
23
24
25 class NODE_HT_header(Header):
26     bl_space_type = 'NODE_EDITOR'
27
28     def draw(self, context):
29         layout = self.layout
30
31         snode = context.space_data
32         snode_id = snode.id
33         id_from = snode.id_from
34
35         row = layout.row(align=True)
36         row.template_header()
37
38         if context.area.show_menus:
39             row.menu("NODE_MT_view")
40             row.menu("NODE_MT_select")
41             row.menu("NODE_MT_add")
42             row.menu("NODE_MT_node")
43
44         layout.prop(snode, "tree_type", text="", expand=True)
45
46         if snode.tree_type == 'MATERIAL':
47             if id_from:
48                 layout.template_ID(id_from, "active_material", new="material.new")
49             if snode_id:
50                 layout.prop(snode_id, "use_nodes")
51
52         elif snode.tree_type == 'TEXTURE':
53             layout.prop(snode, "texture_type", text="", expand=True)
54
55             if id_from:
56                 if snode.texture_type == 'BRUSH':
57                     layout.template_ID(id_from, "texture", new="texture.new")
58                 else:
59                     layout.template_ID(id_from, "active_texture", new="texture.new")
60             if snode_id:
61                 layout.prop(snode_id, "use_nodes")
62
63         elif snode.tree_type == 'COMPOSITING':
64             layout.prop(snode_id, "use_nodes")
65             layout.prop(snode_id.render, "use_free_unused_nodes", text=_("Free Unused"))
66             layout.prop(snode, "show_backdrop")
67             if snode.show_backdrop:
68                 row = layout.row(align=True)
69                 row.prop(snode, "backdrop_channels", text="", expand=True)
70             layout.prop(snode, "use_auto_render")
71
72         layout.separator()
73
74         layout.template_running_jobs()
75
76
77 class NODE_MT_view(Menu):
78     bl_label = "View"
79
80     def draw(self, context):
81         layout = self.layout
82
83         layout.operator("node.properties", icon='MENU_PANEL')
84         layout.separator()
85
86         layout.operator("view2d.zoom_in")
87         layout.operator("view2d.zoom_out")
88
89         layout.separator()
90
91         layout.operator("node.view_all")
92
93         if context.space_data.show_backdrop:
94             layout.separator()
95
96             layout.operator("node.backimage_move", text=_("Backdrop move"))
97             layout.operator("node.backimage_zoom", text=_("Backdrop zoom in")).factor = 1.2
98             layout.operator("node.backimage_zoom", text=_("Backdrop zoom out")).factor = 0.833
99
100         layout.separator()
101
102         layout.operator("screen.area_dupli")
103         layout.operator("screen.screen_full_area")
104
105
106 class NODE_MT_select(Menu):
107     bl_label = "Select"
108
109     def draw(self, context):
110         layout = self.layout
111
112         layout.operator("node.select_border")
113
114         layout.separator()
115         layout.operator("node.select_all")
116         layout.operator("node.select_linked_from")
117         layout.operator("node.select_linked_to")
118         layout.operator("node.select_same_type")
119         layout.operator("node.select_same_type_next")
120         layout.operator("node.select_same_type_prev")
121
122
123 class NODE_MT_node(Menu):
124     bl_label = "Node"
125
126     def draw(self, context):
127         layout = self.layout
128
129         layout.operator("transform.translate")
130         layout.operator("transform.rotate")
131         layout.operator("transform.resize")
132
133         layout.separator()
134
135         layout.operator("node.duplicate_move")
136         layout.operator("node.delete")
137         layout.operator("node.delete_reconnect")
138
139         layout.separator()
140         layout.operator("node.link_make")
141         layout.operator("node.link_make", text=_("Make and Replace Links")).replace = True
142         layout.operator("node.links_cut")
143
144         layout.separator()
145         layout.operator("node.group_edit")
146         layout.operator("node.group_ungroup")
147         layout.operator("node.group_make")
148
149         layout.separator()
150
151         layout.operator("node.hide_toggle")
152         layout.operator("node.mute_toggle")
153         layout.operator("node.preview_toggle")
154         layout.operator("node.hide_socket_toggle")
155
156         layout.separator()
157
158         layout.operator("node.show_cyclic_dependencies")
159         layout.operator("node.read_renderlayers")
160         layout.operator("node.read_fullsamplelayers")
161
162
163 # Node Backdrop options
164 class NODE_PT_properties(Panel):
165     bl_space_type = 'NODE_EDITOR'
166     bl_region_type = 'UI'
167     bl_label = "Backdrop"
168
169     @classmethod
170     def poll(cls, context):
171         snode = context.space_data
172         return snode.tree_type == 'COMPOSITING'
173
174     def draw_header(self, context):
175         snode = context.space_data
176         self.layout.prop(snode, "show_backdrop", text="")
177
178     def draw(self, context):
179         layout = self.layout
180
181         snode = context.space_data
182         layout.active = snode.show_backdrop
183         layout.prop(snode, "backdrop_channels", text="")
184         layout.prop(snode, "backdrop_zoom", text=_("Zoom"))
185
186         col = layout.column(align=True)
187         col.label(text=_("Offset:"))
188         col.prop(snode, "backdrop_x", text="X")
189         col.prop(snode, "backdrop_y", text="Y")
190         col.operator("node.backimage_move", text=_("Move"))
191
192 if __name__ == "__main__":  # only for live edit.
193     bpy.utils.register_module(__name__)