def ident(self): """the identifier to be used in debug messages""" pGroup = self.group() if isAlive(self) else 'notAlive' if pGroup or not isAlive(self): return '%s/A%s' % (pGroup, id4(self)) else: return 'A%s-%s' % (id4(self), self.targetObject().name())
def name(self): """get name for log messages. Readonly.""" stack = list(x[2] for x in traceback.extract_stack()) name = stack[-3] if name in ('__exit__', '__init__'): name = stack[-4] return '%s on %s (%x)' % (name, self.path, id4(self))
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 debugPrefix(self, dbgMarker=''): """prefix for debug message""" return 'T{table} B[{id4:>4}] {caller:<15} {dbgMarker:<3}(out={out})'.format( table=self.table.tableid, id4=id4(self), caller=self.calledBy[:15], dbgMarker=dbgMarker, out=self.outstanding)
def pretty(self): """for debug output""" result = '' if Debug.deferredBlock: result += '[{id4:>4}] '.format(id4=id4(self)) result += '{cmd:<12}<-{cls:>6}({receiver:<10}): ANS={answer}'.format( cls=self.user.__class__.__name__, answer=self.prettyAnswer(), cmd=self.deferred.command, receiver=self.user.name) if self.age() > 0: result += ' after {} sec'.format(self.age()) return result
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)
def __str__(self): """printable string with tile""" rotation = ' rot%d' % self.rotation if self.rotation else '' scale = ' scale=%.2f' % self.scale if self.scale != 1 else '' level = ' level=%d' % self.level if self.level else '' if self.boundingRect(): size = self.boundingRect() size = ' %.2dx%.2d' % (size.width(), size.height()) else: size = '' return '%s(%s) %d: x/y/z=%.1f(%.1f)/%.1f(%.1f)/%.2f%s%s%s%s' % \ (self.tile, self.board.name if self.board else 'None', id4(self), self.xoffset, self.x(), self.yoffset, self.y(), self.zValue(), size, rotation, scale, level)
def __str__(self): cmd = self.deferred.command if self.answer: answer = str(self.answer) # TODO: needed? else: answer = 'OPEN' result = '' if Debug.deferredBlock: result += '[{id4:>4}] '.format(id4=id4(self)) result += '{cmd}->{cls}({receiver:<10}): {answer}'.format( cls=self.user.__class__.__name__, cmd=cmd, receiver=self.user.name, answer=answer) if self.age(): result += ' after {} sec'.format(self.age()) return result
def __addRequest(self, deferred, user, about): """add deferred for user to this block""" assert self.callbackMethod is None, 'AddRequest: already have callback defined' assert not self.completed, 'AddRequest: already completed' request = Request(self, deferred, user, about) self.requests.append(request) self.outstanding += 1 deferred.addCallback(self.__gotAnswer, request).addErrback(self.__failed, request) if Debug.deferredBlock: notifying = ' notifying' if deferred.notifying else '' rqString = '[{id4:>4}] {cmd}{notifying} {about}->{cls:>6}({receiver:<10})'.format( cls=user.__class__.__name__, id4=id4(request), cmd=deferred.command, receiver=user.name, about=about.name if about else '', notifying=notifying) self.debug('+:%d' % len(self.requests), rqString)
def __init__(self, graphicsObject, propName, endValue, parent=None): Animation.clsUid += 1 self.uid = Animation.clsUid pName = propName QPropertyAnimation.__init__(self, graphicsObject, pName.encode(), parent) QPropertyAnimation.setEndValue(self, endValue) duration = Internal.Preferences.animationDuration() self.setDuration(duration) self.setEasingCurve(QEasingCurve.InOutQuad) graphicsObject.queuedAnimations.append(self) Animation.nextAnimations.append(self) self.debug = graphicsObject.name() in Debug.animation or Debug.animation == 'all' self.debug |= 'T{}t'.format(id4(graphicsObject)) in Debug.animation if self.debug: oldAnimation = graphicsObject.activeAnimation.get(propName, None) if isAlive(oldAnimation): logDebug( 'new Animation(%s) (after %s is done)' % (self, oldAnimation.ident())) else: logDebug('Animation(%s)' % self)
def __str__(self): """for debugging""" return 'FocusRect({} on {})'.format( id4(self), self.board if self.board else 'NOBOARD')
def keyPressEvent(self, event): """redirect to the board""" if self is not self.board.focusTile: logDebug('id4(self):%s, self:%s, focusTile:%s/%s' % \ (id4(self), self, id4(self.board.focusTile), self.board.focusTile)) return self.board.keyPressEvent(event)