c49ee68f0bfc9183b3b93634e9ff53db972b51ed
[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
112
113 class NODE_MT_node(bpy.types.Menu):
114     bl_label = "Node"
115
116     def draw(self, context):
117         layout = self.layout
118
119         layout.operator("transform.translate")
120         layout.operator("transform.rotate")
121         layout.operator("transform.resize")
122
123         layout.separator()
124
125         layout.operator("node.duplicate_move")
126         layout.operator("node.delete")
127
128         layout.separator()
129         layout.operator("node.link_make")
130         layout.operator("node.link_make", text="Make and Replace Links").replace = True
131
132         layout.separator()
133         layout.operator("node.group_edit")
134         layout.operator("node.group_ungroup")
135         layout.operator("node.group_make")
136
137         layout.separator()
138
139         layout.operator("node.hide")
140         layout.operator("node.mute")
141
142         # XXX
143         # layout.operator("node.rename")
144
145         layout.separator()
146
147         layout.operator("node.show_cyclic_dependencies")
148
149
150 classes = [
151     NODE_HT_header,
152     NODE_MT_view,
153     NODE_MT_select,
154     NODE_MT_node]
155
156
157 def register():
158     register = bpy.types.register
159     for cls in classes:
160         register(cls)
161
162
163 def unregister():
164     unregister = bpy.types.unregister
165     for cls in classes:
166         unregister(cls)
167
168 if __name__ == "__main__":
169     register()