From 0acca7f4ab128ce50f7eb58bda8d8699a950386a Mon Sep 17 00:00:00 2001 From: Sergei Vakhurin Date: Thu, 5 May 2022 01:31:09 +0300 Subject: [PATCH] fix #12: blender 3.0 clipboard errors I have no idea how to autotest here --- animation_retarget/ops.py | 10 +++++----- tests/cases/test_ops.py | 15 +++++++-------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/animation_retarget/ops.py b/animation_retarget/ops.py index dab98c8..099e8dc 100644 --- a/animation_retarget/ops.py +++ b/animation_retarget/ops.py @@ -3,8 +3,8 @@ from .core import mapping_to_text, text_to_mapping, clear_mapping from .core import trick_blender28, need_to_trick_blender28 -WM = bpy.context.window_manager - +def GetWM(): + return bpy.context.window_manager class OBJECT_OT_CopyMapping(bpy.types.Operator): bl_idname = "animation_retarget.copy_mapping" @@ -13,7 +13,7 @@ class OBJECT_OT_CopyMapping(bpy.types.Operator): def execute(self, context): target_obj = context.active_object - WM.clipboard = mapping_to_text(target_obj) + GetWM().clipboard = mapping_to_text(target_obj) return {'FINISHED'} @classmethod @@ -33,7 +33,7 @@ class OBJECT_OT_PasteMapping(bpy.types.Operator): def execute(self, context): target_obj = context.active_object - text_to_mapping(WM.clipboard, target_obj) + text_to_mapping(GetWM().clipboard, target_obj) return {'FINISHED'} @classmethod @@ -41,7 +41,7 @@ def poll(cls, context): target_obj = context.active_object if (not target_obj) or (target_obj.type not in {'ARMATURE'}): return False - if not WM.clipboard: + if not GetWM().clipboard: return False return True diff --git a/tests/cases/test_ops.py b/tests/cases/test_ops.py index 3e932fb..46b680b 100644 --- a/tests/cases/test_ops.py +++ b/tests/cases/test_ops.py @@ -5,18 +5,17 @@ from animation_retarget import ops -class WM: - def __init__(self): - self.clipboard = '' +class WMock: + clipboard = '' class TestOperations(utils.BaseTestCase): def setUp(self): super().setUp() - ops.WM = WM() + ops.GetWM = lambda: WMock def tearDown(self): - ops.WM = bpy.context.window_manager + ops.GetWM = lambda: bpy.context.window_manager super().tearDown() def test_copy(self): @@ -37,7 +36,7 @@ def test_copy(self): self.assertTrue(operator.poll()) operator() - self.assertEqual(ops.WM.clipboard, """[object] + self.assertEqual(WMock.clipboard, """[object] source = src [bone:root] @@ -55,10 +54,10 @@ def test_paste(self): create_armature('src') tgt = create_armature('tgt') - ops.WM.clipboard = '' + WMock.clipboard = '' # the clipboard is empty self.assertFalse(operator.poll()) - ops.WM.clipboard = """ + WMock.clipboard = """ [object] source=src [bone:root]