Merge with trunk, revision 28528 - 28976.
[blender-staging.git] / release / scripts / 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
22
23 class NODE_HT_header(bpy.types.Header):
24     bl_space_type = 'NODE_EDITOR'
25
26     def draw(self, context):
27         layout = self.layout
28
29         snode = context.space_data
30
31         row = layout.row(align=True)
32         row.template_header()
33
34         if context.area.show_menus:
35             sub = row.row(align=True)
36             sub.menu("NODE_MT_view")
37             sub.menu("NODE_MT_select")
38             sub.menu("NODE_MT_add")
39             sub.menu("NODE_MT_node")
40
41         row = layout.row()
42         row.prop(snode, "tree_type", text="", expand=True)
43
44         if snode.tree_type == 'MATERIAL':
45             ob = snode.id_from
46             snode_id = snode.id
47             if ob:
48                 layout.template_ID(ob, "active_material", new="material.new")
49             if snode_id:
50                 layout.prop(snode_id, "use_nodes")
51
52         elif snode.tree_type == 'TEXTURE':
53             row.prop(snode, "texture_type", text="", expand=True)
54
55             snode_id = snode.id
56             id_from = snode.id_from
57             if id_from:
58                 if snode.texture_type == 'BRUSH':
59                     layout.template_ID(id_from, "texture", new="texture.new")
60                 else:
61                     layout.template_ID(id_from, "active_texture", new="texture.new")
62             if snode_id:
63                 layout.prop(snode_id, "use_nodes")
64
65         elif snode.tree_type == 'COMPOSITING':
66             scene = snode.id
67
68             layout.prop(scene, "use_nodes")
69             layout.prop(scene.render, "free_unused_nodes", text="Free Unused")
70             layout.prop(snode, "backdrop")
71
72         layout.separator()
73
74         layout.template_running_jobs()
75
76
77 class NODE_MT_view(bpy.types.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         layout.separator()
94
95         layout.operator("screen.area_dupli")
96         layout.operator("screen.screen_full_area")
97
98
99 class NODE_MT_select(bpy.types.Menu):
100     bl_label = "Select"
101
102     def draw(self, context):
103         layout = self.layout
104
105         layout.operator("node.select_border")
106
107         layout.separator()
108         layout.operator("node.select_all")
109         layout.operator("node.select_linked_from")
110         layout.operator("node.select_linked_to")
111         layout.operator("node.select_same_type")
112         layout.operator("node.select_same_type_next")
113         layout.operator("node.select_same_type_prev")
114
115
116 class NODE_MT_node(bpy.types.Menu):
117     bl_label = "Node"
118
119     def draw(self, context):
120         layout = self.layout
121
122         layout.operator("transform.translate")
123         layout.operator("transform.rotate")
124         layout.operator("transform.resize")
125
126         layout.separator()
127
128         layout.operator("node.duplicate_move")
129         layout.operator("node.delete")
130
131         layout.separator()
132         layout.operator("node.link_make")
133         layout.operator("node.link_make", text="Make and Replace Links").replace = True
134
135         layout.separator()
136         layout.operator("node.group_edit")
137         layout.operator("node.group_ungroup")
138         layout.operator("node.group_make")
139
140         layout.separator()
141
142         layout.operator("node.hide")
143         layout.operator("node.mute")
144
145         # XXX
146         # layout.operator("node.rename")
147
148         layout.separator()
149
150         layout.operator("node.show_cyclic_dependencies")
151
152
153 classes = [
154     NODE_HT_header,
155     NODE_MT_view,
156     NODE_MT_select,
157     NODE_MT_node]
158
159
160 def register():
161     register = bpy.types.register
162     for cls in classes:
163         register(cls)
164
165
166 def unregister():
167     unregister = bpy.types.unregister
168     for cls in classes:
169         unregister(cls)
170
171 if __name__ == "__main__":
172     register()