Example #1
0
 def __init__(self, duration = 0.0):
     CATransaction.begin()
     self.animations = []
     self.duration = duration
     self.max_animation_time = 0.0
     self.beginTime =  0.0
     if not self.duration:
         self.duration = 0.25
Example #2
0
 def __init__(self, duration=0.0):
     CATransaction.begin()
     self.animations = []
     self.duration = duration
     self.max_animation_time = 0.0
     self.beginTime = 0.0
     if not self.duration:
         self.duration = 0.25
Example #3
0
    def commit(self):
        add_time = CACurrentMediaTime()

        target_map = {}
        anim_map = {}
        slayer_time = self.baseLayer.convertTime_fromLayer_(add_time, None)

        total_time = 0.0
        c_begin = slayer_time
        latest_end_time = c_begin
        for anim in self.animations:
            if anim.label and not anim.isWaitMark:
                anim_map[anim.label] = anim

            if anim.cs_input:
                if not anim.cs_input in target_map:
                    target_map[anim.cs_input] = {'c_begin': c_begin, 'latest_end_time':0}
            use_begin = slayer_time
            if anim.isWaitMark:
                tmp_begin = c_begin
                use_end = latest_end_time
                if anim.cs_input:
                    tmp_begin = target_map[anim.cs_input]['c_begin']
                    use_end = target_map[anim.cs_input]['latest_end_time']
                if anim.label and anim.label in anim_map:
                    label_anim = anim_map[anim.label]
                    use_end = label_anim.end_time

                if anim.isWaitOnly:
                    tmp_begin += anim.duration
                else:
                    tmp_begin = use_end
                    tmp_begin += anim.duration
                if anim.cs_input:
                    target_map[anim.cs_input]['c_begin'] = tmp_begin
                else:
                    c_begin = tmp_begin

            if not anim.ignore_wait and anim.animation:
                anim.animation.setValue_forKeyPath_(anim, "__CS_COMPLETION__")
                anim.animation.setDelegate_(CSAnimationDelegate.alloc().init())
            real_begin = c_begin
            if anim.cs_input:
                t_begin = target_map[anim.cs_input]['c_begin']
                if real_begin > t_begin:
                    target_map[anim.cs_input]['c_begin'] = real_begin
                else:
                    real_begin = t_begin
            
            a_duration = anim.apply(real_begin)
            if not anim.ignore_wait:
                latest_end_time = max(latest_end_time, real_begin+anim.duration)
                if anim.cs_input:
                    t_latest = target_map[anim.cs_input]['latest_end_time']
                    n_latest = real_begin+anim.duration
                    target_map[anim.cs_input]['latest_end_time'] = max(t_latest, n_latest)
        CATransaction.commit()
Example #4
0
 def apply_immediate(self):
     if self.target:
         p_value = self.toValue
         CATransaction.begin()
         #CATransaction.setDisableActions_(True)
         self.target.setValue_forKeyPath_(p_value, self.animation.keyPath())
         if self.extra_model:
             self.extra_model.setValue_forKeyPath_(p_value, self.animation.keyPath())
         CATransaction.commit()
Example #5
0
 def apply_immediate(self):
     if self.target:
         p_value = self.toValue
         CATransaction.begin()
         #CATransaction.setDisableActions_(True)
         self.target.setValue_forKeyPath_(p_value, self.animation.keyPath())
         if self.extra_model:
             self.extra_model.setValue_forKeyPath_(p_value,
                                                   self.animation.keyPath())
         CATransaction.commit()
Example #6
0
    def layoutSublayersOfLayer_(self, layer):
        """ Method is called when the sublayers of the layer may need rearranging. 
            Typically called when a sublayer has changed its size. 
            Receiver (ie, this PVLayout object) is responsible for changing 
                the frame of each sublayer that requires layout.
        """
    
        from Quartz import CATransaction, kCATransactionDisableActions

        newBounds = layer.bounds();
        
        n =  len(layer.sublayers()) 
        
#        NSLog( "class PVLayout: layoutSublayersOfLayer %@ bounds=%@, %d sublayers", layer, RectToString(newBounds), n )        
        NSLog( "layout of layer %@ bounds=%@, %d sublayers", layer.name(), RectToString(newBounds), n )        

        self.layoutGrid = PVLayoutGrid(n)
        NSLog(  "PVLayout is: %r"  % ( self.layoutGrid , ) ) # PVLayout is: n=8, g=3, g2=9
        NSLog(  "i   g2ni gn0  gn0p gn5 (  x  ,  y  ) "  )
#        for i in range(self.layoutGrid.n):  
#            NSLog(  self.layoutGrid.str(i)  )

#        height = (newBounds.size.height-2*10.0)/n     # height of each is less by portion of separations of 10.0 at top and bottom
        height = (newBounds.size.height-(self.layoutGrid.g()+1)*10.0)/(self.layoutGrid.g()+1) # height/width of grid
        width = (newBounds.size.width-(self.layoutGrid.g()+1)*10.0)/(self.layoutGrid.g()+1 )# height/width of grid  # separate width from height, create a layout  based on aspect ration of window?
        
