Skip to content

Commit

Permalink
Merge pull request #13 from /issues/12/3.0-clipboard
Browse files Browse the repository at this point in the history
Fix Blender 3.0 clipboard ReferenceError
  • Loading branch information
igelbox authored May 5, 2022
2 parents f545057 + 0acca7f commit c770a67
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
10 changes: 5 additions & 5 deletions animation_retarget/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -33,15 +33,15 @@ 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
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

Expand Down
15 changes: 7 additions & 8 deletions tests/cases/test_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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]
Expand All @@ -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]
Expand Down

0 comments on commit c770a67

Please sign in to comment.