Python API: Make context.tool_settings never null

Since 1122a05cb6 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 <sergey@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/146166
This commit is contained in:
Brecht Van Lommel
2025-09-29 16:54:40 +02:00
parent 9aaefbab5b
commit 7147227a40
3 changed files with 7 additions and 7 deletions

View File

@@ -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

View File

@@ -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:

View File

@@ -200,7 +200,6 @@ static PointerRNA rna_Context_tool_settings_get(PointerRNA *ptr)
return RNA_pointer_create_id_subdata(
*reinterpret_cast<ID *>(scene), &RNA_ToolSettings, toolsettings);
}
return PointerRNA_NULL;
}
return RNA_pointer_create_id_subdata(
*reinterpret_cast<ID *>(CTX_data_scene(C)), &RNA_ToolSettings, CTX_data_tool_settings(C));