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