This commit adds a toggle functionality to the `brush.asset_activate` operator that makes it behave similarly to the `paint.brush_select` parameter of the same name. When the operator has this option enabled, using the operator or pressing the relevant key will either: * Activate the specified brush and store it if the current brush does not match the specified brush * Activate the previously stored brush if it exists. This option is exposed in the keymaps and enabled by default for the Sculpt Mask brush. This allows, for example, users to press 'M' to switch to the mask brush and then press 'M' again to switch back to their previously active brush. Partially addresses this RCS submission: [1] [1] https://blender.community/c/rightclickselect/1VwZ/ --- ### Notes This commit does not currently clear the `AssetWeakReference` when switching paint modes. Pull Request: https://projects.blender.org/blender/blender/pulls/138845
50 lines
2.2 KiB
Python
50 lines
2.2 KiB
Python
# SPDX-FileCopyrightText: 2025 Blender Authors
|
|
#
|
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
import sys
|
|
import unittest
|
|
|
|
import bpy
|
|
|
|
|
|
class AssetActivateTest(unittest.TestCase):
|
|
def setUp(self):
|
|
# Test case isn't specific to Sculpt Mode, but we need a paint mode in general.
|
|
bpy.ops.object.mode_set(mode='SCULPT')
|
|
bpy.ops.brush.asset_activate(
|
|
asset_library_type='ESSENTIALS',
|
|
relative_asset_identifier='brushes/essentials_brushes-mesh_sculpt.blend/Brush/Draw')
|
|
|
|
def test_loads_essential_asset(self):
|
|
result = bpy.ops.brush.asset_activate(
|
|
asset_library_type='ESSENTIALS',
|
|
relative_asset_identifier='brushes/essentials_brushes-mesh_sculpt.blend/Brush/Smooth')
|
|
self.assertEqual({'FINISHED'}, result)
|
|
|
|
def test_toggle_when_brush_differs_sets_specified_brush(self):
|
|
"""Test that using the 'Toggle' parameter when the brush is not active still activates the correct brush"""
|
|
bpy.ops.brush.asset_activate(
|
|
asset_library_type='ESSENTIALS',
|
|
relative_asset_identifier='brushes/essentials_brushes-mesh_sculpt.blend/Brush/Mask',
|
|
use_toggle=True)
|
|
self.assertEqual(bpy.context.tool_settings.sculpt.brush.name, 'Mask')
|
|
|
|
def test_toggle_when_brush_matches_sets_previous_brush(self):
|
|
"""Test that using the 'Toggle' parameter when the brush is active activates the previously activated brush"""
|
|
bpy.ops.brush.asset_activate(
|
|
asset_library_type='ESSENTIALS',
|
|
relative_asset_identifier='brushes/essentials_brushes-mesh_sculpt.blend/Brush/Mask',
|
|
use_toggle=True)
|
|
self.assertEqual(bpy.context.tool_settings.sculpt.brush.name, 'Mask')
|
|
bpy.ops.brush.asset_activate(
|
|
asset_library_type='ESSENTIALS',
|
|
relative_asset_identifier='brushes/essentials_brushes-mesh_sculpt.blend/Brush/Mask',
|
|
use_toggle=True)
|
|
self.assertEqual(bpy.context.tool_settings.sculpt.brush.name, 'Draw')
|
|
|
|
|
|
if __name__ == "__main__":
|
|
# Drop all arguments before "--", or everything if the delimiter is absent. Keep the executable path.
|
|
unittest.main(argv=sys.argv[:1] + (sys.argv[sys.argv.index("--") + 1:] if "--" in sys.argv else []))
|