tabs to spaces, remove trailing white space. (apart of pep8)
[blender-staging.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     bl_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     bl_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     bl_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     bl_idname = "INFO_MT_file_import"
100     bl_label = "Import"
101
102     def draw(self, context):
103         self.layout.itemO("WM_OT_collada_import", text="COLLADA (.dae)...")
104
105 class INFO_MT_file_export(dynamic_menu.DynMenu):
106     bl_idname = "INFO_MT_file_export"
107     bl_label = "Export"
108
109     def draw(self, context):
110         self.layout.itemO("WM_OT_collada_export", text="COLLADA (.dae)...")
111
112 class INFO_MT_file_external_data(bpy.types.Menu):
113     bl_label = "External Data"
114
115     def draw(self, context):
116         layout = self.layout
117
118         layout.itemO("file.pack_all", text="Pack into .blend file")
119         layout.itemO("file.unpack_all", text="Unpack into Files...")
120
121         layout.itemS()
122
123         layout.itemO("file.make_paths_relative")
124         layout.itemO("file.make_paths_absolute")
125         layout.itemO("file.report_missing_files")
126         layout.itemO("file.find_missing_files")
127
128 class INFO_MT_mesh_add(dynamic_menu.DynMenu):
129     bl_idname = "INFO_MT_mesh_add"
130     bl_label = "Mesh"
131     def draw(self, context):
132         layout = self.layout
133         layout.operator_context = 'INVOKE_REGION_WIN'
134         layout.itemO("mesh.primitive_plane_add", icon='ICON_MESH_PLANE', text="Plane")
135         layout.itemO("mesh.primitive_cube_add", icon='ICON_MESH_CUBE', text="Cube")
136         layout.itemO("mesh.primitive_circle_add", icon='ICON_MESH_CIRCLE', text="Circle")
137         layout.itemO("mesh.primitive_uv_sphere_add", icon='ICON_MESH_UVSPHERE', text="UV Sphere")
138         layout.itemO("mesh.primitive_ico_sphere_add", icon='ICON_MESH_ICOSPHERE', text="Icosphere")
139         layout.itemO("mesh.primitive_tube_add", icon='ICON_MESH_TUBE', text="Tube")
140         layout.itemO("mesh.primitive_cone_add", icon='ICON_MESH_CONE', text="Cone")
141         layout.itemS()
142         layout.itemO("mesh.primitive_grid_add", icon='ICON_MESH_GRID', text="Grid")
143         layout.itemO("mesh.primitive_monkey_add", icon='ICON_MESH_MONKEY', text="Monkey")
144
145 class INFO_MT_add(bpy.types.Menu):
146     bl_label = "Add"
147
148     def draw(self, context):
149         layout = self.layout
150
151         layout.operator_context = "EXEC_SCREEN"
152
153         # layout.item_menu_enumO("object.mesh_add", "type", text="Mesh", icon='ICON_OUTLINER_OB_MESH')
154         layout.itemM("INFO_MT_mesh_add", icon='ICON_OUTLINER_OB_MESH')
155
156         layout.item_menu_enumO("object.curve_add", "type", text="Curve", icon='ICON_OUTLINER_OB_CURVE')
157         layout.item_menu_enumO("object.surface_add", "type", text="Surface", icon='ICON_OUTLINER_OB_SURFACE')
158         layout.item_menu_enumO("object.metaball_add", "type", 'META', text="Metaball", icon='ICON_OUTLINER_OB_META')
159         layout.itemO("object.text_add", text="Text", icon='ICON_OUTLINER_OB_FONT')
160
161         layout.itemS()
162
163         layout.itemO("object.armature_add", text="Armature", icon='ICON_OUTLINER_OB_ARMATURE')
164         layout.item_enumO("object.add", "type", 'LATTICE', icon='ICON_OUTLINER_OB_LATTICE')
165         layout.item_enumO("object.add", "type", 'EMPTY', icon='ICON_OUTLINER_OB_EMPTY')
166
167         layout.itemS()
168
169         layout.item_enumO("object.add", "type", 'CAMERA', icon='ICON_OUTLINER_OB_CAMERA')
170         layout.item_menu_enumO("object.lamp_add", "type", 'LAMP', text="Lamp", icon='ICON_OUTLINER_OB_LAMP')
171
172         layout.itemS()
173
174         layout.item_menu_enumO("object.effector_add", "type", 'EMPTY', text="Force Field", icon='ICON_OUTLINER_OB_EMPTY')
175
176         layout.itemS()
177
178         layout.item_menu_enumO("object.group_instance_add", "type", text="Group Instance", icon='ICON_OUTLINER_OB_EMPTY')
179
180 class INFO_MT_game(bpy.types.Menu):
181     bl_label = "Game"
182
183     def draw(self, context):
184         layout = self.layout
185
186         gs = context.scene.game_data
187
188         layout.itemO("view3d.game_start")
189
190         layout.itemS()
191
192         layout.itemR(gs, "show_debug_properties")
193         layout.itemR(gs, "show_framerate_profile")
194         layout.itemR(gs, "show_physics_visualization")
195         layout.itemR(gs, "deprecation_warnings")
196
197 class INFO_MT_render(bpy.types.Menu):
198     bl_label = "Render"
199
200     def draw(self, context):
201         layout = self.layout
202
203         rd = context.scene.render_data
204
205         layout.itemO("screen.render", text="Render Image", icon='ICON_RENDER_STILL')
206         layout.item_booleanO("screen.render", "animation", True, text="Render Animation", icon='ICON_RENDER_ANIMATION')
207
208         layout.itemS()
209
210         layout.itemO("screen.opengl_render", text="OpenGL Render Image")
211         layout.item_booleanO("screen.opengl_render", "animation", True, text="OpenGL Render Animation")
212
213         layout.itemS()
214
215         layout.itemO("screen.render_view_show")
216
217 class INFO_MT_help(bpy.types.Menu):
218     bl_label = "Help"
219
220     def draw(self, context):
221         layout = self.layout
222
223         layout.itemO("help.manual", icon='ICON_HELP')
224         layout.itemO("help.release_logs", icon='ICON_URL')
225
226         layout.itemS()
227
228         layout.itemO("help.blender_website", icon='ICON_URL')
229         layout.itemO("help.blender_eshop", icon='ICON_URL')
230         layout.itemO("help.developer_community", icon='ICON_URL')
231         layout.itemO("help.user_community", icon='ICON_URL')
232         layout.itemS()
233         layout.itemO("help.report_bug", icon='ICON_URL')
234         layout.itemS()
235         layout.itemO("help.operator_cheat_sheet")
236
237 bpy.types.register(INFO_HT_header)
238 bpy.types.register(INFO_MT_file)
239 bpy.types.register(INFO_MT_file_import)
240 bpy.types.register(INFO_MT_file_export)
241 bpy.types.register(INFO_MT_file_external_data)
242 bpy.types.register(INFO_MT_add)
243 bpy.types.register(INFO_MT_mesh_add)
244 bpy.types.register(INFO_MT_game)
245 bpy.types.register(INFO_MT_render)
246 bpy.types.register(INFO_MT_help)
247
248 # Help operators
249
250 class HelpOperator(bpy.types.Operator):
251     def execute(self, context):
252         import webbrowser
253         webbrowser.open(self._url)
254         return ('FINISHED',)
255
256 class HELP_OT_manual(HelpOperator):
257     '''The Blender Wiki manual'''
258     bl_idname = "help.manual"
259     bl_label = "Manual"
260     _url = 'http://wiki.blender.org/index.php/Manual'
261
262 class HELP_OT_release_logs(HelpOperator):
263     '''Information about the changes in this version of Blender'''
264     bl_idname = "help.release_logs"
265     bl_label = "Release Logs"
266     _url = 'http://www.blender.org/development/release-logs/'
267
268 class HELP_OT_blender_website(HelpOperator):
269     '''The official Blender website'''
270     bl_idname = "help.blender_website"
271     bl_label = "Blender Website"
272     _url = 'http://www.blender.org/'
273
274 class HELP_OT_blender_eshop(HelpOperator):
275     '''Buy official Blender resources and merchandise online'''
276     bl_idname = "help.blender_eshop"
277     bl_label = "Blender e-Shop"
278     _url = 'http://www.blender3d.org/e-shop'
279
280 class HELP_OT_developer_community(HelpOperator):
281     '''Get involved with Blender development'''
282     bl_idname = "help.developer_community"
283     bl_label = "Developer Community"
284     _url = 'http://www.blender.org/community/get-involved/'
285
286 class HELP_OT_user_community(HelpOperator):
287     '''Get involved with other Blender users'''
288     bl_idname = "help.user_community"
289     bl_label = "User Community"
290     _url = 'http://www.blender.org/community/user-community/'
291
292 class HELP_OT_report_bug(HelpOperator):
293     '''Report a bug in the Blender bug tracker'''
294     bl_idname = "help.report_bug"
295     bl_label = "Report a Bug"
296     _url = 'http://projects.blender.org/tracker/?atid=498&group_id=9&func=browse'
297
298 class HELP_OT_operator_cheat_sheet(bpy.types.Operator):
299     bl_idname = "help.operator_cheat_sheet"
300     bl_label = "Operator Cheat Sheet (new textblock)"
301     def execute(self, context):
302         op_strings = []
303         tot = 0
304         for op_module_name in dir(bpy.ops):
305             op_module = getattr(bpy.ops, op_module_name)
306             for op_submodule_name in dir(op_module):
307                 op = getattr(op_module, op_submodule_name)
308                 text = repr(op)
309                 if text.startswith('bpy.ops.'):
310                     op_strings.append(text)
311                     tot += 1
312
313             op_strings.append('')
314
315         bpy.ops.text.new() # XXX - assumes new text is always at the end!
316         textblock = bpy.data.texts[-1]
317         textblock.write('# %d Operators\n\n' % tot)
318         textblock.write('\n'.join(op_strings))
319         textblock.name = "OperatorList.txt"
320         print("See OperatorList.txt textblock")
321         return ('FINISHED',)
322
323 bpy.ops.add(HELP_OT_manual)
324 bpy.ops.add(HELP_OT_release_logs)
325 bpy.ops.add(HELP_OT_blender_website)
326 bpy.ops.add(HELP_OT_blender_eshop)
327 bpy.ops.add(HELP_OT_developer_community)
328 bpy.ops.add(HELP_OT_user_community)
329 bpy.ops.add(HELP_OT_report_bug)
330 bpy.ops.add(HELP_OT_operator_cheat_sheet)