def start(self, dummyResults='DIREKT'): """start the animation, returning its deferred""" assert self.state() != QAbstractAnimation.Running for animation in self.animations: uiTile = animation.targetObject() self.debug |= uiTile.tile in Debug.animation uiTile.setActiveAnimation(animation) self.addAnimation(animation) propName = animation.pName() animation.setStartValue(uiTile.getValue(propName)) if propName == 'rotation': # change direction if that makes the difference smaller endValue = animation.unpackEndValue() currValue = uiTile.rotation if endValue - currValue > 180: animation.setStartValue(currValue + 360) if currValue - endValue > 180: animation.setStartValue(currValue - 360) for animation in self.animations: animation.targetObject().setDrawingOrder() self.finished.connect(self.allFinished) scene = Internal.scene scene.focusRect.hide() QParallelAnimationGroup.start( self, QAbstractAnimation.DeleteWhenStopped) if self.debug: logDebug(u'Animation group %d started (%s)' % ( id(self), ','.join('A%d' % (id(x) % 10000) for x in self.animations))) return succeed(None)
def start(self, dummyResults='DIREKT'): """start the animation, returning its deferred""" if not isAlive(self): return fail() assert self.state() != QAbstractAnimation.Running for animation in self.animations: graphicsObject = animation.targetObject() if not isAlive(animation) or not isAlive(graphicsObject): return fail() graphicsObject.setActiveAnimation(animation) self.addAnimation(animation) propName = animation.pName() animation.setStartValue(graphicsObject.getValue(propName)) if propName == 'rotation': # change direction if that makes the difference smaller endValue = animation.endValue() currValue = graphicsObject.rotation if endValue - currValue > 180: animation.setStartValue(currValue + 360) if currValue - endValue > 180: animation.setStartValue(currValue - 360) for animation in self.animations: animation.targetObject().setDrawingOrder() self.finished.connect(self.allFinished) scene = Internal.scene scene.focusRect.hide() QParallelAnimationGroup.start( self, QAbstractAnimation.DeleteWhenStopped) if self.debug: logDebug('%s started with speed %d (%s)' % ( self, Internal.Preferences.animationSpeed, ','.join('A%s' % id4(x) for x in self.animations))) return succeed(None).addErrback(logException)
def updateCurrentTime(self, value): """count how many steps an animation does.""" self.steps += 1 if self.steps % 50 == 0: # periodically check if the board still exists. # if not (game end), we do not want to go on for animation in self.animations: uiTile = animation.targetObject() if not isAlive(uiTile.board): uiTile.clearActiveAnimation(animation) self.removeAnimation(animation) QParallelAnimationGroup.updateCurrentTime(self, value)
def updateCurrentTime(self, value): """count how many steps an animation does.""" self.steps += 1 if self.steps % 50 == 0: # periodically check if the board still exists. # if not (game end), we do not want to go on for animation in self.animations: graphicsObject = animation.targetObject() if hasattr(graphicsObject, 'board') and not isAlive(graphicsObject.board): graphicsObject.clearActiveAnimation(animation) self.removeAnimation(animation) QParallelAnimationGroup.updateCurrentTime(self, value)
def __init__(self, parent=None): QParallelAnimationGroup.__init__(self, parent) assert Animation.nextAnimations self.animations = Animation.nextAnimations Animation.nextAnimations = [] self.deferred = Deferred() self.steps = 0 self.debug = False self.doAfter = list() if ParallelAnimationGroup.current: if self.debug or ParallelAnimationGroup.current.debug: logDebug(u'Chaining Animation group %d to %d' % (id(self), id(ParallelAnimationGroup.current))) self.doAfter = ParallelAnimationGroup.current.doAfter ParallelAnimationGroup.current.doAfter = list() ParallelAnimationGroup.current.deferred.addCallback(self.start) else: self.start() ParallelAnimationGroup.running.append(self) ParallelAnimationGroup.current = self
def __init__(self, animations, parent=None): QParallelAnimationGroup.__init__(self, parent) self.animations = animations self.uid = ParallelAnimationGroup.clsUid ParallelAnimationGroup.clsUid += 1 self.deferred = Deferred() self.deferred.addErrback(logException) self.steps = 0 self.debug = any(x.debug for x in self.animations) self.debug |= 'G{}g'.format(id4(self)) in Debug.animation self.doAfter = list() if ParallelAnimationGroup.current: if self.debug or ParallelAnimationGroup.current.debug: logDebug('Chaining Animation group G%s to G%s' % (id4(self), ParallelAnimationGroup.current)) self.doAfter = ParallelAnimationGroup.current.doAfter ParallelAnimationGroup.current.doAfter = list() ParallelAnimationGroup.current.deferred.addCallback(self.start).addErrback(logException) else: self.start() ParallelAnimationGroup.running.append(self) ParallelAnimationGroup.current = self self.stateChanged.connect(self.showState)