From 7147227a401af9f52926f225ca8518fd82f0bcc5 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Mon, 29 Sep 2025 16:54:40 +0200 Subject: [PATCH] Python API: Make context.tool_settings never null Since 1122a05cb678 tool settings could return None, but we do not check this consistently in scripts. Now always return some tool settings, since it's difficult to verify and easy to forget proper null checks in e.g. operator poll functions. The sequencer UI code was updated to continue showing tool settings only when there is a sequencer scene. Co-authored-by: Sergey Sharybin Pull Request: https://projects.blender.org/blender/blender/pulls/146166 --- scripts/startup/bl_ui/space_sequencer.py | 11 ++++++----- scripts/startup/bl_ui/space_time.py | 2 +- source/blender/makesrna/intern/rna_context.cc | 1 - 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/scripts/startup/bl_ui/space_sequencer.py b/scripts/startup/bl_ui/space_sequencer.py index 4faf2bb551b..a2f713337c5 100644 --- a/scripts/startup/bl_ui/space_sequencer.py +++ b/scripts/startup/bl_ui/space_sequencer.py @@ -174,7 +174,8 @@ class SEQUENCER_HT_header(Header): layout.separator_spacer() - tool_settings = context.tool_settings + scene = context.sequencer_scene + tool_settings = scene.tool_settings if scene else None sequencer_tool_settings = tool_settings.sequencer_tool_settings if tool_settings else None if st.view_type == 'SEQUENCER': @@ -1485,8 +1486,8 @@ class SEQUENCER_MT_pivot_pie(Menu): layout = self.layout pie = layout.menu_pie() - if context.tool_settings: - sequencer_tool_settings = context.tool_settings.sequencer_tool_settings + if context.sequencer_scene: + sequencer_tool_settings = context.sequencer_scene.tool_settings.sequencer_tool_settings pie.prop_enum(sequencer_tool_settings, "pivot_point", value='CENTER') pie.prop_enum(sequencer_tool_settings, "pivot_point", value='CURSOR') @@ -3120,7 +3121,7 @@ class SEQUENCER_PT_preview_snapping(Panel): @classmethod def poll(cls, context): st = context.space_data - return st.view_type in {'PREVIEW', 'SEQUENCER_PREVIEW'} and context.tool_settings + return st.view_type in {'PREVIEW', 'SEQUENCER_PREVIEW'} and context.sequencer_scene def draw(self, context): tool_settings = context.tool_settings @@ -3145,7 +3146,7 @@ class SEQUENCER_PT_sequencer_snapping(Panel): @classmethod def poll(cls, context): st = context.space_data - return st.view_type in {'SEQUENCER', 'SEQUENCER_PREVIEW'} and context.tool_settings + return st.view_type in {'SEQUENCER', 'SEQUENCER_PREVIEW'} and context.sequencer_scene def draw(self, context): tool_settings = context.tool_settings diff --git a/scripts/startup/bl_ui/space_time.py b/scripts/startup/bl_ui/space_time.py index 23e3f2e8918..9f4b0f66ea0 100644 --- a/scripts/startup/bl_ui/space_time.py +++ b/scripts/startup/bl_ui/space_time.py @@ -42,7 +42,7 @@ def playback_controls(layout, context): is_sequencer = st.type == 'SEQUENCE_EDITOR' and st.view_type == 'SEQUENCER' scene = context.scene if not is_sequencer else context.sequencer_scene - tool_settings = context.tool_settings + tool_settings = scene.tool_settings if scene else None screen = context.screen if scene: diff --git a/source/blender/makesrna/intern/rna_context.cc b/source/blender/makesrna/intern/rna_context.cc index 59bfe24e190..e4985245742 100644 --- a/source/blender/makesrna/intern/rna_context.cc +++ b/source/blender/makesrna/intern/rna_context.cc @@ -200,7 +200,6 @@ static PointerRNA rna_Context_tool_settings_get(PointerRNA *ptr) return RNA_pointer_create_id_subdata( *reinterpret_cast(scene), &RNA_ToolSettings, toolsettings); } - return PointerRNA_NULL; } return RNA_pointer_create_id_subdata( *reinterpret_cast(CTX_data_scene(C)), &RNA_ToolSettings, CTX_data_tool_settings(C));