Changeset View
Changeset View
Standalone View
Standalone View
release/scripts/startup/bl_ui/space_spreadsheet.py
| # SPDX-License-Identifier: GPL-2.0-or-later | # SPDX-License-Identifier: GPL-2.0-or-later | ||||
| import bpy | import bpy | ||||
| class SPREADSHEET_HT_header(bpy.types.Header): | class SPREADSHEET_HT_header(bpy.types.Header): | ||||
| bl_space_type = 'SPREADSHEET' | bl_space_type = 'SPREADSHEET' | ||||
| def draw(self, context): | def draw(self, context): | ||||
| layout = self.layout | layout = self.layout | ||||
| space = context.space_data | space = context.space_data | ||||
| layout.template_header() | layout.template_header() | ||||
| viewer_path = space.viewer_path.path | |||||
| if len(space.context_path) == 0: | if len(viewer_path) == 0: | ||||
| self.draw_without_context_path(layout) | self.draw_without_viewer_path(layout) | ||||
| return | return | ||||
| root_context = space.context_path[0] | root_context = viewer_path[0] | ||||
| if root_context.type != 'OBJECT': | if root_context.type != 'ID': | ||||
| self.draw_without_context_path(layout) | self.draw_without_viewer_path(layout) | ||||
| return | return | ||||
| obj = root_context.object | if not isinstance(root_context.id, bpy.types.Object): | ||||
| self.draw_without_viewer_path(layout) | |||||
| return | |||||
| obj = root_context.id | |||||
| if obj is None: | if obj is None: | ||||
| self.draw_without_context_path(layout) | self.draw_without_viewer_path(layout) | ||||
| return | return | ||||
| layout.prop(space, "object_eval_state", text="") | layout.prop(space, "object_eval_state", text="") | ||||
| context_path = space.context_path | |||||
| if space.object_eval_state == 'ORIGINAL': | if space.object_eval_state == 'ORIGINAL': | ||||
| # Only show first context. | # Only show first context. | ||||
| context_path = context_path[:1] | viewer_path = viewer_path[:1] | ||||
| if space.display_context_path_collapsed: | if space.display_viewer_path_collapsed: | ||||
| self.draw_collapsed_context_path(context, layout, context_path) | self.draw_collapsed_viewer_path(context, layout, viewer_path) | ||||
| else: | else: | ||||
| self.draw_full_context_path(context, layout, context_path) | self.draw_full_viewer_path(context, layout, viewer_path) | ||||
| pin_icon = 'PINNED' if space.is_pinned else 'UNPINNED' | pin_icon = 'PINNED' if space.is_pinned else 'UNPINNED' | ||||
| layout.operator("spreadsheet.toggle_pin", text="", icon=pin_icon, emboss=False) | layout.operator("spreadsheet.toggle_pin", text="", icon=pin_icon, emboss=False) | ||||
| if space.object_eval_state == 'VIEWER_NODE' and len(context_path) < 3: | if space.object_eval_state == 'VIEWER_NODE' and len(viewer_path) < 3: | ||||
| layout.label(text="No active viewer node", icon='INFO') | layout.label(text="No active viewer node", icon='INFO') | ||||
| layout.separator_spacer() | layout.separator_spacer() | ||||
| row = layout.row(align=True) | row = layout.row(align=True) | ||||
| sub = row.row(align=True) | sub = row.row(align=True) | ||||
| sub.active = self.selection_filter_available(space) | sub.active = self.selection_filter_available(space) | ||||
| sub.prop(space, "show_only_selected", text="") | sub.prop(space, "show_only_selected", text="") | ||||
| row.prop(space, "use_filter", toggle=True, icon='FILTER', icon_only=True) | row.prop(space, "use_filter", toggle=True, icon='FILTER', icon_only=True) | ||||
| def draw_without_context_path(self, layout): | def draw_without_viewer_path(self, layout): | ||||
| layout.label(text="No active context") | layout.label(text="No active context") | ||||
| def draw_full_context_path(self, context, layout, context_path): | def draw_full_viewer_path(self, context, layout, viewer_path): | ||||
| space = context.space_data | space = context.space_data | ||||
| row = layout.row() | row = layout.row() | ||||
| for ctx in context_path[:-1]: | for ctx in viewer_path[:-1]: | ||||
| subrow = row.row(align=True) | subrow = row.row(align=True) | ||||
| self.draw_spreadsheet_context(subrow, ctx) | self.draw_spreadsheet_context(subrow, ctx) | ||||
| self.draw_spreadsheet_context_path_icon(subrow, space) | self.draw_spreadsheet_viewer_path_icon(subrow, space) | ||||
| self.draw_spreadsheet_context(row, context_path[-1]) | self.draw_spreadsheet_context(row, viewer_path[-1]) | ||||
| def draw_collapsed_context_path(self, context, layout, context_path): | def draw_collapsed_viewer_path(self, context, layout, viewer_path): | ||||
| space = context.space_data | space = context.space_data | ||||
| row = layout.row(align=True) | row = layout.row(align=True) | ||||
| self.draw_spreadsheet_context(row, context_path[0]) | self.draw_spreadsheet_context(row, viewer_path[0]) | ||||
| if len(context_path) == 1: | if len(viewer_path) == 1: | ||||
| return | return | ||||
| self.draw_spreadsheet_context_path_icon(row, space) | self.draw_spreadsheet_viewer_path_icon(row, space) | ||||
| if len(context_path) > 2: | if len(viewer_path) > 2: | ||||
| self.draw_spreadsheet_context_path_icon(row, space, icon='DOT') | self.draw_spreadsheet_viewer_path_icon(row, space, icon='DOT') | ||||
| self.draw_spreadsheet_context_path_icon(row, space) | self.draw_spreadsheet_viewer_path_icon(row, space) | ||||
| self.draw_spreadsheet_context(row, context_path[-1]) | self.draw_spreadsheet_context(row, viewer_path[-1]) | ||||
| def draw_spreadsheet_context(self, layout, ctx): | def draw_spreadsheet_context(self, layout, ctx): | ||||
| if ctx.type == 'OBJECT': | if ctx.type == 'ID': | ||||
| if ctx.object is None: | if ctx.id is not None and isinstance(ctx.id, bpy.types.Object): | ||||
| layout.label(text="<no object>", icon='OBJECT_DATA') | layout.label(text=ctx.id.name, icon='OBJECT_DATA') | ||||
| else: | else: | ||||
| layout.label(text=ctx.object.name, icon='OBJECT_DATA') | layout.label(text="Invalid id") | ||||
| elif ctx.type == 'MODIFIER': | elif ctx.type == 'MODIFIER': | ||||
| layout.label(text=ctx.modifier_name, icon='MODIFIER') | layout.label(text=ctx.modifier_name, icon='MODIFIER') | ||||
| elif ctx.type == 'NODE': | elif ctx.type == 'NODE': | ||||
| layout.label(text=ctx.node_name, icon='NODE') | layout.label(text=ctx.node_name, icon='NODE') | ||||
| def draw_spreadsheet_context_path_icon(self, layout, space, icon='RIGHTARROW_THIN'): | def draw_spreadsheet_viewer_path_icon(self, layout, space, icon='RIGHTARROW_THIN'): | ||||
| layout.prop(space, "display_context_path_collapsed", icon_only=True, emboss=False, icon=icon) | layout.prop(space, "display_viewer_path_collapsed", icon_only=True, emboss=False, icon=icon) | ||||
| def selection_filter_available(self, space): | def selection_filter_available(self, space): | ||||
| root_context = space.context_path[0] | root_context = space.viewer_path.path[0] | ||||
| if root_context.type != 'OBJECT': | if root_context.type != 'ID': | ||||
| return False | |||||
| if not isinstance(root_context.id, bpy.types.Object): | |||||
| return False | return False | ||||
| obj = root_context.object | obj = root_context.id | ||||
| if obj is None: | if obj is None: | ||||
| return False | return False | ||||
| if obj.type == 'MESH': | if obj.type == 'MESH': | ||||
| return obj.mode == 'EDIT' | return obj.mode == 'EDIT' | ||||
| if obj.type == 'CURVES': | if obj.type == 'CURVES': | ||||
| return obj.mode == 'SCULPT_CURVES' | return obj.mode == 'SCULPT_CURVES' | ||||
| return True | return True | ||||
| Show All 9 Lines | |||||