* added an armature submenu where python defined armatures can go.
[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 class INFO_MT_armature_add(dynamic_menu.DynMenu):
186     bl_idname = "INFO_MT_armature_add"
187     bl_label = "Armature"
188
189     def draw(self, context):
190         layout = self.layout
191         layout.operator_context = 'INVOKE_REGION_WIN'
192         layout.operator("object.armature_add", text="Single Bone", icon='BONE_DATA')
193
194
195 class INFO_MT_add(bpy.types.Menu):
196     bl_label = "Add"
197
198     def draw(self, context):
199         layout = self.layout
200
201         layout.operator_context = 'EXEC_SCREEN'
202
203         #layout.operator_menu_enum("object.mesh_add", "type", text="Mesh", icon='OUTLINER_OB_MESH')
204         layout.menu("INFO_MT_mesh_add", icon='OUTLINER_OB_MESH')
205
206         layout.operator_menu_enum("object.curve_add", "type", text="Curve", icon='OUTLINER_OB_CURVE')
207         layout.operator_menu_enum("object.surface_add", "type", text="Surface", icon='OUTLINER_OB_SURFACE')
208         layout.operator_menu_enum("object.metaball_add", "type", 'META', text="Metaball", icon='OUTLINER_OB_META')
209         layout.operator("object.text_add", text="Text", icon='OUTLINER_OB_FONT')
210         layout.separator()
211
212         layout.operator_context = 'INVOKE_REGION_WIN'
213         layout.menu("INFO_MT_armature_add", icon='OUTLINER_OB_ARMATURE')
214         layout.operator("object.add", text="Lattice", icon='OUTLINER_OB_LATTICE').type = 'LATTICE'
215         layout.operator("object.add", text="Empty", icon='OUTLINER_OB_EMPTY').type = 'EMPTY'
216         layout.separator()
217
218         layout.operator("object.add", text="Camera", icon='OUTLINER_OB_CAMERA').type = 'CAMERA'
219         layout.operator_context = 'EXEC_SCREEN'
220         layout.operator_menu_enum("object.lamp_add", "type", 'LAMP', text="Lamp", icon='OUTLINER_OB_LAMP')
221         layout.separator()
222
223         layout.operator_menu_enum("object.effector_add", "type", 'EMPTY', text="Force Field", icon='OUTLINER_OB_EMPTY')
224         layout.separator()
225
226         layout.operator_menu_enum("object.group_instance_add", "type", text="Group Instance", icon='OUTLINER_OB_EMPTY')
227
228
229 class INFO_MT_game(bpy.types.Menu):
230     bl_label = "Game"
231
232     def draw(self, context):
233         layout = self.layout
234
235         gs = context.scene.game_data
236
237         layout.operator("view3d.game_start")
238
239         layout.separator()
240
241         layout.prop(gs, "show_debug_properties")
242         layout.prop(gs, "show_framerate_profile")
243         layout.prop(gs, "show_physics_visualization")
244         layout.prop(gs, "deprecation_warnings")
245
246
247 class INFO_MT_render(bpy.types.Menu):
248     bl_label = "Render"
249
250     def draw(self, context):
251         layout = self.layout
252
253         # rd = context.scene.render_data
254
255         layout.operator("screen.render", text="Render Image", icon='RENDER_STILL')
256         layout.operator("screen.render", text="Render Animation", icon='RENDER_ANIMATION').animation = True
257
258         layout.separator()
259
260         layout.operator("screen.opengl_render", text="OpenGL Render Image")
261         layout.operator("screen.opengl_render", text="OpenGL Render Animation").animation = True
262
263         layout.separator()
264
265         layout.operator("screen.render_view_show")
266         layout.operator("screen.play_rendered_anim")
267
268
269 class INFO_MT_help(bpy.types.Menu):
270     bl_label = "Help"
271
272     def draw(self, context):
273         layout = self.layout
274
275         layout.operator("help.manual", icon='HELP')
276         layout.operator("help.release_logs", icon='URL')
277
278         layout.separator()
279
280         layout.operator("help.blender_website", icon='URL')
281         layout.operator("help.blender_eshop", icon='URL')
282         layout.operator("help.developer_community", icon='URL')
283         layout.operator("help.user_community", icon='URL')
284         layout.separator()
285         layout.operator("help.report_bug", icon='URL')
286         layout.separator()
287         layout.operator("help.python_api", icon='URL')
288         layout.operator("help.operator_cheat_sheet")
289
290 bpy.types.register(INFO_HT_header)
291 bpy.types.register(INFO_MT_file)
292 bpy.types.register(INFO_MT_file_import)
293 bpy.types.register(INFO_MT_file_export)
294 bpy.types.register(INFO_MT_file_external_data)
295 bpy.types.register(INFO_MT_add)
296 bpy.types.register(INFO_MT_mesh_add)
297 bpy.types.register(INFO_MT_armature_add)
298 bpy.types.register(INFO_MT_game)
299 bpy.types.register(INFO_MT_render)
300 bpy.types.register(INFO_MT_help)
301
302 # Help operators
303
304
305 class HelpOperator(bpy.types.Operator):
306
307     def execute(self, context):
308         import webbrowser
309         webbrowser.open(self._url)
310         return ('FINISHED',)
311
312
313 class HELP_OT_manual(HelpOperator):
314     '''The Blender Wiki manual'''
315     bl_idname = "help.manual"
316     bl_label = "Manual"
317     _url = 'http://wiki.blender.org/index.php/Doc:Manual'
318
319
320 class HELP_OT_release_logs(HelpOperator):
321     '''Information about the changes in this version of Blender'''
322     bl_idname = "help.release_logs"
323     bl_label = "Release Log"
324     _url = 'http://www.blender.org/development/release-logs/blender-250/'
325
326
327 class HELP_OT_blender_website(HelpOperator):
328     '''The official Blender website'''
329     bl_idname = "help.blender_website"
330     bl_label = "Blender Website"
331     _url = 'http://www.blender.org/'
332
333
334 class HELP_OT_blender_eshop(HelpOperator):
335     '''Buy official Blender resources and merchandise online'''
336     bl_idname = "help.blender_eshop"
337     bl_label = "Blender e-Shop"
338     _url = 'http://www.blender3d.org/e-shop'
339
340
341 class HELP_OT_developer_community(HelpOperator):
342     '''Get involved with Blender development'''
343     bl_idname = "help.developer_community"
344     bl_label = "Developer Community"
345     _url = 'http://www.blender.org/community/get-involved/'
346
347
348 class HELP_OT_user_community(HelpOperator):
349     '''Get involved with other Blender users'''
350     bl_idname = "help.user_community"
351     bl_label = "User Community"
352     _url = 'http://www.blender.org/community/user-community/'
353
354
355 class HELP_OT_report_bug(HelpOperator):
356     '''Report a bug in the Blender bug tracker'''
357     bl_idname = "help.report_bug"
358     bl_label = "Report a Bug"
359     _url = 'http://projects.blender.org/tracker/?atid=498&group_id=9&func=browse'
360
361
362 class HELP_OT_python_api(HelpOperator):
363     '''Reference for operator and data Python API'''
364     bl_idname = "help.python_api"
365     bl_label = "Python API Reference"
366     _url = 'http://www.blender.org/documentation/250PythonDoc/'
367
368
369 class HELP_OT_operator_cheat_sheet(bpy.types.Operator):
370     bl_idname = "help.operator_cheat_sheet"
371     bl_label = "Operator Cheat Sheet (new textblock)"
372
373     def execute(self, context):
374         op_strings = []
375         tot = 0
376         for op_module_name in dir(bpy.ops):
377             op_module = getattr(bpy.ops, op_module_name)
378             for op_submodule_name in dir(op_module):
379                 op = getattr(op_module, op_submodule_name)
380                 text = repr(op)
381                 if text.startswith('bpy.ops.'):
382                     op_strings.append(text)
383                     tot += 1
384
385             op_strings.append('')
386
387         bpy.ops.text.new() # XXX - assumes new text is always at the end!
388         textblock = bpy.data.texts[-1]
389         textblock.write('# %d Operators\n\n' % tot)
390         textblock.write('\n'.join(op_strings))
391         textblock.name = "OperatorList.txt"
392         print("See OperatorList.txt textblock")
393         return ('FINISHED',)
394
395 bpy.ops.add(HELP_OT_manual)
396 bpy.ops.add(HELP_OT_release_logs)
397 bpy.ops.add(HELP_OT_blender_website)
398 bpy.ops.add(HELP_OT_blender_eshop)
399 bpy.ops.add(HELP_OT_developer_community)
400 bpy.ops.add(HELP_OT_user_community)
401 bpy.ops.add(HELP_OT_report_bug)
402 bpy.ops.add(HELP_OT_python_api)
403 bpy.ops.add(HELP_OT_operator_cheat_sheet)