Esempio n. 1
0
def create_cgpath(frame):
    newPath = CGPathCreateMutable()
    CGPathMoveToPoint(newPath, None, 0, 0)
    CGPathAddLineToPoint(newPath, None, frame.size.width, 0)
    CGPathAddLineToPoint(newPath, None, 0, frame.size.height)
    CGPathCloseSubpath(newPath)
    return newPath
Esempio n. 2
0
    def shake(self, the_window):
        '''Uses CoreAnimation to "shake" the alert window'''
        # adapted from here:
        # http://stackoverflow.com/questions/10517386/how-to-give-nswindow-a-shake-effect-as-saying-no-as-in-login-failure-window/23491643#23491643

        numberOfShakes = 3
        durationOfShake = 0.5
        vigourOfShake = 0.05

        frame = the_window.frame()
        shakeAnimation = CAKeyframeAnimation.animation()

        shakePath = CGPathCreateMutable()
        CGPathMoveToPoint(shakePath, None, NSMinX(frame), NSMinY(frame))
        for index in range(numberOfShakes):
            CGPathAddLineToPoint(
                shakePath, None,
                NSMinX(frame) - frame.size.width * vigourOfShake, NSMinY(frame))
            CGPathAddLineToPoint(
                shakePath, None,
                NSMinX(frame) + frame.size.width * vigourOfShake, NSMinY(frame))
        CGPathCloseSubpath(shakePath)
        shakeAnimation.setPath_(shakePath)
        shakeAnimation.setDuration_(durationOfShake)

        the_window.setAnimations_({'frameOrigin': shakeAnimation})
        the_window.animator().setFrameOrigin_(frame.origin)