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