new python submodule. eg.
[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
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         window = context.window
30         scene = context.scene
31         rd = scene.render_data
32
33         row = layout.row(align=True)
34         row.template_header()
35
36         if context.area.show_menus:
37             sub = row.row(align=True)
38             sub.menu("INFO_MT_file")
39             sub.menu("INFO_MT_add")
40             if rd.use_game_engine:
41                 sub.menu("INFO_MT_game")
42             else:
43                 sub.menu("INFO_MT_render")
44             sub.menu("INFO_MT_help")
45
46         if window.screen.fullscreen:
47             layout.operator("screen.back_to_previous", icon='SCREEN_BACK', text="Back to Previous")
48             layout.separator()
49         else:
50             layout.template_ID(context.window, "screen", new="screen.new", unlink="screen.delete")
51
52         layout.template_ID(context.screen, "scene", new="scene.new", unlink="scene.delete")
53
54         layout.separator()
55
56         if rd.multiple_engines:
57             layout.prop(rd, "engine", text="")
58
59         layout.separator()
60
61         layout.template_operator_search()
62         layout.template_running_jobs()
63
64         layout.label(text=scene.statistics())
65
66         layout.operator("wm.window_fullscreen_toggle", icon='FULLSCREEN_ENTER', text="")
67
68
69 class INFO_MT_file(bpy.types.Menu):
70     bl_label = "File"
71
72     def draw(self, context):
73         layout = self.layout
74
75         layout.operator_context = 'EXEC_AREA'
76         layout.operator("wm.read_homefile", text="New", icon='NEW')
77         layout.operator_context = 'INVOKE_AREA'
78         layout.operator("wm.open_mainfile", text="Open...", icon='FILE_FOLDER')
79         layout.menu("INFO_MT_file_open_recent")
80         layout.operator("wm.recover_last_session")
81         layout.operator("wm.recover_auto_save", text="Recover Auto Save...")
82
83         layout.separator()
84
85         layout.operator_context = 'INVOKE_AREA'
86         layout.operator("wm.save_mainfile", text="Save", icon='FILE_TICK')
87         layout.operator_context = 'INVOKE_AREA'
88         layout.operator("wm.save_as_mainfile", text="Save As...")
89
90         layout.separator()
91
92         layout.operator("screen.userpref_show", text="User Preferences...", icon='PREFERENCES')
93         layout.operator("wm.read_homefile", text="Load Factory Settings").factory = True
94
95         layout.separator()
96
97         layout.operator_context = 'INVOKE_AREA'
98         layout.operator("wm.link_append", text="Link")
99         layout.operator("wm.link_append", text="Append").link = False
100
101         layout.separator()
102
103         layout.menu("INFO_MT_file_import")
104         layout.menu("INFO_MT_file_export")
105
106         layout.separator()
107
108         layout.menu("INFO_MT_file_external_data")
109
110         layout.separator()
111
112         layout.operator_context = 'EXEC_AREA'
113         layout.operator("wm.exit_blender", text="Quit", icon='QUIT')
114
115
116 class INFO_MT_file_open_recent(bpy.types.Menu):
117     bl_idname = "INFO_MT_file_open_recent"
118     bl_label = "Open Recent..."
119
120     def draw(self, context):
121         import os
122         layout = self.layout
123         layout.operator_context = 'EXEC_AREA'
124         file = open(os.path.join(bpy.app.home, ".Blog"), "rU")
125         for line in file:
126             line = line.rstrip()
127             layout.operator("wm.open_mainfile", text=line, icon='FILE_BLEND').path = line
128         file.close()
129
130 class INFO_MT_file_import(bpy.types.Menu):
131     bl_idname = "INFO_MT_file_import"
132     bl_label = "Import"
133
134     def draw(self, context):
135         if "collada_import" in dir(bpy.ops.wm):
136             self.layout.operator("wm.collada_import", text="COLLADA (.dae)...")
137
138
139 class INFO_MT_file_export(bpy.types.Menu):
140     bl_idname = "INFO_MT_file_export"
141     bl_label = "Export"
142
143     def draw(self, context):
144         if "collada_export" in dir(bpy.ops.wm):
145             self.layout.operator("wm.collada_export", text="COLLADA (.dae)...")
146
147
148 class INFO_MT_file_external_data(bpy.types.Menu):
149     bl_label = "External Data"
150
151     def draw(self, context):
152         layout = self.layout
153
154         layout.operator("file.pack_all", text="Pack into .blend file")
155         layout.operator("file.unpack_all", text="Unpack into Files...")
156
157         layout.separator()
158
159         layout.operator("file.make_paths_relative")
160         layout.operator("file.make_paths_absolute")
161         layout.operator("file.report_missing_files")
162         layout.operator("file.find_missing_files")
163
164
165 class INFO_MT_mesh_add(bpy.types.Menu):
166     bl_idname = "INFO_MT_mesh_add"
167     bl_label = "Add Mesh"
168
169     def draw(self, context):
170         layout = self.layout
171         layout.operator_context = 'INVOKE_REGION_WIN'
172         layout.operator("mesh.primitive_plane_add", icon='MESH_PLANE', text="Plane")
173         layout.operator("mesh.primitive_cube_add", icon='MESH_CUBE', text="Cube")
174         layout.operator("mesh.primitive_circle_add", icon='MESH_CIRCLE', text="Circle")
175         layout.operator("mesh.primitive_uv_sphere_add", icon='MESH_UVSPHERE', text="UV Sphere")
176         layout.operator("mesh.primitive_ico_sphere_add", icon='MESH_ICOSPHERE', text="Icosphere")
177         layout.operator("mesh.primitive_tube_add", icon='MESH_TUBE', text="Tube")
178         layout.operator("mesh.primitive_cone_add", icon='MESH_CONE', text="Cone")
179         layout.separator()
180         layout.operator("mesh.primitive_grid_add", icon='MESH_GRID', text="Grid")
181         layout.operator("mesh.primitive_monkey_add", icon='MESH_MONKEY', text="Monkey")
182
183
184 class INFO_MT_armature_add(bpy.types.Menu):
185     bl_idname = "INFO_MT_armature_add"
186     bl_label = "Armature"
187
188     def draw(self, context):
189         layout = self.layout
190         layout.operator_context = 'INVOKE_REGION_WIN'
191         layout.operator("object.armature_add", text="Single Bone", icon='BONE_DATA')
192
193
194 class INFO_MT_add(bpy.types.Menu):
195     bl_label = "Add"
196
197     def draw(self, context):
198         layout = self.layout
199
200         layout.operator_context = 'EXEC_SCREEN'
201
202         #layout.operator_menu_enum("object.mesh_add", "type", text="Mesh", icon='OUTLINER_OB_MESH')
203         layout.menu("INFO_MT_mesh_add", icon='OUTLINER_OB_MESH')
204
205         layout.operator_menu_enum("object.curve_add", "type", text="Curve", icon='OUTLINER_OB_CURVE')
206         layout.operator_menu_enum("object.surface_add", "type", text="Surface", icon='OUTLINER_OB_SURFACE')
207         layout.operator_menu_enum("object.metaball_add", "type", 'META', text="Metaball", icon='OUTLINER_OB_META')
208         layout.operator("object.text_add", text="Text", icon='OUTLINER_OB_FONT')
209         layout.separator()
210
211         layout.operator_context = 'INVOKE_REGION_WIN'
212         layout.menu("INFO_MT_armature_add", icon='OUTLINER_OB_ARMATURE')
213         layout.operator("object.add", text="Lattice", icon='OUTLINER_OB_LATTICE').type = 'LATTICE'
214         layout.operator("object.add", text="Empty", icon='OUTLINER_OB_EMPTY').type = 'EMPTY'
215         layout.separator()
216
217         layout.operator("object.add", text="Camera", icon='OUTLINER_OB_CAMERA').type = 'CAMERA'
218         layout.operator_context = 'EXEC_SCREEN'
219         layout.operator_menu_enum("object.lamp_add", "type", 'LAMP', text="Lamp", icon='OUTLINER_OB_LAMP')
220         layout.separator()
221
222         layout.operator_menu_enum("object.effector_add", "type", 'EMPTY', text="Force Field", icon='OUTLINER_OB_EMPTY')
223         layout.separator()
224
225         layout.operator_menu_enum("object.group_instance_add", "type", text="Group Instance", icon='OUTLINER_OB_EMPTY')
226
227
228 class INFO_MT_game(bpy.types.Menu):
229     bl_label = "Game"
230
231     def draw(self, context):
232         layout = self.layout
233
234         gs = context.scene.game_data
235
236         layout.operator("view3d.game_start")
237
238         layout.separator()
239
240         layout.prop(gs, "show_debug_properties")
241         layout.prop(gs, "show_framerate_profile")
242         layout.prop(gs, "show_physics_visualization")
243         layout.prop(gs, "deprecation_warnings")
244
245
246 class INFO_MT_render(bpy.types.Menu):
247     bl_label = "Render"
248
249     def draw(self, context):
250         layout = self.layout
251
252         # rd = context.scene.render_data
253
254         layout.operator("screen.render", text="Render Image", icon='RENDER_STILL')
255         layout.operator("screen.render", text="Render Animation", icon='RENDER_ANIMATION').animation = True
256
257         layout.separator()
258
259         layout.operator("screen.opengl_render", text="OpenGL Render Image")
260         layout.operator("screen.opengl_render", text="OpenGL Render Animation").animation = True
261
262         layout.separator()
263
264         layout.operator("screen.render_view_show")
265         layout.operator("screen.play_rendered_anim")
266
267
268 class INFO_MT_help(bpy.types.Menu):
269     bl_label = "Help"
270
271     def draw(self, context):
272         layout = self.layout
273
274         layout.operator("help.manual", icon='HELP')
275         layout.operator("help.release_logs", icon='URL')
276
277         layout.separator()
278
279         layout.operator("help.blender_website", icon='URL')
280         layout.operator("help.blender_eshop", icon='URL')
281         layout.operator("help.developer_community", icon='URL')
282         layout.operator("help.user_community", icon='URL')
283         layout.separator()
284         layout.operator("help.report_bug", icon='URL')
285         layout.separator()
286         layout.operator("help.python_api", icon='URL')
287         layout.operator("help.operator_cheat_sheet")
288
289 bpy.types.register(INFO_HT_header)
290 bpy.types.register(INFO_MT_file)
291 bpy.types.register(INFO_MT_file_open_recent)
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.types.register(HELP_OT_manual)
396 bpy.types.register(HELP_OT_release_logs)
397 bpy.types.register(HELP_OT_blender_website)
398 bpy.types.register(HELP_OT_blender_eshop)
399 bpy.types.register(HELP_OT_developer_community)
400 bpy.types.register(HELP_OT_user_community)
401 bpy.types.register(HELP_OT_report_bug)
402 bpy.types.register(HELP_OT_python_api)
403 bpy.types.register(HELP_OT_operator_cheat_sheet)