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