Cleanup: unused imports
[blender.git] / release / scripts / startup / bl_ui / space_topbar.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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 #
17 # ##### END GPL LICENSE BLOCK #####
18
19 # <pep8 compliant>
20 import bpy
21 from bpy.types import Header, Menu, Panel
22
23
24 class TOPBAR_HT_upper_bar(Header):
25     bl_space_type = 'TOPBAR'
26
27     def draw(self, context):
28         region = context.region
29
30         if region.alignment == 'RIGHT':
31             self.draw_right(context)
32         else:
33             self.draw_left(context)
34
35     def draw_left(self, context):
36         layout = self.layout
37
38         window = context.window
39         screen = context.screen
40
41         layout.operator("wm.splash", text="", icon='BLENDER', emboss=False)
42
43         TOPBAR_MT_editor_menus.draw_collapsible(context, layout)
44
45         layout.separator()
46
47         if not screen.show_fullscreen:
48             layout.template_ID_tabs(
49                 window, "workspace",
50                 new="workspace.add",
51                 menu="TOPBAR_MT_workspace_menu",
52             )
53         else:
54             layout.operator(
55                 "screen.back_to_previous",
56                 icon='SCREEN_BACK',
57                 text="Back to Previous",
58             )
59
60     def draw_right(self, context):
61         layout = self.layout
62
63         window = context.window
64         screen = context.screen
65         scene = window.scene
66
67         # If statusbar is hidden, still show messages at the top
68         if not screen.show_statusbar:
69             layout.template_reports_banner()
70             layout.template_running_jobs()
71
72         # Active workspace view-layer is retrieved through window, not through workspace.
73         layout.template_ID(window, "scene", new="scene.new", unlink="scene.delete")
74
75         row = layout.row(align=True)
76         row.template_search(
77             window, "view_layer",
78             scene, "view_layers",
79             new="scene.view_layer_add",
80             unlink="scene.view_layer_remove")
81
82
83 class TOPBAR_HT_lower_bar(Header):
84     bl_space_type = 'TOPBAR'
85     bl_region_type = 'WINDOW'
86
87     def draw(self, context):
88         region = context.region
89
90         if region.alignment == 'RIGHT':
91             self.draw_right(context)
92         else:
93             self.draw_left(context)
94
95     def draw_left(self, context):
96         layout = self.layout
97
98         # Active Tool
99         # -----------
100         from .space_toolsystem_common import ToolSelectPanelHelper
101         tool = ToolSelectPanelHelper.draw_active_tool_header(context, layout)
102         tool_space_type = 'VIEW_3D' if tool is None else tool.space_type
103         tool_mode = context.mode if tool is None else tool.mode
104
105         # Object Mode Options
106         # -------------------
107
108         # Example of how tool_settings can be accessed as pop-overs.
109
110         # TODO(campbell): editing options should be after active tool options
111         # (obviously separated for from the users POV)
112         draw_fn = getattr(getattr(_draw_left_context_mode, tool_space_type, None), tool_mode, None)
113         if draw_fn is not None:
114             draw_fn(context, layout, tool)
115
116         if tool_space_type == 'VIEW_3D':
117             # Note: general mode options should be added to 'draw_right'.
118             if tool_mode == 'SCULPT':
119                 if (tool is not None) and tool.has_datablock:
120                     layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".paint_common", category="")
121             elif tool_mode == 'PAINT_VERTEX':
122                 if (tool is not None) and tool.has_datablock:
123                     layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".paint_common", category="")
124             elif tool_mode == 'PAINT_WEIGHT':
125                 if (tool is not None) and tool.has_datablock:
126                     layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".paint_common", category="")
127             elif tool_mode == 'PAINT_TEXTURE':
128                 if (tool is not None) and tool.has_datablock:
129                     layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".paint_common", category="")
130             elif tool_mode == 'EDIT_ARMATURE':
131                 pass
132             elif tool_mode == 'EDIT_CURVE':
133                 pass
134             elif tool_mode == 'EDIT_MESH':
135                 pass
136             elif tool_mode == 'POSE':
137                 pass
138             elif tool_mode == 'PARTICLE':
139                 # Disable, only shows "Brush" panel, which is already in the top-bar.
140                 # if tool.has_datablock:
141                 #     layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".paint_common", category="")
142                 pass
143             elif tool_mode == 'PAINT_GPENCIL':
144                 if (tool is not None) and tool.has_datablock:
145                     layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".greasepencil_paint", category="")
146             elif tool_mode == 'SCULPT_GPENCIL':
147                 layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".greasepencil_sculpt", category="")
148             elif tool_mode == 'WEIGHT_GPENCIL':
149                 layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".greasepencil_weight", category="")
150         elif tool_space_type == 'IMAGE_EDITOR':
151             if tool_mode == 'PAINT':
152                 if (tool is not None) and tool.has_datablock:
153                     layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".paint_common_2d", category="")
154             elif context.uv_sculpt_object is not None:
155                 layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".uv_sculpt", category="")
156
157     def draw_right(self, context):
158         layout = self.layout
159
160         # Active Tool
161         # -----------
162         from .space_toolsystem_common import ToolSelectPanelHelper
163         tool = ToolSelectPanelHelper.tool_active_from_context(context)
164         tool_space_type = 'VIEW_3D' if tool is None else tool.space_type
165         tool_mode = context.mode if tool is None else tool.mode
166
167         if tool_space_type == 'VIEW_3D':
168             if tool_mode == 'SCULPT':
169                 layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".sculpt_mode", category="")
170             elif tool_mode == 'PAINT_VERTEX':
171                 layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".vertexpaint", category="")
172             elif tool_mode == 'PAINT_WEIGHT':
173                 layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".weightpaint", category="")
174             elif tool_mode == 'PAINT_TEXTURE':
175                 layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".imagepaint", category="")
176             elif tool_mode == 'EDIT_TEXT':
177                 layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".text_edit", category="")
178             elif tool_mode == 'EDIT_ARMATURE':
179                 layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".armature_edit", category="")
180             elif tool_mode == 'EDIT_METABALL':
181                 layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".mball_edit", category="")
182             elif tool_mode == 'EDIT_LATTICE':
183                 layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".lattice_edit", category="")
184             elif tool_mode == 'EDIT_CURVE':
185                 layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".curve_edit", category="")
186             elif tool_mode == 'EDIT_MESH':
187                 layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".mesh_edit", category="")
188             elif tool_mode == 'POSE':
189                 layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".posemode", category="")
190             elif tool_mode == 'PARTICLE':
191                 layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".particlemode", category="")
192             elif tool_mode == 'OBJECT':
193                 layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".objectmode", category="")
194             elif tool_mode in {'PAINT_GPENCIL', 'EDIT_GPENCIL', 'SCULPT_GPENCIL', 'WEIGHT_GPENCIL'}:
195                 # Grease pencil layer.
196                 gpl = context.active_gpencil_layer
197                 if gpl and gpl.info is not None:
198                     text = gpl.info
199                     maxw = 25
200                     if len(text) > maxw:
201                         text = text[:maxw - 5] + '..' + text[-3:]
202                 else:
203                     text = ""
204
205                 layout.label(text="Layer:")
206                 sub = layout.row()
207                 sub.ui_units_x = 8
208                 sub.popover(
209                     panel="TOPBAR_PT_gpencil_layers",
210                     text=text,
211                 )
212         elif tool_space_type == 'IMAGE_EDITOR':
213             if tool_mode == 'PAINT':
214                 layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".imagepaint_2d", category="")
215
216
217 class _draw_left_context_mode:
218     class VIEW_3D:
219         @staticmethod
220         def SCULPT(context, layout, tool):
221             if (tool is None) or (not tool.has_datablock):
222                 return
223
224             paint = context.tool_settings.sculpt
225             layout.template_ID_preview(paint, "brush", rows=3, cols=8, hide_buttons=True)
226
227             brush = paint.brush
228             if brush is None:
229                 return
230
231             from .properties_paint_common import (
232                 brush_basic_sculpt_settings,
233             )
234             brush_basic_sculpt_settings(layout, context, brush, compact=True)
235
236         @staticmethod
237         def PAINT_TEXTURE(context, layout, tool):
238             if (tool is None) or (not tool.has_datablock):
239                 return
240
241             paint = context.tool_settings.image_paint
242             layout.template_ID_preview(paint, "brush", rows=3, cols=8, hide_buttons=True)
243
244             brush = paint.brush
245             if brush is None:
246                 return
247
248             from .properties_paint_common import (
249                 UnifiedPaintPanel,
250                 brush_basic_texpaint_settings,
251             )
252             capabilities = brush.image_paint_capabilities
253             if capabilities.has_color:
254                 UnifiedPaintPanel.prop_unified_color(layout, context, brush, "color", text="")
255             brush_basic_texpaint_settings(layout, context, brush, compact=True)
256
257         @staticmethod
258         def PAINT_VERTEX(context, layout, tool):
259             if (tool is None) or (not tool.has_datablock):
260                 return
261
262             paint = context.tool_settings.vertex_paint
263             layout.template_ID_preview(paint, "brush", rows=3, cols=8, hide_buttons=True)
264
265             brush = paint.brush
266             if brush is None:
267                 return
268
269             from .properties_paint_common import (
270                 UnifiedPaintPanel,
271                 brush_basic_vpaint_settings,
272             )
273             capabilities = brush.vertex_paint_capabilities
274             if capabilities.has_color:
275                 UnifiedPaintPanel.prop_unified_color(layout, context, brush, "color", text="")
276             brush_basic_vpaint_settings(layout, context, brush, compact=True)
277
278         @staticmethod
279         def PAINT_WEIGHT(context, layout, tool):
280             if (tool is None) or (not tool.has_datablock):
281                 return
282
283             paint = context.tool_settings.weight_paint
284             layout.template_ID_preview(paint, "brush", rows=3, cols=8, hide_buttons=True)
285             brush = paint.brush
286             if brush is None:
287                 return
288
289             from .properties_paint_common import brush_basic_wpaint_settings
290             brush_basic_wpaint_settings(layout, context, brush, compact=True)
291
292         @staticmethod
293         def PAINT_GPENCIL(context, layout, tool):
294             if tool is None:
295                 return
296
297             is_paint = True
298             if tool.name in {"Line", "Box", "Circle", "Arc", "Curve"}:
299                 is_paint = False
300             elif tool.name == "Cutter":
301                 row = layout.row(align=True)
302                 row.prop(context.tool_settings.gpencil_sculpt, "intersection_threshold")
303                 return
304             elif not tool.has_datablock:
305                 return
306
307             paint = context.tool_settings.gpencil_paint
308             brush = paint.brush
309             if brush is None:
310                 return
311
312             gp_settings = brush.gpencil_settings
313
314             def draw_color_selector():
315                 ma = gp_settings.material
316                 row = layout.row(align=True)
317
318                 icon_id = 0
319                 if ma:
320                     icon_id = ma.id_data.preview.icon_id
321                     txt_ma = ma.name
322                     maxw = 25
323                     if len(txt_ma) > maxw:
324                         txt_ma = txt_ma[:maxw - 5] + '..' + txt_ma[-3:]
325                 else:
326                     txt_ma = ""
327
328                 row.label(text="Material:")
329                 sub = row.row()
330                 sub.ui_units_x = 8
331                 sub.popover(
332                     panel="TOPBAR_PT_gpencil_materials",
333                     text=txt_ma,
334                     icon_value=icon_id,
335                 )
336
337                 row.prop(gp_settings, "use_material_pin", text="")
338
339             row = layout.row(align=True)
340             tool_settings = context.scene.tool_settings
341             settings = tool_settings.gpencil_paint
342             row.template_ID_preview(settings, "brush", rows=3, cols=8, hide_buttons=True)
343
344             if brush.gpencil_tool in {'FILL', 'DRAW'}:
345                 draw_color_selector()
346
347             from .properties_paint_common import (
348                 brush_basic_gpencil_paint_settings,
349             )
350             brush_basic_gpencil_paint_settings(layout, context, brush, compact=True)
351
352             if tool.name in {"Arc", "Curve", "Line", "Box", "Circle"}:
353                 settings = context.tool_settings.gpencil_sculpt
354                 row = layout.row(align=True)
355                 row.prop(settings, "use_thickness_curve", text="", icon='CURVE_DATA')
356                 sub = row.row(align=True)
357                 sub.active = settings.use_thickness_curve
358                 sub.popover(
359                     panel="TOPBAR_PT_gpencil_primitive",
360                     text="Thickness Profile"
361                 )
362
363         @staticmethod
364         def SCULPT_GPENCIL(context, layout, tool):
365             if (tool is None) or (not tool.has_datablock):
366                 return
367             tool_settings = context.tool_settings
368             settings = tool_settings.gpencil_sculpt
369             brush = settings.brush
370
371             from .properties_paint_common import (
372                 brush_basic_gpencil_sculpt_settings,
373             )
374             brush_basic_gpencil_sculpt_settings(layout, context, brush, compact=True)
375
376         @staticmethod
377         def WEIGHT_GPENCIL(context, layout, tool):
378             if (tool is None) or (not tool.has_datablock):
379                 return
380             tool_settings = context.tool_settings
381             settings = tool_settings.gpencil_sculpt
382             brush = settings.brush
383
384             from .properties_paint_common import (
385                 brush_basic_gpencil_weight_settings,
386             )
387             brush_basic_gpencil_weight_settings(layout, context, brush, compact=True)
388
389         @staticmethod
390         def PARTICLE(context, layout, tool):
391             if (tool is None) or (not tool.has_datablock):
392                 return
393
394             # See: 'VIEW3D_PT_tools_brush', basically a duplicate
395             settings = context.tool_settings.particle_edit
396             brush = settings.brush
397             tool = settings.tool
398             if tool != 'NONE':
399                 layout.prop(brush, "size", slider=True)
400                 if tool == 'ADD':
401                     layout.prop(brush, "count")
402
403                     layout.prop(settings, "use_default_interpolate")
404                     layout.prop(brush, "steps", slider=True)
405                     layout.prop(settings, "default_key_count", slider=True)
406                 else:
407                     layout.prop(brush, "strength", slider=True)
408
409                     if tool == 'LENGTH':
410                         layout.row().prop(brush, "length_mode", expand=True)
411                     elif tool == 'PUFF':
412                         layout.row().prop(brush, "puff_mode", expand=True)
413                         layout.prop(brush, "use_puff_volume")
414                     elif tool == 'COMB':
415                         # Note: actually in 'Options' panel,
416                         # disabled when used in popover.
417                         row = layout.row()
418                         row.active = settings.is_editable
419                         row.prop(settings, "use_emitter_deflect", text="Deflect Emitter")
420                         sub = row.row(align=True)
421                         sub.active = settings.use_emitter_deflect
422                         sub.prop(settings, "emitter_distance", text="Distance")
423
424     class IMAGE_EDITOR:
425         @staticmethod
426         def VIEW(context, layout, tool):
427             tool_settings = context.tool_settings
428             if tool_settings.use_uv_sculpt:
429                 if context.mode == 'EDIT_MESH':
430                     uv_sculpt = tool_settings.uv_sculpt
431                     brush = uv_sculpt.brush
432                     if brush:
433                         from .properties_paint_common import UnifiedPaintPanel
434
435                         row = layout.row(align=True)
436                         UnifiedPaintPanel.prop_unified_size(row, context, brush, "size", slider=True)
437                         UnifiedPaintPanel.prop_unified_size(row, context, brush, "use_pressure_size", text="")
438
439                         row = layout.row(align=True)
440                         UnifiedPaintPanel.prop_unified_strength(row, context, brush, "strength", slider=True)
441                         UnifiedPaintPanel.prop_unified_strength(row, context, brush, "use_pressure_strength", text="")
442
443         @staticmethod
444         def PAINT(context, layout, tool):
445             if (tool is None) or (not tool.has_datablock):
446                 return
447
448             paint = context.tool_settings.image_paint
449             layout.template_ID_preview(paint, "brush", rows=3, cols=8, hide_buttons=True)
450
451             brush = paint.brush
452             if brush is None:
453                 return
454
455             from .properties_paint_common import (
456                 UnifiedPaintPanel,
457                 brush_basic_texpaint_settings,
458             )
459             capabilities = brush.image_paint_capabilities
460             if capabilities.has_color:
461                 UnifiedPaintPanel.prop_unified_color(layout, context, brush, "color", text="")
462             brush_basic_texpaint_settings(layout, context, brush, compact=True)
463
464
465 class TOPBAR_PT_gpencil_layers(Panel):
466     bl_space_type = 'VIEW_3D'
467     bl_region_type = 'HEADER'
468     bl_label = "Layers"
469     bl_ui_units_x = 14
470
471     @classmethod
472     def poll(cls, context):
473         if context.gpencil_data is None:
474             return False
475
476         ob = context.object
477         if ob is not None and ob.type == 'GPENCIL':
478             return True
479
480         return False
481
482     def draw(self, context):
483         layout = self.layout
484         gpd = context.gpencil_data
485
486         # Grease Pencil data...
487         if (gpd is None) or (not gpd.layers):
488             layout.operator("gpencil.layer_add", text="New Layer")
489         else:
490             self.draw_layers(context, layout, gpd)
491
492     def draw_layers(self, context, layout, gpd):
493         row = layout.row()
494
495         col = row.column()
496         layer_rows = 10
497         col.template_list("GPENCIL_UL_layer", "", gpd, "layers", gpd.layers, "active_index",
498                           rows=layer_rows, sort_reverse=True, sort_lock=True)
499
500         gpl = context.active_gpencil_layer
501         if gpl:
502             srow = col.row(align=True)
503             srow.prop(gpl, "blend_mode", text="Blend")
504
505             srow = col.row(align=True)
506             srow.prop(gpl, "opacity", text="Opacity", slider=True)
507             srow.prop(gpl, "clamp_layer", text="",
508                       icon='MOD_MASK' if gpl.clamp_layer else 'LAYER_ACTIVE')
509
510             srow = col.row(align=True)
511             srow.prop(gpl, "use_solo_mode", text="Show Only On Keyframed")
512
513         col = row.column()
514
515         sub = col.column(align=True)
516         sub.operator("gpencil.layer_add", icon='ADD', text="")
517         sub.operator("gpencil.layer_remove", icon='REMOVE', text="")
518
519         gpl = context.active_gpencil_layer
520         if gpl:
521             sub.menu("GPENCIL_MT_layer_context_menu", icon='DOWNARROW_HLT', text="")
522
523             if len(gpd.layers) > 1:
524                 col.separator()
525
526                 sub = col.column(align=True)
527                 sub.operator("gpencil.layer_move", icon='TRIA_UP', text="").type = 'UP'
528                 sub.operator("gpencil.layer_move", icon='TRIA_DOWN', text="").type = 'DOWN'
529
530                 col.separator()
531
532                 sub = col.column(align=True)
533                 sub.operator("gpencil.layer_isolate", icon='LOCKED', text="").affect_visibility = False
534                 sub.operator("gpencil.layer_isolate", icon='HIDE_OFF', text="").affect_visibility = True
535
536
537 class TOPBAR_MT_editor_menus(Menu):
538     bl_idname = "TOPBAR_MT_editor_menus"
539     bl_label = ""
540
541     def draw(self, context):
542         layout = self.layout
543         layout.menu("TOPBAR_MT_file")
544         layout.menu("TOPBAR_MT_edit")
545
546         layout.menu("TOPBAR_MT_render")
547
548         layout.menu("TOPBAR_MT_window")
549         layout.menu("TOPBAR_MT_help")
550
551
552 class TOPBAR_MT_file(Menu):
553     bl_label = "File"
554
555     def draw(self, context):
556         layout = self.layout
557
558         layout.operator_context = 'INVOKE_AREA'
559         layout.menu("TOPBAR_MT_file_new", text="New", icon='FILE_NEW')
560         layout.operator("wm.open_mainfile", text="Open...", icon='FILE_FOLDER')
561         layout.menu("TOPBAR_MT_file_open_recent")
562         layout.operator("wm.revert_mainfile")
563         layout.operator("wm.recover_last_session")
564         layout.operator("wm.recover_auto_save", text="Recover Auto Save...")
565
566         layout.separator()
567
568         layout.operator_context = 'EXEC_AREA' if context.blend_data.is_saved else 'INVOKE_AREA'
569         layout.operator("wm.save_mainfile", text="Save", icon='FILE_TICK')
570
571         layout.operator_context = 'INVOKE_AREA'
572         layout.operator("wm.save_as_mainfile", text="Save As...")
573         layout.operator_context = 'INVOKE_AREA'
574         layout.operator("wm.save_as_mainfile", text="Save Copy...").copy = True
575
576         layout.separator()
577         layout.operator_context = 'INVOKE_AREA'
578
579         if any(bpy.utils.app_template_paths()):
580             app_template = context.preferences.app_template
581         else:
582             app_template = None
583
584         if app_template:
585             layout.label(text=bpy.path.display_name(app_template, has_ext=False))
586             layout.operator("wm.save_homefile")
587             layout.operator(
588                 "wm.read_factory_settings",
589                 text="Load Factory Settings",
590             ).app_template = app_template
591         else:
592             layout.operator("wm.save_homefile")
593             layout.operator("wm.read_factory_settings")
594
595         layout.separator()
596
597         layout.operator("preferences.app_template_install", text="Install Application Template...")
598
599         layout.separator()
600
601         layout.operator_context = 'INVOKE_AREA'
602         layout.operator("wm.link", text="Link...", icon='LINK_BLEND')
603         layout.operator("wm.append", text="Append...", icon='APPEND_BLEND')
604         layout.menu("TOPBAR_MT_file_previews")
605
606         layout.separator()
607
608         layout.menu("TOPBAR_MT_file_import", icon='IMPORT')
609         layout.menu("TOPBAR_MT_file_export", icon='EXPORT')
610
611         layout.separator()
612
613         layout.menu("TOPBAR_MT_file_external_data")
614
615         layout.separator()
616
617         layout.operator_context = 'EXEC_AREA'
618         if bpy.data.is_dirty:
619             layout.operator_context = 'INVOKE_SCREEN'  # quit dialog
620         layout.operator("wm.quit_blender", text="Quit", icon='QUIT')
621
622
623 class TOPBAR_MT_file_new(Menu):
624     bl_label = "New File"
625
626     @staticmethod
627     def app_template_paths():
628         import os
629
630         template_paths = bpy.utils.app_template_paths()
631
632         # expand template paths
633         app_templates = []
634         for path in template_paths:
635             for d in os.listdir(path):
636                 if d.startswith(("__", ".")):
637                     continue
638                 template = os.path.join(path, d)
639                 if os.path.isdir(template):
640                     # template_paths_expand.append(template)
641                     app_templates.append(d)
642
643         return sorted(app_templates)
644
645     def draw_ex(layout, context, *, use_splash=False, use_more=False):
646         layout.operator_context = 'EXEC_DEFAULT'
647
648         # Limit number of templates in splash screen, spill over into more menu.
649         paths = TOPBAR_MT_file_new.app_template_paths()
650         splash_limit = 5
651
652         if use_splash:
653             icon = 'FILE_NEW'
654             show_more = len(paths) > (splash_limit - 1)
655             if show_more:
656                 paths = paths[:splash_limit - 2]
657         elif use_more:
658             icon = 'FILE_NEW'
659             paths = paths[splash_limit - 2:]
660             show_more = False
661         else:
662             icon = 'NONE'
663             show_more = False
664
665         # Draw application templates.
666         if not use_more:
667             props = layout.operator("wm.read_homefile", text="General", icon=icon)
668             props.app_template = ""
669
670         for d in paths:
671             props = layout.operator(
672                 "wm.read_homefile",
673                 text=bpy.path.display_name(d),
674                 icon=icon,
675             )
676             props.app_template = d
677
678         if show_more:
679             layout.menu("TOPBAR_MT_templates_more", text="...")
680
681     def draw(self, context):
682         TOPBAR_MT_file_new.draw_ex(self.layout, context)
683
684
685 class TOPBAR_MT_templates_more(Menu):
686     bl_label = "Templates"
687
688     def draw(self, context):
689         bpy.types.TOPBAR_MT_file_new.draw_ex(self.layout, context, use_more=True)
690
691
692 class TOPBAR_MT_file_import(Menu):
693     bl_idname = "TOPBAR_MT_file_import"
694     bl_label = "Import"
695
696     def draw(self, context):
697         if bpy.app.build_options.collada:
698             self.layout.operator("wm.collada_import", text="Collada (Default) (.dae)")
699         if bpy.app.build_options.alembic:
700             self.layout.operator("wm.alembic_import", text="Alembic (.abc)")
701
702
703 class TOPBAR_MT_file_export(Menu):
704     bl_idname = "TOPBAR_MT_file_export"
705     bl_label = "Export"
706
707     def draw(self, context):
708         if bpy.app.build_options.collada:
709             self.layout.operator("wm.collada_export", text="Collada (Default) (.dae)")
710         if bpy.app.build_options.alembic:
711             self.layout.operator("wm.alembic_export", text="Alembic (.abc)")
712
713
714 class TOPBAR_MT_file_external_data(Menu):
715     bl_label = "External Data"
716
717     def draw(self, context):
718         layout = self.layout
719
720         icon = 'CHECKBOX_HLT' if bpy.data.use_autopack else 'CHECKBOX_DEHLT'
721         layout.operator("file.autopack_toggle", icon=icon)
722
723         layout.separator()
724
725         pack_all = layout.row()
726         pack_all.operator("file.pack_all")
727         pack_all.active = not bpy.data.use_autopack
728
729         unpack_all = layout.row()
730         unpack_all.operator("file.unpack_all")
731         unpack_all.active = not bpy.data.use_autopack
732
733         layout.separator()
734
735         layout.operator("file.make_paths_relative")
736         layout.operator("file.make_paths_absolute")
737         layout.operator("file.report_missing_files")
738         layout.operator("file.find_missing_files")
739
740
741 class TOPBAR_MT_file_previews(Menu):
742     bl_label = "Data Previews"
743
744     def draw(self, context):
745         layout = self.layout
746
747         layout.operator("wm.previews_ensure")
748         layout.operator("wm.previews_batch_generate")
749
750         layout.separator()
751
752         layout.operator("wm.previews_clear")
753         layout.operator("wm.previews_batch_clear")
754
755
756 class TOPBAR_MT_render(Menu):
757     bl_label = "Render"
758
759     def draw(self, context):
760         layout = self.layout
761
762         rd = context.scene.render
763
764         layout.operator("render.render", text="Render Image", icon='RENDER_STILL').use_viewport = True
765         props = layout.operator("render.render", text="Render Animation", icon='RENDER_ANIMATION')
766         props.animation = True
767         props.use_viewport = True
768
769         layout.separator()
770
771         layout.operator("sound.mixdown", text="Render Audio...")
772
773         layout.separator()
774
775         layout.operator("render.view_show", text="View Render")
776         layout.operator("render.play_rendered_anim", text="View Animation")
777         layout.prop_menu_enum(rd, "display_mode", text="Display Mode")
778
779         layout.separator()
780
781         layout.prop(rd, "use_lock_interface", text="Lock Interface")
782
783
784 class TOPBAR_MT_edit(Menu):
785     bl_label = "Edit"
786
787     def draw(self, context):
788         layout = self.layout
789
790         layout.operator("ed.undo")
791         layout.operator("ed.redo")
792
793         layout.separator()
794
795         layout.operator("ed.undo_history", text="Undo History...")
796
797         layout.separator()
798
799         layout.operator("screen.repeat_last")
800         layout.operator("screen.repeat_history", text="Repeat History...")
801
802         layout.separator()
803
804         layout.operator("screen.redo_last", text="Adjust Last Operation...")
805
806         layout.separator()
807
808         layout.operator("wm.search_menu", text="Operator Search...", icon='VIEWZOOM')
809
810         layout.separator()
811
812         # Should move elsewhere (impacts outliner & 3D view).
813         tool_settings = context.tool_settings
814         layout.prop(tool_settings, "lock_object_mode")
815
816         layout.separator()
817
818         layout.operator("screen.userpref_show", text="Preferences...", icon='PREFERENCES')
819
820
821 class TOPBAR_MT_window(Menu):
822     bl_label = "Window"
823
824     def draw(self, context):
825         import sys
826
827         layout = self.layout
828
829         layout.operator("wm.window_new")
830         layout.operator("wm.window_new_main")
831
832         layout.separator()
833
834         layout.operator("wm.window_fullscreen_toggle", icon='FULLSCREEN_ENTER')
835
836         layout.separator()
837
838         layout.operator("screen.workspace_cycle", text="Next Workspace").direction = 'NEXT'
839         layout.operator("screen.workspace_cycle", text="Previous Workspace").direction = 'PREV'
840
841         layout.separator()
842
843         layout.prop(context.screen, "show_topbar")
844         layout.prop(context.screen, "show_statusbar")
845
846         layout.separator()
847
848         layout.operator("screen.screenshot")
849
850         if sys.platform[:3] == "win":
851             layout.separator()
852             layout.operator("wm.console_toggle", icon='CONSOLE')
853
854         if context.scene.render.use_multiview:
855             layout.separator()
856             layout.operator("wm.set_stereo_3d")
857
858
859 class TOPBAR_MT_help(Menu):
860     bl_label = "Help"
861
862     def draw(self, context):
863         # If 'url_prefill_from_blender' becomes slow it could be made into a separate operator
864         # to avoid constructing the bug report just to show this menu.
865         from bl_ui_utils.bug_report_url import url_prefill_from_blender
866
867         layout = self.layout
868
869         show_developer = context.preferences.view.show_developer_ui
870
871         layout.operator(
872             "wm.url_open", text="Manual", icon='HELP',
873         ).url = "https://docs.blender.org/manual/en/dev/"
874
875         layout.operator(
876             "wm.url_open", text="Report a Bug", icon='URL',
877         ).url = url_prefill_from_blender()
878
879         layout.separator()
880
881         layout.operator(
882             "wm.url_open", text="User Communities", icon='URL',
883         ).url = "https://www.blender.org/community/"
884         layout.operator(
885             "wm.url_open", text="Developer Community", icon='URL',
886         ).url = "https://www.blender.org/get-involved/developers/"
887
888         layout.separator()
889
890         layout.operator(
891             "wm.url_open", text="Blender Website", icon='URL',
892         ).url = "https://www.blender.org"
893         layout.operator(
894             "wm.url_open", text="Release Notes", icon='URL',
895         ).url = "https://www.blender.org/download/releases/%d-%d/" % bpy.app.version[:2]
896         layout.operator(
897             "wm.url_open", text="Credits", icon='URL',
898         ).url = "https://www.blender.org/about/credits/"
899
900         layout.separator()
901
902         layout.operator(
903             "wm.url_open", text="Blender Store", icon='URL',
904         ).url = "https://store.blender.org"
905         layout.operator(
906             "wm.url_open", text="Development Fund", icon='URL'
907         ).url = "https://fund.blender.org"
908         layout.operator(
909             "wm.url_open", text="Donate", icon='URL',
910         ).url = "https://www.blender.org/foundation/donation-payment/"
911
912         layout.separator()
913
914         if show_developer:
915             layout.operator(
916                 "wm.url_open", text="Python API Reference", icon='URL',
917             ).url = bpy.types.WM_OT_doc_view._prefix
918
919             layout.operator("wm.operator_cheat_sheet", icon='TEXT')
920
921         layout.operator("wm.sysinfo")
922
923         layout.separator()
924
925         layout.operator("wm.splash", icon='BLENDER')
926
927
928 class TOPBAR_MT_file_context_menu(Menu):
929     bl_label = "File Context Menu"
930
931     def draw(self, context):
932         layout = self.layout
933
934         layout.operator_context = 'INVOKE_AREA'
935         layout.operator("wm.read_homefile", text="New", icon='FILE_NEW')
936         layout.operator("wm.open_mainfile", text="Open...", icon='FILE_FOLDER')
937
938         layout.separator()
939
940         layout.operator("wm.link", text="Link...", icon='LINK_BLEND')
941         layout.operator("wm.append", text="Append...", icon='APPEND_BLEND')
942
943         layout.separator()
944
945         layout.menu("TOPBAR_MT_file_import", icon='IMPORT')
946         layout.menu("TOPBAR_MT_file_export", icon='EXPORT')
947
948
949 class TOPBAR_MT_window_context_menu(Menu):
950     bl_label = "Window Context Menu"
951
952     def draw(self, context):
953         layout = self.layout
954
955         layout.operator_context = 'EXEC_AREA'
956
957         layout.operator("wm.window_new")
958         layout.operator("wm.window_new_main")
959
960         layout.operator_context = 'INVOKE_AREA'
961
962         layout.operator("screen.area_dupli", icon='DUPLICATE')
963
964         layout.separator()
965
966         layout.operator("screen.area_split", text="Horizontal Split").direction = 'HORIZONTAL'
967         layout.operator("screen.area_split", text="Vertical Split").direction = 'VERTICAL'
968
969         layout.separator()
970
971         layout.operator("wm.window_fullscreen_toggle", icon='FULLSCREEN_ENTER')
972
973         layout.separator()
974
975         layout.operator("screen.userpref_show", text="Preferences...", icon='PREFERENCES')
976
977
978 class TOPBAR_MT_workspace_menu(Menu):
979     bl_label = "Workspace"
980
981     def draw(self, context):
982         layout = self.layout
983
984         layout.operator("workspace.duplicate", text="Duplicate", icon='DUPLICATE')
985         if len(bpy.data.workspaces) > 1:
986             layout.operator("workspace.delete", text="Delete", icon='REMOVE')
987
988         layout.separator()
989
990         layout.operator("workspace.reorder_to_front", text="Reorder to Front", icon='TRIA_LEFT_BAR')
991         layout.operator("workspace.reorder_to_back", text="Reorder to Back", icon='TRIA_RIGHT_BAR')
992
993         layout.separator()
994
995         # For key binding discoverability.
996         props = layout.operator("screen.workspace_cycle", text="Previous Workspace")
997         props.direction = 'PREV'
998         props = layout.operator("screen.workspace_cycle", text="Next Workspace")
999         props.direction = 'NEXT'
1000
1001
1002 class TOPBAR_PT_active_tool(Panel):
1003     bl_space_type = 'PROPERTIES'
1004     bl_region_type = 'WINDOW'
1005     bl_category = ""
1006     bl_context = ".active_tool"  # dot on purpose (access from tool settings)
1007     bl_label = "Active Tool"
1008     bl_options = {'HIDE_HEADER'}
1009
1010     def draw(self, context):
1011         layout = self.layout
1012
1013         # Panel display of topbar tool settings.
1014         # currently displays in tool settings, keep here since the same functionality is used for the topbar.
1015
1016         layout.use_property_split = True
1017         layout.use_property_decorate = False
1018
1019         from .space_toolsystem_common import ToolSelectPanelHelper
1020         ToolSelectPanelHelper.draw_active_tool_header(context, layout, show_tool_name=True)
1021
1022
1023 # Grease Pencil Object - Primitive curve
1024 class TOPBAR_PT_gpencil_primitive(Panel):
1025     bl_space_type = 'VIEW_3D'
1026     bl_region_type = 'HEADER'
1027     bl_label = "Primitives"
1028
1029     def draw(self, context):
1030         settings = context.tool_settings.gpencil_sculpt
1031
1032         layout = self.layout
1033         # Curve
1034         layout.template_curve_mapping(settings, "thickness_primitive_curve", brush=True)
1035
1036
1037 classes = (
1038     TOPBAR_HT_upper_bar,
1039     TOPBAR_HT_lower_bar,
1040     TOPBAR_MT_file_context_menu,
1041     TOPBAR_MT_window_context_menu,
1042     TOPBAR_MT_workspace_menu,
1043     TOPBAR_MT_editor_menus,
1044     TOPBAR_MT_file,
1045     TOPBAR_MT_file_new,
1046     TOPBAR_MT_templates_more,
1047     TOPBAR_MT_file_import,
1048     TOPBAR_MT_file_export,
1049     TOPBAR_MT_file_external_data,
1050     TOPBAR_MT_file_previews,
1051     TOPBAR_MT_edit,
1052     TOPBAR_MT_render,
1053     TOPBAR_MT_window,
1054     TOPBAR_MT_help,
1055     TOPBAR_PT_active_tool,
1056     TOPBAR_PT_gpencil_layers,
1057     TOPBAR_PT_gpencil_primitive,
1058 )
1059
1060 if __name__ == "__main__":  # only for live edit.
1061     from bpy.utils import register_class
1062     for cls in classes:
1063         register_class(cls)