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