4c504cd69c952fd6a0b30041e8f95c49245c1ee0
[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
203 class INFO_MT_armature_add(bpy.types.Menu):
204     bl_idname = "INFO_MT_armature_add"
205     bl_label = "Armature"
206
207     def draw(self, context):
208         layout = self.layout
209         layout.operator_context = 'INVOKE_REGION_WIN'
210         layout.operator("object.armature_add", text="Single Bone", icon='BONE_DATA')
211
212
213 class INFO_MT_add(bpy.types.Menu):
214     bl_label = "Add"
215
216     def draw(self, context):
217         layout = self.layout
218
219         layout.operator_context = 'EXEC_SCREEN'
220
221         #layout.operator_menu_enum("object.mesh_add", "type", text="Mesh", icon='OUTLINER_OB_MESH')
222         layout.menu("INFO_MT_mesh_add", icon='OUTLINER_OB_MESH')
223
224         layout.operator_menu_enum("object.curve_add", "type", text="Curve", icon='OUTLINER_OB_CURVE')
225         layout.operator_menu_enum("object.surface_add", "type", text="Surface", icon='OUTLINER_OB_SURFACE')
226         layout.operator_menu_enum("object.metaball_add", "type", text="Metaball", icon='OUTLINER_OB_META')
227         layout.operator("object.text_add", text="Text", icon='OUTLINER_OB_FONT')
228         layout.separator()
229
230         layout.operator_context = 'INVOKE_REGION_WIN'
231         layout.menu("INFO_MT_armature_add", icon='OUTLINER_OB_ARMATURE')
232         layout.operator("object.add", text="Lattice", icon='OUTLINER_OB_LATTICE').type = 'LATTICE'
233         layout.operator("object.add", text="Empty", icon='OUTLINER_OB_EMPTY').type = 'EMPTY'
234         layout.separator()
235
236         layout.operator("object.camera_add", text="Camera", icon='OUTLINER_OB_CAMERA')
237         layout.operator_context = 'EXEC_SCREEN'
238         layout.operator_menu_enum("object.lamp_add", "type", text="Lamp", icon='OUTLINER_OB_LAMP')
239         layout.separator()
240
241         layout.operator_menu_enum("object.effector_add", "type", text="Force Field", icon='OUTLINER_OB_EMPTY')
242         layout.separator()
243
244         if(len(bpy.data.groups) > 10):
245             layout.operator_context = 'INVOKE_DEFAULT'
246             layout.operator("object.group_instance_add", text="Group Instance...", icon='OUTLINER_OB_EMPTY')
247         else:
248             layout.operator_menu_enum("object.group_instance_add", "group", text="Group Instance", icon='OUTLINER_OB_EMPTY')
249
250
251 class INFO_MT_game(bpy.types.Menu):
252     bl_label = "Game"
253
254     def draw(self, context):
255         layout = self.layout
256
257         gs = context.scene.game_data
258
259         layout.operator("view3d.game_start")
260
261         layout.separator()
262
263         layout.prop(gs, "show_debug_properties")
264         layout.prop(gs, "show_framerate_profile")
265         layout.prop(gs, "show_physics_visualization")
266         layout.prop(gs, "use_deprecation_warnings")
267         layout.prop(gs, "use_animation_record")
268         layout.separator()
269         layout.prop(gs, "auto_start")
270
271
272 class INFO_MT_render(bpy.types.Menu):
273     bl_label = "Render"
274
275     def draw(self, context):
276         layout = self.layout
277
278         # rd = context.scene.render
279
280         layout.operator("render.render", text="Render Image", icon='RENDER_STILL')
281         layout.operator("render.render", text="Render Animation", icon='RENDER_ANIMATION').animation = True
282
283         layout.separator()
284
285         layout.operator("render.opengl", text="OpenGL Render Image")
286         layout.operator("render.opengl", text="OpenGL Render Animation").animation = True
287
288         layout.separator()
289
290         layout.operator("render.view_show")
291         layout.operator("render.play_rendered_anim")
292
293
294 class INFO_MT_help(bpy.types.Menu):
295     bl_label = "Help"
296
297     def draw(self, context):
298         layout = self.layout
299
300         layout.operator("help.manual", icon='HELP')
301         layout.operator("help.release_logs", icon='URL')
302
303         layout.separator()
304
305         layout.operator("help.blender_website", icon='URL')
306         layout.operator("help.blender_eshop", icon='URL')
307         layout.operator("help.developer_community", icon='URL')
308         layout.operator("help.user_community", icon='URL')
309         layout.separator()
310         layout.operator("help.report_bug", icon='URL')
311         layout.separator()
312         layout.operator("help.python_api", icon='URL')
313         layout.operator("help.operator_cheat_sheet")
314         layout.separator()
315         layout.operator("wm.splash")
316
317
318 # Help operators
319
320
321 class HelpOperator(bpy.types.Operator):
322
323     def execute(self, context):
324         import webbrowser
325         webbrowser.open(self._url)
326         return {'FINISHED'}
327
328
329 class HELP_OT_manual(HelpOperator):
330     '''The Blender Wiki manual'''
331     bl_idname = "help.manual"
332     bl_label = "Manual"
333     _url = 'http://wiki.blender.org/index.php/Doc:Manual'
334
335
336 class HELP_OT_release_logs(HelpOperator):
337     '''Information about the changes in this version of Blender'''
338     bl_idname = "help.release_logs"
339     bl_label = "Release Log"
340     _url = 'http://www.blender.org/development/release-logs/blender-250/'
341
342
343 class HELP_OT_blender_website(HelpOperator):
344     '''The official Blender website'''
345     bl_idname = "help.blender_website"
346     bl_label = "Blender Website"
347     _url = 'http://www.blender.org/'
348
349
350 class HELP_OT_blender_eshop(HelpOperator):
351     '''Buy official Blender resources and merchandise online'''
352     bl_idname = "help.blender_eshop"
353     bl_label = "Blender e-Shop"
354     _url = 'http://www.blender.org/e-shop'
355
356
357 class HELP_OT_developer_community(HelpOperator):
358     '''Get involved with Blender development'''
359     bl_idname = "help.developer_community"
360     bl_label = "Developer Community"
361     _url = 'http://www.blender.org/community/get-involved/'
362
363
364 class HELP_OT_user_community(HelpOperator):
365     '''Get involved with other Blender users'''
366     bl_idname = "help.user_community"
367     bl_label = "User Community"
368     _url = 'http://www.blender.org/community/user-community/'
369
370
371 class HELP_OT_report_bug(HelpOperator):
372     '''Report a bug in the Blender bug tracker'''
373     bl_idname = "help.report_bug"
374     bl_label = "Report a Bug"
375     _url = 'http://projects.blender.org/tracker/?atid=498&group_id=9&func=browse'
376
377
378 class HELP_OT_python_api(HelpOperator):
379     '''Reference for operator and data Python API'''
380     bl_idname = "help.python_api"
381     bl_label = "Python API Reference"
382     _url = 'http://www.blender.org/documentation/250PythonDoc/contents.html'
383
384
385 class HELP_OT_operator_cheat_sheet(bpy.types.Operator):
386     bl_idname = "help.operator_cheat_sheet"
387     bl_label = "Operator Cheat Sheet (new textblock)"
388
389     def execute(self, context):
390         op_strings = []
391         tot = 0
392         for op_module_name in dir(bpy.ops):
393             op_module = getattr(bpy.ops, op_module_name)
394             for op_submodule_name in dir(op_module):
395                 op = getattr(op_module, op_submodule_name)
396                 text = repr(op)
397                 if text.startswith('bpy.ops.'):
398                     op_strings.append(text)
399                     tot += 1
400
401             op_strings.append('')
402
403         textblock = bpy.data.texts.new("OperatorList.txt")
404         textblock.write('# %d Operators\n\n' % tot)
405         textblock.write('\n'.join(op_strings))
406         self.report({'INFO'}, "See OperatorList.txt textblock")
407         return {'FINISHED'}
408
409
410 classes = [
411     INFO_HT_header,
412     INFO_MT_file,
413     INFO_MT_file_open_recent,
414     INFO_MT_file_import,
415     INFO_MT_file_export,
416     INFO_MT_file_external_data,
417     INFO_MT_add,
418     INFO_MT_mesh_add,
419     INFO_MT_armature_add,
420     INFO_MT_game,
421     INFO_MT_render,
422     INFO_MT_help,
423
424     HELP_OT_manual,
425     HELP_OT_release_logs,
426     HELP_OT_blender_website,
427     HELP_OT_blender_eshop,
428     HELP_OT_developer_community,
429     HELP_OT_user_community,
430     HELP_OT_report_bug,
431     HELP_OT_python_api,
432     HELP_OT_operator_cheat_sheet]
433
434
435 def register():
436     register = bpy.types.register
437     for cls in classes:
438         register(cls)
439
440
441 def unregister():
442     unregister = bpy.types.unregister
443     for cls in classes:
444         unregister(cls)
445
446 if __name__ == "__main__":
447     register()