Made Add Surface Operator more atomic, now each primitive has own operator, but calli...
[blender.git] / release / scripts / ui / space_info.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 INFO_HT_header(bpy.types.Header):
24     bl_space_type = 'INFO'
25
26     def draw(self, context):
27         layout = self.layout
28
29         wm = context.manager
30         if wm and len(wm.operators):
31             last_op = wm.operators[-1]
32         else:
33             last_op = None
34         window = context.window
35         scene = context.scene
36         rd = scene.render
37
38         row = layout.row(align=True)
39         row.template_header()
40
41         if context.area.show_menus:
42             sub = row.row(align=True)
43             sub.menu("INFO_MT_file")
44             sub.menu("INFO_MT_add")
45             if rd.use_game_engine:
46                 sub.menu("INFO_MT_game")
47             else:
48                 sub.menu("INFO_MT_render")
49             sub.menu("INFO_MT_help")
50
51         if window.screen.fullscreen:
52             layout.operator("screen.back_to_previous", icon='SCREEN_BACK', text="Back to Previous")
53             layout.separator()
54         else:
55             layout.template_ID(context.window, "screen", new="screen.new", unlink="screen.delete")
56
57         layout.template_ID(context.screen, "scene", new="scene.new", unlink="scene.delete")
58
59         layout.separator()
60
61         if rd.multiple_engines:
62             layout.prop(rd, "engine", text="")
63
64         layout.separator()
65
66         layout.template_running_jobs()
67
68         layout.template_reports_banner()
69
70         layout.label(text=scene.statistics())
71
72         # XXX: this should be right-aligned to the RHS of the region
73         layout.operator("wm.window_fullscreen_toggle", icon='FULLSCREEN_ENTER', text="")
74
75
76 class INFO_MT_file(bpy.types.Menu):
77     bl_label = "File"
78
79     def draw(self, context):
80         layout = self.layout
81
82         layout.operator_context = 'EXEC_AREA'
83         layout.operator("wm.read_homefile", text="New", icon='NEW')
84         layout.operator_context = 'INVOKE_AREA'
85         layout.operator("wm.open_mainfile", text="Open...", icon='FILE_FOLDER')
86         layout.menu("INFO_MT_file_open_recent")
87         layout.operator("wm.recover_last_session", icon='RECOVER_LAST')
88         layout.operator("wm.recover_auto_save", text="Recover Auto Save...")
89
90         layout.separator()
91
92         layout.operator_context = 'INVOKE_AREA'
93         layout.operator("wm.save_mainfile", text="Save", icon='FILE_TICK').check_existing = False
94         layout.operator_context = 'INVOKE_AREA'
95         layout.operator("wm.save_as_mainfile", text="Save As...")
96
97         layout.separator()
98
99         layout.operator("screen.userpref_show", text="User Preferences...", icon='PREFERENCES')
100
101         layout.operator_context = 'EXEC_AREA'
102         layout.operator("wm.read_homefile", text="Load Factory Settings").factory = True
103
104         layout.separator()
105
106         layout.operator_context = 'INVOKE_AREA'
107         layout.operator("wm.link_append", text="Link")
108         props = layout.operator("wm.link_append", text="Append")
109         props.link = False
110         props.instance_groups = False
111
112         layout.separator()
113
114         layout.menu("INFO_MT_file_import")
115         layout.menu("INFO_MT_file_export")
116
117         layout.separator()
118
119         layout.menu("INFO_MT_file_external_data")
120
121         layout.separator()
122
123         layout.operator_context = 'EXEC_AREA'
124         layout.operator("wm.exit_blender", text="Quit", icon='QUIT')
125
126
127 class INFO_MT_file_open_recent(bpy.types.Menu):
128     bl_idname = "INFO_MT_file_open_recent"
129     bl_label = "Open Recent..."
130
131     def draw(self, context):
132         import os
133         layout = self.layout
134         layout.operator_context = 'EXEC_AREA'
135
136         path = os.path.join(bpy.app.home, ".Blog")
137
138         if os.path.isfile(path):
139             file = open(path, "rU")
140             for line in file:
141                 line = line.rstrip()
142                 layout.operator("wm.open_mainfile", text=line, icon='FILE_BLEND').path = line
143             file.close()
144         else:
145             layout.label(text='No recent files')
146
147
148 class INFO_MT_file_import(bpy.types.Menu):
149     bl_idname = "INFO_MT_file_import"
150     bl_label = "Import"
151
152     def draw(self, context):
153         if "collada_import" in dir(bpy.ops.wm):
154             self.layout.operator("wm.collada_import", text="COLLADA (.dae)")
155
156
157 class INFO_MT_file_export(bpy.types.Menu):
158     bl_idname = "INFO_MT_file_export"
159     bl_label = "Export"
160
161     def draw(self, context):
162         if "collada_export" in dir(bpy.ops.wm):
163             self.layout.operator("wm.collada_export", text="COLLADA (.dae)")
164
165
166 class INFO_MT_file_external_data(bpy.types.Menu):
167     bl_label = "External Data"
168
169     def draw(self, context):
170         layout = self.layout
171
172         layout.operator("file.pack_all", text="Pack into .blend file")
173         layout.operator("file.unpack_all", text="Unpack into Files")
174
175         layout.separator()
176
177         layout.operator("file.make_paths_relative")
178         layout.operator("file.make_paths_absolute")
179         layout.operator("file.report_missing_files")
180         layout.operator("file.find_missing_files")
181
182
183 class INFO_MT_mesh_add(bpy.types.Menu):
184     bl_idname = "INFO_MT_mesh_add"
185     bl_label = "Mesh"
186
187     def draw(self, context):
188         layout = self.layout
189         layout.operator_context = 'INVOKE_REGION_WIN'
190         layout.operator("mesh.primitive_plane_add", icon='MESH_PLANE', text="Plane")
191         layout.operator("mesh.primitive_cube_add", icon='MESH_CUBE', text="Cube")
192         layout.operator("mesh.primitive_circle_add", icon='MESH_CIRCLE', text="Circle")
193         layout.operator("mesh.primitive_uv_sphere_add", icon='MESH_UVSPHERE', text="UV Sphere")
194         layout.operator("mesh.primitive_ico_sphere_add", icon='MESH_ICOSPHERE', text="Icosphere")
195         layout.operator("mesh.primitive_tube_add", icon='MESH_TUBE', text="Tube")
196         layout.operator("mesh.primitive_cone_add", icon='MESH_CONE', text="Cone")
197         layout.separator()
198         layout.operator("mesh.primitive_grid_add", icon='MESH_GRID', text="Grid")
199         layout.operator("mesh.primitive_monkey_add", icon='MESH_MONKEY', text="Monkey")
200
201
202 class INFO_MT_curve_add(bpy.types.Menu):
203     bl_idname = "INFO_MT_curve_add"
204     bl_label = "Curve"
205
206     def draw(self, context):
207         layout = self.layout
208         layout.operator_context = 'INVOKE_REGION_WIN'
209         layout.operator("curve.primitive_bezier_curve_add", icon='CURVE_BEZCURVE', text="Bezier")
210         layout.operator("curve.primitive_bezier_circle_add", icon='CURVE_BEZCIRCLE', text="Circle")
211         layout.operator("curve.primitive_nurbs_curve_add", icon='CURVE_NCURVE', text="Nurbs Curve")
212         layout.operator("curve.primitive_nurbs_circle_add", icon='CURVE_NCIRCLE', text="Nurbs Circle")
213         layout.operator("curve.primitive_nurbs_path_add", icon='CURVE_PATH', text="Path")
214
215 class INFO_MT_surface_add(bpy.types.Menu):
216     bl_idname = "INFO_MT_surface_add"
217     bl_label = "Surface"
218
219     def draw(self, context):
220         layout = self.layout
221         layout.operator_context = 'INVOKE_REGION_WIN'
222         layout.operator("surface.primitive_nurbs_surface_curve_add", icon='SURFACE_NCURVE', text="NURBS Curve")
223         layout.operator("surface.primitive_nurbs_surface_circle_add", icon='SURFACE_NCIRCLE', text="NURBS Circle")
224         layout.operator("surface.primitive_nurbs_surface_surface_add", icon='SURFACE_NSURFACE', text="NURBS Surface")
225         layout.operator("surface.primitive_nurbs_surface_tube_add", icon='SURFACE_NTUBE', text="NURBS Tube")
226         layout.operator("surface.primitive_nurbs_surface_sphere_add", icon='SURFACE_NSPHERE', text="NURBS Sphere")
227         layout.operator("surface.primitive_nurbs_surface_donut_add", icon='SURFACE_NDONUT', text="NURBS Torus")
228
229 class INFO_MT_armature_add(bpy.types.Menu):
230     bl_idname = "INFO_MT_armature_add"
231     bl_label = "Armature"
232
233     def draw(self, context):
234         layout = self.layout
235         layout.operator_context = 'INVOKE_REGION_WIN'
236         layout.operator("object.armature_add", text="Single Bone", icon='BONE_DATA')
237
238
239 class INFO_MT_add(bpy.types.Menu):
240     bl_label = "Add"
241
242     def draw(self, context):
243         layout = self.layout
244
245         layout.operator_context = 'EXEC_SCREEN'
246
247         #layout.operator_menu_enum("object.mesh_add", "type", text="Mesh", icon='OUTLINER_OB_MESH')
248         layout.menu("INFO_MT_mesh_add", icon='OUTLINER_OB_MESH')
249
250         #layout.operator_menu_enum("object.curve_add", "type", text="Curve", icon='OUTLINER_OB_CURVE')
251         layout.menu("INFO_MT_curve_add", icon='OUTLINER_OB_CURVE')
252         #layout.operator_menu_enum("object.surface_add", "type", text="Surface", icon='OUTLINER_OB_SURFACE')
253         layout.menu("INFO_MT_surface_add", icon='OUTLINER_OB_SURFACE')
254         layout.operator_menu_enum("object.metaball_add", "type", text="Metaball", icon='OUTLINER_OB_META')
255         layout.operator("object.text_add", text="Text", icon='OUTLINER_OB_FONT')
256         layout.separator()
257
258         layout.operator_context = 'INVOKE_REGION_WIN'
259         layout.menu("INFO_MT_armature_add", icon='OUTLINER_OB_ARMATURE')
260         layout.operator("object.add", text="Lattice", icon='OUTLINER_OB_LATTICE').type = 'LATTICE'
261         layout.operator("object.add", text="Empty", icon='OUTLINER_OB_EMPTY').type = 'EMPTY'
262         layout.separator()
263
264         layout.operator("object.camera_add", text="Camera", icon='OUTLINER_OB_CAMERA')
265         layout.operator_context = 'EXEC_SCREEN'
266         layout.operator_menu_enum("object.lamp_add", "type", text="Lamp", icon='OUTLINER_OB_LAMP')
267         layout.separator()
268
269         layout.operator_menu_enum("object.effector_add", "type", text="Force Field", icon='OUTLINER_OB_EMPTY')
270         layout.separator()
271
272         if(len(bpy.data.groups) > 10):
273             layout.operator_context = 'INVOKE_DEFAULT'
274             layout.operator("object.group_instance_add", text="Group Instance...", icon='OUTLINER_OB_EMPTY')
275         else:
276             layout.operator_menu_enum("object.group_instance_add", "group", text="Group Instance", icon='OUTLINER_OB_EMPTY')
277
278
279 class INFO_MT_game(bpy.types.Menu):
280     bl_label = "Game"
281
282     def draw(self, context):
283         layout = self.layout
284
285         gs = context.scene.game_data
286
287         layout.operator("view3d.game_start")
288
289         layout.separator()
290
291         layout.prop(gs, "show_debug_properties")
292         layout.prop(gs, "show_framerate_profile")
293         layout.prop(gs, "show_physics_visualization")
294         layout.prop(gs, "use_deprecation_warnings")
295         layout.prop(gs, "use_animation_record")
296         layout.separator()
297         layout.prop(gs, "auto_start")
298
299
300 class INFO_MT_render(bpy.types.Menu):
301     bl_label = "Render"
302
303     def draw(self, context):
304         layout = self.layout
305
306         # rd = context.scene.render
307
308         layout.operator("render.render", text="Render Image", icon='RENDER_STILL')
309         layout.operator("render.render", text="Render Animation", icon='RENDER_ANIMATION').animation = True
310
311         layout.separator()
312
313         layout.operator("render.opengl", text="OpenGL Render Image")
314         layout.operator("render.opengl", text="OpenGL Render Animation").animation = True
315
316         layout.separator()
317
318         layout.operator("render.view_show")
319         layout.operator("render.play_rendered_anim")
320
321
322 class INFO_MT_help(bpy.types.Menu):
323     bl_label = "Help"
324
325     def draw(self, context):
326         layout = self.layout
327
328         layout.operator("wm.url_open", text="Manual", icon='HELP').url = 'http://wiki.blender.org/index.php/Doc:Manual'
329         layout.operator("wm.url_open", text="Release Log", icon='URL').url = 'http://www.blender.org/development/release-logs/blender-250/'
330
331         layout.separator()
332
333         layout.operator("wm.url_open", text="Blender Website", icon='URL').url = 'http://www.blender.org/'
334         layout.operator("wm.url_open", text="Blender e-Shop", icon='URL').url = 'http://www.blender.org/e-shop'
335         layout.operator("wm.url_open", text="Developer Community", icon='URL').url = 'http://www.blender.org/community/get-involved/'
336         layout.operator("wm.url_open", text="User Community", icon='URL').url = 'http://www.blender.org/community/user-community/'
337         layout.separator()
338         layout.operator("wm.url_open", text="Report a Bug", icon='URL').url = 'http://projects.blender.org/tracker/?atid=498&group_id=9&func=browse'
339         layout.separator()
340         layout.operator("wm.url_open", text="Python API Reference", icon='URL').url = 'http://www.blender.org/documentation/250PythonDoc/contents.html'
341         layout.operator("help.operator_cheat_sheet")
342         layout.separator()
343         layout.operator("wm.splash")
344
345
346 # Help operators
347
348
349 class HELP_OT_operator_cheat_sheet(bpy.types.Operator):
350     bl_idname = "help.operator_cheat_sheet"
351     bl_label = "Operator Cheat Sheet (new textblock)"
352
353     def execute(self, context):
354         op_strings = []
355         tot = 0
356         for op_module_name in dir(bpy.ops):
357             op_module = getattr(bpy.ops, op_module_name)
358             for op_submodule_name in dir(op_module):
359                 op = getattr(op_module, op_submodule_name)
360                 text = repr(op)
361                 if text.startswith('bpy.ops.'):
362                     op_strings.append(text)
363                     tot += 1
364
365             op_strings.append('')
366
367         textblock = bpy.data.texts.new("OperatorList.txt")
368         textblock.write('# %d Operators\n\n' % tot)
369         textblock.write('\n'.join(op_strings))
370         self.report({'INFO'}, "See OperatorList.txt textblock")
371         return {'FINISHED'}
372
373
374 classes = [
375     INFO_HT_header,
376     INFO_MT_file,
377     INFO_MT_file_open_recent,
378     INFO_MT_file_import,
379     INFO_MT_file_export,
380     INFO_MT_file_external_data,
381     INFO_MT_add,
382     INFO_MT_mesh_add,
383     INFO_MT_curve_add,
384     INFO_MT_surface_add,
385     INFO_MT_armature_add,
386     INFO_MT_game,
387     INFO_MT_render,
388     INFO_MT_help,
389
390     HELP_OT_operator_cheat_sheet]
391
392
393 def register():
394     register = bpy.types.register
395     for cls in classes:
396         register(cls)
397
398
399 def unregister():
400     unregister = bpy.types.unregister
401     for cls in classes:
402         unregister(cls)
403
404 if __name__ == "__main__":
405     register()