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