menus are now global (like operators), so for eg, the info add menu and the 3D add...
[blender.git] / release / scripts / ui / space_info.py
1
2 import bpy
3
4 class INFO_HT_header(bpy.types.Header):
5         __space_type__ = 'INFO'
6
7         def draw(self, context):
8                 layout = self.layout
9                 
10                 st = context.space_data
11                 scene = context.scene
12                 rd = scene.render_data
13
14                 row = layout.row(align=True)
15                 row.template_header()
16
17                 if context.area.show_menus:
18                         sub = row.row(align=True)
19                         sub.itemM("INFO_MT_file")
20                         sub.itemM("INFO_MT_add")
21                         if rd.use_game_engine:
22                                 sub.itemM("INFO_MT_game")
23                         else:
24                                 sub.itemM("INFO_MT_render")
25                         sub.itemM("INFO_MT_help")
26
27                 layout.template_ID(context.window, "screen", new="screen.new", unlink="screen.delete")
28                 layout.template_ID(context.screen, "scene", new="scene.new", unlink="scene.delete")
29
30                 if rd.multiple_engines:
31                         layout.itemR(rd, "engine", text="")
32
33                 layout.itemS()
34
35                 layout.template_operator_search()
36                 layout.template_running_jobs()
37
38                 layout.itemL(text=scene.statistics())
39                         
40 class INFO_MT_file(bpy.types.Menu):
41         __label__ = "File"
42
43         def draw(self, context):
44                 layout = self.layout
45
46                 layout.operator_context = "EXEC_AREA"
47                 layout.itemO("wm.read_homefile", text="New")
48                 layout.operator_context = "INVOKE_AREA"
49                 layout.itemO("wm.open_mainfile", text="Open...")
50                 layout.item_menu_enumO("wm.open_recentfile", "file", text="Open Recent")
51                 layout.itemO("wm.recover_last_session")
52
53                 layout.itemS()
54
55                 layout.operator_context = "EXEC_AREA"
56                 layout.itemO("wm.save_mainfile", text="Save")
57                 layout.operator_context = "INVOKE_AREA"
58                 layout.itemO("wm.save_as_mainfile", text="Save As...")
59                 layout.itemO("screen.userpref_show", text="User Preferences...")
60
61                 layout.itemS()
62                 layout.operator_context = "INVOKE_AREA"
63                 layout.itemO("wm.link_append", text="Link")
64                 layout.item_booleanO("wm.link_append", "link", False, text="Append")
65                 layout.itemS()
66
67                 layout.itemM("INFO_MT_file_import")
68                 layout.itemM("INFO_MT_file_export")
69
70                 layout.itemS()
71
72                 layout.itemM("INFO_MT_file_external_data")
73
74                 layout.itemS()
75
76                 layout.operator_context = "EXEC_AREA"
77                 layout.itemO("wm.exit_blender", text="Quit")
78
79 class INFO_MT_file_import(bpy.types.Menu):
80         __label__ = "Import"
81
82         def draw(self, context):
83                 layout = self.layout
84                 
85                 layout.itemO("import.3ds", text="3DS")
86                 layout.itemO("import.obj", text="OBJ")
87
88
89 class INFO_MT_file_export(bpy.types.Menu):
90         __label__ = "Export"
91
92         def draw(self, context):
93                 layout = self.layout
94
95                 layout.itemO("export.3ds", text="3DS")
96                 layout.itemO("export.fbx", text="FBX")
97                 layout.itemO("export.obj", text="OBJ")
98                 layout.itemO("export.mdd", text="MDD")
99                 layout.itemO("export.ply", text="PLY")
100                 layout.itemO("export.x3d", text="X3D")
101
102
103 class INFO_MT_file_external_data(bpy.types.Menu):
104         __label__ = "External Data"
105
106         def draw(self, context):
107                 layout = self.layout
108
109                 layout.itemO("file.pack_all", text="Pack into .blend file")
110                 layout.itemO("file.unpack_all", text="Unpack into Files...")
111
112                 layout.itemS()
113
114                 layout.itemO("file.make_paths_relative")
115                 layout.itemO("file.make_paths_absolute")
116                 layout.itemO("file.report_missing_files")
117                 layout.itemO("file.find_missing_files")
118
119 class INFO_MT_add(bpy.types.Menu):
120         __label__ = "Add"
121
122         def draw(self, context):
123                 layout = self.layout
124
125                 layout.operator_context = "EXEC_SCREEN"
126
127                 layout.item_menu_enumO("object.mesh_add", "type", text="Mesh", icon='ICON_OUTLINER_OB_MESH')
128                 layout.item_menu_enumO("object.curve_add", "type", text="Curve", icon='ICON_OUTLINER_OB_CURVE')
129                 layout.item_menu_enumO("object.surface_add", "type", text="Surface", icon='ICON_OUTLINER_OB_SURFACE')
130                 layout.item_menu_enumO("object.metaball_add", "type", 'META', text="Metaball", icon='ICON_OUTLINER_OB_META')
131                 layout.itemO("object.text_add", text="Text", icon='ICON_OUTLINER_OB_FONT')
132
133                 layout.itemS()
134
135                 layout.itemO("object.armature_add", text="Armature", icon='ICON_OUTLINER_OB_ARMATURE')
136                 layout.item_enumO("object.add", "type", 'LATTICE', icon='ICON_OUTLINER_OB_LATTICE')
137                 layout.item_enumO("object.add", "type", 'EMPTY', icon='ICON_OUTLINER_OB_EMPTY')
138
139                 layout.itemS()
140
141                 layout.item_enumO("object.add", "type", 'CAMERA', icon='ICON_OUTLINER_OB_CAMERA')
142                 layout.item_menu_enumO("object.lamp_add", "type", 'LAMP', text="Lamp", icon='ICON_OUTLINER_OB_LAMP')
143                 
144                 layout.itemS()
145                 
146                 layout.item_menu_enumO("object.effector_add", "type", 'EMPTY', text="Force Field", icon='ICON_OUTLINER_OB_EMPTY')
147
148 class INFO_MT_game(bpy.types.Menu):
149         __label__ = "Game"
150
151         def draw(self, context):
152                 layout = self.layout
153
154                 gs = context.scene.game_data
155
156                 layout.itemO("view3d.game_start")
157
158                 layout.itemS()
159
160                 layout.itemR(gs, "show_debug_properties")
161                 layout.itemR(gs, "show_framerate_profile")
162                 layout.itemR(gs, "show_physics_visualization")
163                 layout.itemR(gs, "deprecation_warnings")
164
165 class INFO_MT_render(bpy.types.Menu):
166         __label__ = "Render"
167
168         def draw(self, context):
169                 layout = self.layout
170                 
171                 rd = context.scene.render_data
172
173                 layout.itemO("screen.render", text="Render Image")
174                 layout.item_booleanO("screen.render", "animation", True, text="Render Animation")
175
176                 layout.itemS()
177
178                 layout.itemO("screen.render_view_show")
179
180 class INFO_MT_help(bpy.types.Menu):
181         __label__ = "Help"
182
183         def draw(self, context):
184                 layout = self.layout
185
186                 layout.itemO("help.manual")
187                 layout.itemO("help.release_logs")
188
189                 layout.itemS()
190
191                 layout.itemO("help.blender_website")
192                 layout.itemO("help.blender_eshop")
193                 layout.itemO("help.developer_community")
194                 layout.itemO("help.user_community")
195                 layout.itemS()
196                 layout.itemO("help.operator_cheat_sheet")
197                 
198
199 bpy.types.register(INFO_HT_header)
200 bpy.types.register(INFO_MT_file)
201 bpy.types.register(INFO_MT_file_import)
202 bpy.types.register(INFO_MT_file_export)
203 bpy.types.register(INFO_MT_file_external_data)
204 bpy.types.register(INFO_MT_add)
205 bpy.types.register(INFO_MT_game)
206 bpy.types.register(INFO_MT_render)
207 bpy.types.register(INFO_MT_help)
208
209 # Help operators
210
211 class HelpOperator(bpy.types.Operator):
212         def execute(self, context):
213                 try: import webbrowser
214                 except: webbrowser = None
215
216                 if webbrowser:
217                         webbrowser.open(self.__URL__)
218                 else:
219                         raise Exception("Operator requires a full Python installation")
220
221                 return ('FINISHED',)
222
223 class HELP_OT_manual(HelpOperator):
224         __idname__ = "help.manual"
225         __label__ = "Manual"
226         __URL__ = 'http://wiki.blender.org/index.php/Manual'
227
228 class HELP_OT_release_logs(HelpOperator):
229         __idname__ = "help.release_logs"
230         __label__ = "Release Logs"
231         __URL__ = 'http://www.blender.org/development/release-logs/'
232
233 class HELP_OT_blender_website(HelpOperator):
234         __idname__ = "help.blender_website"
235         __label__ = "Blender Website"
236         __URL__ = 'http://www.blender.org/'
237
238 class HELP_OT_blender_eshop(HelpOperator):
239         __idname__ = "help.blender_eshop"
240         __label__ = "Blender e-Shop"
241         __URL__ = 'http://www.blender3d.org/e-shop'
242
243 class HELP_OT_developer_community(HelpOperator):
244         __idname__ = "help.developer_community"
245         __label__ = "Developer Community"
246         __URL__ = 'http://www.blender.org/community/get-involved/'
247
248 class HELP_OT_user_community(HelpOperator):
249         __idname__ = "help.user_community"
250         __label__ = "User Community"
251         __URL__ = 'http://www.blender.org/community/user-community/'
252
253 class HELP_OT_operator_cheat_sheet(bpy.types.Operator):
254         __idname__ = "help.operator_cheat_sheet"
255         __label__ = "Operator Cheet Sheet (new textblock)"
256         def execute(self, context):
257                 op_strings = []
258                 tot = 0
259                 for op_module_name in dir(bpy.ops):
260                         op_module = getattr(bpy.ops, op_module_name)
261                         for op_submodule_name in dir(op_module):
262                                 op = getattr(op_module, op_submodule_name)
263                                 text = repr(op)
264                                 if text.startswith('bpy.ops.'):
265                                         op_strings.append(text)
266                                         tot += 1
267                         
268                         op_strings.append('')
269                 
270                 bpy.ops.text.new() # XXX - assumes new text is always at the end!
271                 textblock = bpy.data.texts[-1]
272                 textblock.write('# %d Operators\n\n' % tot)
273                 textblock.write('\n'.join(op_strings))
274                 textblock.name = "OperatorList.txt"
275                 print("See OperatorList.txt textblock")
276                 return ('FINISHED',)
277
278
279 bpy.ops.add(HELP_OT_manual)
280 bpy.ops.add(HELP_OT_release_logs)
281 bpy.ops.add(HELP_OT_blender_website)
282 bpy.ops.add(HELP_OT_blender_eshop)
283 bpy.ops.add(HELP_OT_developer_community)
284 bpy.ops.add(HELP_OT_user_community)
285 bpy.ops.add(HELP_OT_operator_cheat_sheet)
286