#        z = CATransaction.getValue_(<#value#>)   value_forKey_     value_forKey_(kCATransactionDisableActions)

        CATransaction.setValue_forKey_( YES , kCATransactionDisableActions )

        for i, l in enumerate(layer.sublayers()):

            NSLog(  self.layoutGrid.str(i)  )
        
            # I'm setting the *frame*. So whatever's going on inside the layer I don't care about, (like bounds and position and anchorPoint) :-)
        
            originalFrame = l.frame();  # bounds is *its* rectangle, frame is the *superlayer*'s rectangle.
            originalBounds = l.bounds()
            
            if l.isKindOfClass_(CATextLayer):  
                # no resizing, just move the origin.
                origin = (10,10 + i * height ) 
                size = ( originalBounds.size.width , originalBounds.size.height ) # really just want originalBounds.size.                                   
                l.setFrame_(  ( origin , size )  )                     
            else:
                #origin = (10,10 + i * height )                                  
                origin = (self.layoutGrid.xn(i) * newBounds.size.width , self.layoutGrid.yn(i) * newBounds.size.height )                                  
                #size = ( newBounds.size.width-2*10.0, height ) 
                size = ( width , height ) 
                l.setFrame_(  ( origin , size )  )                      # I'm setting the *frame*. So whatever's going on inside the layer I don't care about :-)

            NSLog( LayerToString( l , i ) )

        CATransaction.setValue_forKey_( NO , kCATransactionDisableActions)     # :[NSNumber numberWithBool:YES] :kCATransactionDisableActions];
Example #7
0
    def set_model_value(self, realme=None):

        if self.target:
            p_layer = self.target.presentationLayer()
            if not p_layer:
                return
            p_value = p_layer.valueForKeyPath_(self.animation.keyPath())
            CATransaction.begin()
            CATransaction.setDisableActions_(True)
            self.target.setValue_forKeyPath_(p_value, self.animation.keyPath())
            if self.extra_model:
                self.extra_model.setValue_forKeyPath_(p_value, self.animation.keyPath())
            self.target.removeAnimationForKey_(self.uukey)
            CATransaction.commit()
Example #8
0
    def set_model_value(self, realme=None):

        if self.target:
            p_layer = self.target.presentationLayer()
            if not p_layer:
                return
            p_value = p_layer.valueForKeyPath_(self.animation.keyPath())
            CATransaction.begin()
            CATransaction.setDisableActions_(True)
            self.target.setValue_forKeyPath_(p_value, self.animation.keyPath())
            if self.extra_model:
                self.extra_model.setValue_forKeyPath_(p_value,
                                                      self.animation.keyPath())
            self.target.removeAnimationForKey_(self.uukey)
            CATransaction.commit()
Example #9
0
    def commit(self):
        add_time = CACurrentMediaTime()

        target_map = {}
        anim_map = {}
        slayer_time = self.baseLayer.convertTime_fromLayer_(add_time, None)

        total_time = 0.0
        c_begin = slayer_time
        latest_end_time = c_begin
        for anim in self.animations:
            if anim.label and not anim.isWaitMark:
                anim_map[anim.label] = anim

            if anim.cs_input:
                if not anim.cs_input in target_map:
                    target_map[anim.cs_input] = {
                        'c_begin': c_begin,
                        'latest_end_time': 0
                    }
            use_begin = slayer_time
            if anim.isWaitMark:
                tmp_begin = c_begin
                use_end = latest_end_time
                if anim.cs_input:
                    tmp_begin = target_map[anim.cs_input]['c_begin']
                    use_end = target_map[anim.cs_input]['latest_end_time']
                if anim.label and anim.label in anim_map:
                    label_anim = anim_map[anim.label]
                    use_end = label_anim.end_time

                if anim.isWaitOnly:
                    tmp_begin += anim.duration
                else:
                    tmp_begin = use_end
                    tmp_begin += anim.duration
                if anim.cs_input:
                    target_map[anim.cs_input]['c_begin'] = tmp_begin
                else:
                    c_begin = tmp_begin

            if not anim.ignore_wait and anim.animation:
                anim.animation.setValue_forKeyPath_(anim, "__CS_COMPLETION__")
                anim.animation.setDelegate_(CSAnimationDelegate.alloc().init())
            real_begin = c_begin
            if anim.cs_input:
                t_begin = target_map[anim.cs_input]['c_begin']
                if real_begin > t_begin:
                    target_map[anim.cs_input]['c_begin'] = real_begin
                else:
                    real_begin = t_begin

            a_duration = anim.apply(real_begin)
            if not anim.ignore_wait:
                latest_end_time = max(latest_end_time,
                                      real_begin + anim.duration)
                if anim.cs_input:
                    t_latest = target_map[anim.cs_input]['latest_end_time']
                    n_latest = real_begin + anim.duration
                    target_map[anim.cs_input]['latest_end_time'] = max(
                        t_latest, n_latest)
        CATransaction.commit()