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