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