37075ac3188a16f7e67812348fc426455aa94351
[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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
16 #
17 # ##### END GPL LICENSE BLOCK #####
18
19 # <pep8 compliant>
20 import bpy
21
22 import dynamic_menu
23 # reload(dynamic_menu)
24
25
26 class INFO_HT_header(bpy.types.Header):
27     bl_space_type = 'INFO'
28
29     def draw(self, context):
30         layout = self.layout
31
32         window = context.window
33         scene = context.scene
34         rd = scene.render_data
35
36         row = layout.row(align=True)
37         row.template_header()
38
39         if context.area.show_menus:
40             sub = row.row(align=True)
41             sub.menu("INFO_MT_file")
42             sub.menu("INFO_MT_add")
43             if rd.use_game_engine:
44                 sub.menu("INFO_MT_game")
45             else:
46                 sub.menu("INFO_MT_render")
47             sub.menu("INFO_MT_help")
48
49         if window.screen.fullscreen:
50             layout.operator("screen.back_to_previous", icon='SCREEN_BACK', text="Back to Previous")
51             layout.separator()
52         else:
53             layout.template_ID(context.window, "screen", new="screen.new", unlink="screen.delete")
54         
55         layout.template_ID(context.screen, "scene", new="scene.new", unlink="scene.delete")
56
57         layout.separator()
58
59         if rd.multiple_engines:
60             layout.prop(rd, "engine", text="")
61
62         layout.separator()
63
64         layout.template_operator_search()
65         layout.template_running_jobs()
66
67         layout.label(text=scene.statistics())
68
69         layout.operator("wm.window_fullscreen_toggle", icon='FULLSCREEN_ENTER', text="")
70
71
72 class INFO_MT_file(bpy.types.Menu):
73     bl_label = "File"
74
75     def draw(self, context):
76         layout = self.layout
77
78         layout.operator_context = 'EXEC_AREA'
79         layout.operator("wm.read_homefile", text="New", icon='NEW')
80         layout.operator_context = 'INVOKE_AREA'
81         layout.operator("wm.open_mainfile", text="Open...", icon='FILE_FOLDER')
82         layout.operator_menu_enum("wm.open_recentfile", "file", text="Open Recent")
83         layout.operator("wm.recover_last_session")
84         layout.operator("wm.recover_auto_save", text="Recover Auto Save...")
85
86         layout.separator()
87
88         layout.operator_context = 'INVOKE_AREA'
89         layout.operator("wm.save_mainfile", text="Save", icon='FILE_TICK')
90         layout.operator_context = 'INVOKE_AREA'
91         layout.operator("wm.save_as_mainfile", text="Save As...")
92
93         layout.separator()
94
95         layout.operator("screen.userpref_show", text="User Preferences...", icon='PREFERENCES')
96         layout.operator("wm.read_homefile", text="Load Factory Settings").factory = True
97
98         layout.separator()
99
100         layout.operator_context = 'INVOKE_AREA'
101         layout.operator("wm.link_append", text="Link")
102         layout.operator("wm.link_append", text="Append").link = False
103
104         layout.separator()
105
106         layout.menu("INFO_MT_file_import")
107         layout.menu("INFO_MT_file_export")
108
109         layout.separator()
110
111         layout.menu("INFO_MT_file_external_data")
112
113         layout.separator()
114
115         layout.operator_context = 'EXEC_AREA'
116         layout.operator("wm.exit_blender", text="Quit", icon='QUIT')
117
118 # test for expanding menus
119 '''
120 class INFO_MT_file_more(INFO_MT_file):
121     bl_label = "File"
122
123     def draw(self, context):
124         layout = self.layout
125
126         layout.operator("wm.read_homefile", text="TESTING ")
127
128 dynamic_menu.setup(INFO_MT_file_more)
129 '''
130
131
132 class INFO_MT_file_import(dynamic_menu.DynMenu):
133     bl_idname = "INFO_MT_file_import"
134     bl_label = "Import"
135
136     def draw(self, context):
137         if "collada_import" in dir(bpy.ops.wm):
138             self.layout.operator("wm.collada_import", text="COLLADA (.dae)...")
139
140
141 class INFO_MT_file_export(dynamic_menu.DynMenu):
142     bl_idname = "INFO_MT_file_export"
143     bl_label = "Export"
144
145     def draw(self, context):
146         if "collada_export" in dir(bpy.ops.wm):
147             self.layout.operator("wm.collada_export", text="COLLADA (.dae)...")
148
149
150 class INFO_MT_file_external_data(bpy.types.Menu):
151     bl_label = "External Data"
152
153     def draw(self, context):
154         layout = self.layout
155
156         layout.operator("file.pack_all", text="Pack into .blend file")
157         layout.operator("file.unpack_all", text="Unpack into Files...")
158
159         layout.separator()
160
161         layout.operator("file.make_paths_relative")
162         layout.operator("file.make_paths_absolute")
163         layout.operator("file.report_missing_files")
164         layout.operator("file.find_missing_files")
165
166
167 class INFO_MT_mesh_add(dynamic_menu.DynMenu):
168     bl_idname = "INFO_MT_mesh_add"
169     bl_label = "Mesh"
170
171     def draw(self, context):
172         layout = self.layout
173         layout.operator_context = 'INVOKE_REGION_WIN'
174         layout.operator("mesh.primitive_plane_add", icon='MESH_PLANE', text="Plane")
175         layout.operator("mesh.primitive_cube_add", icon='MESH_CUBE', text="Cube")
176         layout.operator("mesh.primitive_circle_add", icon='MESH_CIRCLE', text="Circle")
177         layout.operator("mesh.primitive_uv_sphere_add", icon='MESH_UVSPHERE', text="UV Sphere")
178         layout.operator("mesh.primitive_ico_sphere_add", icon='MESH_ICOSPHERE', text="Icosphere")
179         layout.operator("mesh.primitive_tube_add", icon='MESH_TUBE', text="Tube")
180         layout.operator("mesh.primitive_cone_add", icon='MESH_CONE', text="Cone")
181         layout.separator()
182         layout.operator("mesh.primitive_grid_add", icon='MESH_GRID', text="Grid")
183         layout.operator("mesh.primitive_monkey_add", icon='MESH_MONKEY', text="Monkey")
184
185
186 class INFO_MT_add(bpy.types.Menu):
187     bl_label = "Add"
188
189     def draw(self, context):
190         layout = self.layout
191
192         layout.operator_context = 'EXEC_SCREEN'
193
194         #layout.operator_menu_enum("object.mesh_add", "type", text="Mesh", icon='OUTLINER_OB_MESH')
195         layout.menu("INFO_MT_mesh_add", icon='OUTLINER_OB_MESH')
196
197         layout.operator_menu_enum("object.curve_add", "type", text="Curve", icon='OUTLINER_OB_CURVE')
198         layout.operator_menu_enum("object.surface_add", "type", text="Surface", icon='OUTLINER_OB_SURFACE')
199         layout.operator_menu_enum("object.metaball_add", "type", 'META', text="Metaball", icon='OUTLINER_OB_META')
200         layout.operator("object.text_add", text="Text", icon='OUTLINER_OB_FONT')
201
202         layout.separator()
203
204         layout.operator_context = 'INVOKE_REGION_WIN'
205
206         layout.operator("object.armature_add", text="Armature", icon='OUTLINER_OB_ARMATURE')
207         layout.operator("object.add", text="Lattice", icon='OUTLINER_OB_LATTICE').type = 'LATTICE'
208         layout.operator("object.add", text="Empty", icon='OUTLINER_OB_EMPTY').type = 'EMPTY'
209
210         layout.separator()
211
212         layout.operator("object.add", text="Camera", icon='OUTLINER_OB_CAMERA').type = 'CAMERA'
213
214         layout.operator_context = 'EXEC_SCREEN'
215
216         layout.operator_menu_enum("object.lamp_add", "type", 'LAMP', text="Lamp", icon='OUTLINER_OB_LAMP')
217
218         layout.separator()
219
220         layout.operator_menu_enum("object.effector_add", "type", 'EMPTY', text="Force Field", icon='OUTLINER_OB_EMPTY')
221
222         layout.separator()
223
224         layout.operator_menu_enum("object.group_instance_add", "type", text="Group Instance", icon='OUTLINER_OB_EMPTY')
225
226
227 class INFO_MT_game(bpy.types.Menu):
228     bl_label = "Game"
229
230     def draw(self, context):
231         layout = self.layout
232
233         gs = context.scene.game_data
234
235         layout.operator("view3d.game_start")
236
237         layout.separator()
238
239         layout.prop(gs, "show_debug_properties")
240         layout.prop(gs, "show_framerate_profile")
241         layout.prop(gs, "show_physics_visualization")
242         layout.prop(gs, "deprecation_warnings")
243
244
245 class INFO_MT_render(bpy.types.Menu):
246     bl_label = "Render"
247
248     def draw(self, context):
249         layout = self.layout
250
251         # rd = context.scene.render_data
252
253         layout.operator("screen.render", text="Render Image", icon='RENDER_STILL')
254         layout.operator("screen.render", text="Render Animation", icon='RENDER_ANIMATION').animation = True
255
256         layout.separator()
257
258         layout.operator("screen.opengl_render", text="OpenGL Render Image")
259         layout.operator("screen.opengl_render", text="OpenGL Render Animation").animation = True
260
261         layout.separator()
262
263         layout.operator("screen.render_view_show")
264         layout.operator("screen.play_rendered_anim")
265
266
267 class INFO_MT_help(bpy.types.Menu):
268     bl_label = "Help"
269
270     def draw(self, context):
271         layout = self.layout
272
273         layout.operator("help.manual", icon='HELP')
274         layout.operator("help.release_logs", icon='URL')
275
276         layout.separator()
277
278         layout.operator("help.blender_website", icon='URL')
279         layout.operator("help.blender_eshop", icon='URL')
280         layout.operator("help.developer_community", icon='URL')
281         layout.operator("help.user_community", icon='URL')
282         layout.separator()
283         layout.operator("help.report_bug", icon='URL')
284         layout.separator()
285         layout.operator("help.python_api", icon='URL')
286         layout.operator("help.operator_cheat_sheet")
287
288 bpy.types.register(INFO_HT_header)
289 bpy.types.register(INFO_MT_file)
290 bpy.types.register(INFO_MT_file_import)
291 bpy.types.register(INFO_MT_file_export)
292 bpy.types.register(INFO_MT_file_external_data)
293 bpy.types.register(INFO_MT_add)
294 bpy.types.register(INFO_MT_mesh_add)
295 bpy.types.register(INFO_MT_game)
296 bpy.types.register(INFO_MT_render)
297 bpy.types.register(INFO_MT_help)
298
299 # Help operators
300
301
302 class HelpOperator(bpy.types.Operator):
303
304     def execute(self, context):
305         import webbrowser
306         webbrowser.open(self._url)
307         return ('FINISHED',)
308
309
310 class HELP_OT_manual(HelpOperator):
311     '''The Blender Wiki manual'''
312     bl_idname = "help.manual"
313     bl_label = "Manual"
314     _url = 'http://wiki.blender.org/index.php/Doc:Manual'
315
316
317 class HELP_OT_release_logs(HelpOperator):
318     '''Information about the changes in this version of Blender'''
319     bl_idname = "help.release_logs"
320     bl_label = "Release Log"
321     _url = 'http://www.blender.org/development/release-logs/blender-250/'
322
323
324 class HELP_OT_blender_website(HelpOperator):
325     '''The official Blender website'''
326     bl_idname = "help.blender_website"
327     bl_label = "Blender Website"
328     _url = 'http://www.blender.org/'
329
330
331 class HELP_OT_blender_eshop(HelpOperator):
332     '''Buy official Blender resources and merchandise online'''
333     bl_idname = "help.blender_eshop"
334     bl_label = "Blender e-Shop"
335     _url = 'http://www.blender3d.org/e-shop'
336
337
338 class HELP_OT_developer_community(HelpOperator):
339     '''Get involved with Blender development'''
340     bl_idname = "help.developer_community"
341     bl_label = "Developer Community"
342     _url = 'http://www.blender.org/community/get-involved/'
343
344
345 class HELP_OT_user_community(HelpOperator):
346     '''Get involved with other Blender users'''
347     bl_idname = "help.user_community"
348     bl_label = "User Community"
349     _url = 'http://www.blender.org/community/user-community/'
350
351
352 class HELP_OT_report_bug(HelpOperator):
353     '''Report a bug in the Blender bug tracker'''
354     bl_idname = "help.report_bug"
355     bl_label = "Report a Bug"
356     _url = 'http://projects.blender.org/tracker/?atid=498&group_id=9&func=browse'
357
358
359 class HELP_OT_python_api(HelpOperator):
360     '''Reference for operator and data Python API'''
361     bl_idname = "help.python_api"
362     bl_label = "Python API Reference"
363     _url = 'http://www.blender.org/documentation/250PythonDoc/'
364
365
366 class HELP_OT_operator_cheat_sheet(bpy.types.Operator):
367     bl_idname = "help.operator_cheat_sheet"
368     bl_label = "Operator Cheat Sheet (new textblock)"
369
370     def execute(self, context):
371         op_strings = []
372         tot = 0
373         for op_module_name in dir(bpy.ops):
374             op_module = getattr(bpy.ops, op_module_name)
375             for op_submodule_name in dir(op_module):
376                 op = getattr(op_module, op_submodule_name)
377                 text = repr(op)
378                 if text.startswith('bpy.ops.'):
379                     op_strings.append(text)
380                     tot += 1
381
382             op_strings.append('')
383
384         bpy.ops.text.new() # XXX - assumes new text is always at the end!
385         textblock = bpy.data.texts[-1]
386         textblock.write('# %d Operators\n\n' % tot)
387         textblock.write('\n'.join(op_strings))
388         textblock.name = "OperatorList.txt"
389         print("See OperatorList.txt textblock")
390         return ('FINISHED',)
391
392 bpy.ops.add(HELP_OT_manual)
393 bpy.ops.add(HELP_OT_release_logs)
394 bpy.ops.add(HELP_OT_blender_website)
395 bpy.ops.add(HELP_OT_blender_eshop)
396 bpy.ops.add(HELP_OT_developer_community)
397 bpy.ops.add(HELP_OT_user_community)
398 bpy.ops.add(HELP_OT_report_bug)
399 bpy.ops.add(HELP_OT_python_api)
400 bpy.ops.add(HELP_OT_operator_cheat_sheet)