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