(no commit message)
[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         if last_op and last_op.has_reports:
69             layout.template_reports_banner(last_op)
70         else:
71             layout.label(text=scene.statistics())
72
73         # XXX: this should be right-aligned to the RHS of the region
74         layout.operator("wm.window_fullscreen_toggle", icon='FULLSCREEN_ENTER', text="")
75
76
77 class INFO_MT_file(bpy.types.Menu):
78     bl_label = "File"
79
80     def draw(self, context):
81         layout = self.layout
82
83         layout.operator_context = 'EXEC_AREA'
84         layout.operator("wm.read_homefile", text="New", icon='NEW')
85         layout.operator_context = 'INVOKE_AREA'
86         layout.operator("wm.open_mainfile", text="Open...", icon='FILE_FOLDER')
87         layout.menu("INFO_MT_file_open_recent")
88         layout.operator("wm.recover_last_session", icon='RECOVER_LAST')
89         layout.operator("wm.recover_auto_save", text="Recover Auto Save...")
90
91         layout.separator()
92
93         layout.operator_context = 'INVOKE_AREA'
94         layout.operator("wm.save_mainfile", text="Save", icon='FILE_TICK').check_existing = False
95         layout.operator_context = 'INVOKE_AREA'
96         layout.operator("wm.save_as_mainfile", text="Save As...")
97
98         layout.separator()
99
100         layout.operator("screen.userpref_show", text="User Preferences...", icon='PREFERENCES')
101
102         layout.operator_context = 'EXEC_AREA'
103         layout.operator("wm.read_homefile", text="Load Factory Settings").factory = True
104
105         layout.separator()
106
107         layout.operator_context = 'INVOKE_AREA'
108         layout.operator("wm.link_append", text="Link")
109         props = layout.operator("wm.link_append", text="Append")
110         props.link = False
111         props.instance_groups = False
112
113         layout.separator()
114
115         layout.menu("INFO_MT_file_import")
116         layout.menu("INFO_MT_file_export")
117
118         layout.separator()
119
120         layout.menu("INFO_MT_file_external_data")
121
122         layout.separator()
123
124         layout.operator_context = 'EXEC_AREA'
125         layout.operator("wm.exit_blender", text="Quit", icon='QUIT')
126
127
128 class INFO_MT_file_open_recent(bpy.types.Menu):
129     bl_idname = "INFO_MT_file_open_recent"
130     bl_label = "Open Recent..."
131
132     def draw(self, context):
133         import os
134         layout = self.layout
135         layout.operator_context = 'EXEC_AREA'
136
137         path = os.path.join(bpy.app.home, ".Blog")
138
139         if os.path.isfile(path):
140             file = open(path, "rU")
141             for line in file:
142                 line = line.rstrip()
143                 layout.operator("wm.open_mainfile", text=line, icon='FILE_BLEND').path = line
144             file.close()
145         else:
146             layout.label(text='No recent files')
147
148
149 class INFO_MT_file_import(bpy.types.Menu):
150     bl_idname = "INFO_MT_file_import"
151     bl_label = "Import"
152
153     def draw(self, context):
154         if "collada_import" in dir(bpy.ops.wm):
155             self.layout.operator("wm.collada_import", text="COLLADA (.dae)")
156
157
158 class INFO_MT_file_export(bpy.types.Menu):
159     bl_idname = "INFO_MT_file_export"
160     bl_label = "Export"
161
162     def draw(self, context):
163         if "collada_export" in dir(bpy.ops.wm):
164             self.layout.operator("wm.collada_export", text="COLLADA (.dae)")
165
166
167 class INFO_MT_file_external_data(bpy.types.Menu):
168     bl_label = "External Data"
169
170     def draw(self, context):
171         layout = self.layout
172
173         layout.operator("file.pack_all", text="Pack into .blend file")
174         layout.operator("file.unpack_all", text="Unpack into Files")
175
176         layout.separator()
177
178         layout.operator("file.make_paths_relative")
179         layout.operator("file.make_paths_absolute")
180         layout.operator("file.report_missing_files")
181         layout.operator("file.find_missing_files")
182
183
184 class INFO_MT_mesh_add(bpy.types.Menu):
185     bl_idname = "INFO_MT_mesh_add"
186     bl_label = "Mesh"
187
188     def draw(self, context):
189         layout = self.layout
190         layout.operator_context = 'INVOKE_REGION_WIN'
191         layout.operator("mesh.primitive_plane_add", icon='MESH_PLANE', text="Plane")
192         layout.operator("mesh.primitive_cube_add", icon='MESH_CUBE', text="Cube")
193         layout.operator("mesh.primitive_circle_add", icon='MESH_CIRCLE', text="Circle")
194         layout.operator("mesh.primitive_uv_sphere_add", icon='MESH_UVSPHERE', text="UV Sphere")
195         layout.operator("mesh.primitive_ico_sphere_add", icon='MESH_ICOSPHERE', text="Icosphere")
196         layout.operator("mesh.primitive_tube_add", icon='MESH_TUBE', text="Tube")
197         layout.operator("mesh.primitive_cone_add", icon='MESH_CONE', text="Cone")
198         layout.separator()
199         layout.operator("mesh.primitive_grid_add", icon='MESH_GRID', text="Grid")
200         layout.operator("mesh.primitive_monkey_add", icon='MESH_MONKEY', text="Monkey")
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_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_curve_path_add", icon='CURVE_PATH', text="Path")
214
215 class INFO_MT_armature_add(bpy.types.Menu):
216     bl_idname = "INFO_MT_armature_add"
217     bl_label = "Armature"
218
219     def draw(self, context):
220         layout = self.layout
221         layout.operator_context = 'INVOKE_REGION_WIN'
222         layout.operator("object.armature_add", text="Single Bone", icon='BONE_DATA')
223
224
225 class INFO_MT_add(bpy.types.Menu):
226     bl_label = "Add"
227
228     def draw(self, context):
229         layout = self.layout
230
231         layout.operator_context = 'EXEC_SCREEN'
232
233         #layout.operator_menu_enum("object.mesh_add", "type", text="Mesh", icon='OUTLINER_OB_MESH')
234         layout.menu("INFO_MT_mesh_add", icon='OUTLINER_OB_MESH')
235
236         #layout.operator_menu_enum("object.curve_add", "type", text="Curve", icon='OUTLINER_OB_CURVE')
237         layout.menu("INFO_MT_curve_add", icon='OUTLINER_OB_CURVE')
238         layout.operator_menu_enum("object.surface_add", "type", text="Surface", icon='OUTLINER_OB_SURFACE')
239         layout.operator_menu_enum("object.metaball_add", "type", text="Metaball", icon='OUTLINER_OB_META')
240         layout.operator("object.text_add", text="Text", icon='OUTLINER_OB_FONT')
241         layout.separator()
242
243         layout.operator_context = 'INVOKE_REGION_WIN'
244         layout.menu("INFO_MT_armature_add", icon='OUTLINER_OB_ARMATURE')
245         layout.operator("object.add", text="Lattice", icon='OUTLINER_OB_LATTICE').type = 'LATTICE'
246         layout.operator("object.add", text="Empty", icon='OUTLINER_OB_EMPTY').type = 'EMPTY'
247         layout.separator()
248
249         layout.operator("object.camera_add", text="Camera", icon='OUTLINER_OB_CAMERA')
250         layout.operator_context = 'EXEC_SCREEN'
251         layout.operator_menu_enum("object.lamp_add", "type", text="Lamp", icon='OUTLINER_OB_LAMP')
252         layout.separator()
253
254         layout.operator_menu_enum("object.effector_add", "type", text="Force Field", icon='OUTLINER_OB_EMPTY')
255         layout.separator()
256
257         if(len(bpy.data.groups) > 10):
258             layout.operator_context = 'INVOKE_DEFAULT'
259             layout.operator("object.group_instance_add", text="Group Instance...", icon='OUTLINER_OB_EMPTY')
260         else:
261             layout.operator_menu_enum("object.group_instance_add", "group", text="Group Instance", icon='OUTLINER_OB_EMPTY')
262
263
264 class INFO_MT_game(bpy.types.Menu):
265     bl_label = "Game"
266
267     def draw(self, context):
268         layout = self.layout
269
270         gs = context.scene.game_data
271
272         layout.operator("view3d.game_start")
273
274         layout.separator()
275
276         layout.prop(gs, "show_debug_properties")
277         layout.prop(gs, "show_framerate_profile")
278         layout.prop(gs, "show_physics_visualization")
279         layout.prop(gs, "use_deprecation_warnings")
280         layout.prop(gs, "use_animation_record")
281         layout.separator()
282         layout.prop(gs, "auto_start")
283
284
285 class INFO_MT_render(bpy.types.Menu):
286     bl_label = "Render"
287
288     def draw(self, context):
289         layout = self.layout
290
291         # rd = context.scene.render
292
293         layout.operator("render.render", text="Render Image", icon='RENDER_STILL')
294         layout.operator("render.render", text="Render Animation", icon='RENDER_ANIMATION').animation = True
295
296         layout.separator()
297
298         layout.operator("render.opengl", text="OpenGL Render Image")
299         layout.operator("render.opengl", text="OpenGL Render Animation").animation = True
300
301         layout.separator()
302
303         layout.operator("render.view_show")
304         layout.operator("render.play_rendered_anim")
305
306
307 class INFO_MT_help(bpy.types.Menu):
308     bl_label = "Help"
309
310     def draw(self, context):
311         layout = self.layout
312
313         layout.operator("help.manual", icon='HELP')
314         layout.operator("help.release_logs", icon='URL')
315
316         layout.separator()
317
318         layout.operator("help.blender_website", icon='URL')
319         layout.operator("help.blender_eshop", icon='URL')
320         layout.operator("help.developer_community", icon='URL')
321         layout.operator("help.user_community", icon='URL')
322         layout.separator()
323         layout.operator("help.report_bug", icon='URL')
324         layout.separator()
325         layout.operator("help.python_api", icon='URL')
326         layout.operator("help.operator_cheat_sheet")
327         layout.separator()
328         layout.operator("wm.splash")
329
330
331 # Help operators
332
333
334 class HelpOperator(bpy.types.Operator):
335
336     def execute(self, context):
337         import webbrowser
338         webbrowser.open(self._url)
339         return {'FINISHED'}
340
341
342 class HELP_OT_manual(HelpOperator):
343     '''The Blender Wiki manual'''
344     bl_idname = "help.manual"
345     bl_label = "Manual"
346     _url = 'http://wiki.blender.org/index.php/Doc:Manual'
347
348
349 class HELP_OT_release_logs(HelpOperator):
350     '''Information about the changes in this version of Blender'''
351     bl_idname = "help.release_logs"
352     bl_label = "Release Log"
353     _url = 'http://www.blender.org/development/release-logs/blender-250/'
354
355
356 class HELP_OT_blender_website(HelpOperator):
357     '''The official Blender website'''
358     bl_idname = "help.blender_website"
359     bl_label = "Blender Website"
360     _url = 'http://www.blender.org/'
361
362
363 class HELP_OT_blender_eshop(HelpOperator):
364     '''Buy official Blender resources and merchandise online'''
365     bl_idname = "help.blender_eshop"
366     bl_label = "Blender e-Shop"
367     _url = 'http://www.blender.org/e-shop'
368
369
370 class HELP_OT_developer_community(HelpOperator):
371     '''Get involved with Blender development'''
372     bl_idname = "help.developer_community"
373     bl_label = "Developer Community"
374     _url = 'http://www.blender.org/community/get-involved/'
375
376
377 class HELP_OT_user_community(HelpOperator):
378     '''Get involved with other Blender users'''
379     bl_idname = "help.user_community"
380     bl_label = "User Community"
381     _url = 'http://www.blender.org/community/user-community/'
382
383
384 class HELP_OT_report_bug(HelpOperator):
385     '''Report a bug in the Blender bug tracker'''
386     bl_idname = "help.report_bug"
387     bl_label = "Report a Bug"
388     _url = 'http://projects.blender.org/tracker/?atid=498&group_id=9&func=browse'
389
390
391 class HELP_OT_python_api(HelpOperator):
392     '''Reference for operator and data Python API'''
393     bl_idname = "help.python_api"
394     bl_label = "Python API Reference"
395     _url = 'http://www.blender.org/documentation/250PythonDoc/contents.html'
396
397
398 class HELP_OT_operator_cheat_sheet(bpy.types.Operator):
399     bl_idname = "help.operator_cheat_sheet"
400     bl_label = "Operator Cheat Sheet (new textblock)"
401
402     def execute(self, context):
403         op_strings = []
404         tot = 0
405         for op_module_name in dir(bpy.ops):
406             op_module = getattr(bpy.ops, op_module_name)
407             for op_submodule_name in dir(op_module):
408                 op = getattr(op_module, op_submodule_name)
409                 text = repr(op)
410                 if text.startswith('bpy.ops.'):
411                     op_strings.append(text)
412                     tot += 1
413
414             op_strings.append('')
415
416         textblock = bpy.data.texts.new("OperatorList.txt")
417         textblock.write('# %d Operators\n\n' % tot)
418         textblock.write('\n'.join(op_strings))
419         self.report({'INFO'}, "See OperatorList.txt textblock")
420         return {'FINISHED'}
421
422
423 classes = [
424     INFO_HT_header,
425     INFO_MT_file,
426     INFO_MT_file_open_recent,
427     INFO_MT_file_import,
428     INFO_MT_file_export,
429     INFO_MT_file_external_data,
430     INFO_MT_add,
431     INFO_MT_mesh_add,
432     INFO_MT_curve_add,
433     INFO_MT_armature_add,
434     INFO_MT_game,
435     INFO_MT_render,
436     INFO_MT_help,
437
438     HELP_OT_manual,
439     HELP_OT_release_logs,
440     HELP_OT_blender_website,
441     HELP_OT_blender_eshop,
442     HELP_OT_developer_community,
443     HELP_OT_user_community,
444     HELP_OT_report_bug,
445     HELP_OT_python_api,
446     HELP_OT_operator_cheat_sheet]
447
448
449 def register():
450     register = bpy.types.register
451     for cls in classes:
452         register(cls)
453
454
455 def unregister():
456     unregister = bpy.types.unregister
457     for cls in classes:
458         unregister(cls)
459
460 if __name__ == "__main__":
461     register()