2222from PySide2 import QtCore , QtWidgets , QtGui
2323from PySide2 .QtWidgets import QShortcut
2424from PySide2 .QtGui import QKeySequence
25+ from PySide2 .QtCore import QTimer
2526
2627# Find folder path to this file. This will enable all other files to be accessed within the same folder.
2728CurrentDirectory = os .path .dirname (__file__ )
@@ -467,6 +468,9 @@ def __init__(self, Parent = None):
467468 self .TakeList .itemCollapsed .connect (self .OnCollapse )
468469 # (Call function) Move and group items in list.
469470 self .TakeList .model ().rowsInserted .connect (self .MoveTakeItems )
471+ self .MoveTakesTimer = QTimer ()
472+ self .MoveTakesTimer .setSingleShot (True )
473+ self .MoveTakesTimer .timeout .connect (self .MoveTakeItemsOutput )
470474 # (Call function) Selecting items in list also selects takes in MotionBuilder navigator.
471475 self .TakeList .itemSelectionChanged .connect (self .MakeMoBuSelection )
472476
@@ -555,6 +559,8 @@ def __init__(self, Parent = None):
555559
556560
557561
562+ self .bIsToolInitialized = True
563+ self .bPreventInfiniteTimer = False
558564 self .bIsUpdatingNatively = True
559565 self .bIsMovingTakesFromTool = False
560566 self .bPreventSelectionUpdate = False
@@ -667,6 +673,9 @@ def OnTakeChanged(self, Scene: FBScene, Event: FBEventTakeChange):
667673 elif Event .Type == FBTakeChangeType .kFBTakeChangeMoved :
668674 if not self .bIsMovingTakesFromTool :
669675 self .RefreshTakeList (bClearSearchBar = False )
676+ Item = self .GetItemByTake (Event .Take )
677+ if IsBound (Item ):
678+ Item .setSelected (True )
670679 if self .SearchBar .text ():
671680 self .Search (self .SearchBar .text ())
672681 # Current Active Take.
@@ -1165,11 +1174,20 @@ def DeleteTakeItems(self, Item: TakeTreeItem, bDeleteChildren, bUpdateGuiOnly =
11651174 # ----------------- MOVE TAKE EVENTS ----------------- #
11661175
11671176
1177+ def StartMoveTakesTimer (self ):
1178+ """ Timer is used to reduce multiple signal emissions when moving takes into a single callback. """
1179+ if self .bPreventInfiniteTimer :
1180+ return
1181+ self .MoveTakesTimer .start (0 )
1182+ self .bPreventInfiniteTimer = True
1183+
11681184
11691185 def MoveTakeItems (self , ParentModelIndex : QtCore .QModelIndex , FirstIndex : int , LastIndex : int ):
11701186 """ Move and group items in list. """
1171- if self .bIsUpdatingNatively or self .bIsDuplicatingItems :
1187+ if self .bIsUpdatingNatively or self .bIsDuplicatingItems or self .bIsToolInitialized :
1188+ self .bIsToolInitialized = False
11721189 return
1190+ self .bPreventInfiniteTimer = False
11731191 self .bIsMovingTakesFromTool = True
11741192 self .bPreventSelectionUpdate = True
11751193 # Grouping.
@@ -1183,6 +1201,11 @@ def MoveTakeItems(self, ParentModelIndex: QtCore.QModelIndex, FirstIndex: int, L
11831201 Item .SetParentProperty (Parent )
11841202 Parent .setExpanded (True )
11851203 Item .setSelected (True )
1204+ self .StartMoveTakesTimer ()
1205+
1206+
1207+ def MoveTakeItemsOutput (self ):
1208+ """ Triggered when timer runs out, meaning this can only be called once. This finalizes the take list order. """
11861209 # Sync take order natively to match our own list.
11871210 self .SyncTakeOrderNatively ()
11881211 # Hack fix to make sure the native take list is following the tool take list.
@@ -1192,8 +1215,8 @@ def MoveTakeItems(self, ParentModelIndex: QtCore.QModelIndex, FirstIndex: int, L
11921215 self .MakeMoBuSelection ()
11931216 if self .SearchBar .text ():
11941217 self .Search (self .SearchBar .text ())
1218+
11951219
1196-
11971220
11981221 # ----------------- GROUP MANAGEMENT ----------------- #
11991222
0 commit comments