Hi all,

I spent some time this summer playing with pyclutter and ran into a bug
where my animations stop but the print statements to debug still work. 
I just updated to clutter and pyclutter 0.4.2 with no luck.  In fact, it
doesn't animate at all.  I think I need a second or third pair of eyes. 
I've attached the two files involved.  You'll need to use a test jpeg to
try it.  Simply place a jpeg in the directory and add the filename to
the albums list on line 37 in test.py.

Thanks,
Scott
import clutter
import gtk.gdk

class BehaviourRotate (clutter.Behaviour):
        __gtype_name__ = 'BehaviourRotate'
        def __init__ (self, alpha=None):
                clutter.Behaviour.__init__(self)
                self.set_alpha(alpha)

        def do_alpha_notify (self, alpha_value):
                for actor in self.get_actors():
                        print "r",
                        actor.rotate_y(alpha_value,-50,0)

class BehaviourDepth (clutter.Behaviour):
        __gtype_name__ = 'BehaviourDepth'
        def __init__ (self, alpha=None):
                clutter.Behaviour.__init__(self)
                self.set_alpha(alpha)

        def do_alpha_notify (self, alpha_value):
                for actor in self.get_actors():
                        print "d",
                        actor.set_depth(alpha_value)

class BehaviourPos (clutter.Behaviour):
        __gtype_name__ = 'BehaviourPos'
        def __init__ (self, alpha=None):
                clutter.Behaviour.__init__(self)
                self.set_alpha(alpha)

        def do_alpha_notify (self, alpha_value):
                for actor in self.get_actors():
                        print "p",
                        actor.set_position(alpha_value,actor.get_y())

class SidestreamAlbum(clutter.Group):
    middle_rotation = -20.0 # rotation from 0
    first_duration = 4.0 # number of frames for initial rotation
    second_duration = 4.0 # number of frames for rotation back to 0
    middle_depth = 300.0
    final_depth = 600.0
    depth_to_scale = 300.0
    s2_duration = 10.0
    square_size = 100
    def __init__(self,image):
        clutter.Group.__init__(self)
        pixbuf = gtk.gdk.pixbuf_new_from_file(image)
        self.actor = clutter.texture_new_from_pixbuf(pixbuf)
        self.actor.set_position(-1*self.square_size/2, -1*self.square_size/2)
        self.actor.set_size(self.square_size,self.square_size)
        self.actor.show()
        self.add(self.actor)
        
        #stage one up
        self.timeline1 = clutter.Timeline(int(self.first_duration+self.second_duration), 30)
        rotate1_alpha = clutter.Alpha(self.timeline1, self.stage1_rotate)
        depth1_alpha = clutter.Alpha(self.timeline1, self.stage1_depth)
        behaviour1_rotate = BehaviourRotate(rotate1_alpha)
        behaviour1_rotate.apply(self)
        behaviour1_depth = BehaviourDepth(depth1_alpha)
        behaviour1_depth.apply(self)
        
        #stage one down
        self.timeline1r = clutter.Timeline(int(self.first_duration+self.second_duration), 30)
        rotate1r_alpha = clutter.Alpha(self.timeline1r, self.stage1r_rotate)
        depth1r_alpha = clutter.Alpha(self.timeline1r, self.stage1r_depth)
        behaviour1r_rotate = BehaviourRotate(rotate1r_alpha)
        behaviour1r_rotate.apply(self)
        behaviour1r_depth = BehaviourDepth(depth1r_alpha)
        behaviour1r_depth.apply(self)
        
        #stage two up
        self.timeline2 = clutter.Timeline(int(self.s2_duration), 30)
        rotate2_alpha = clutter.Alpha(self.timeline2, self.s2_rotate)
        behaviour2_rotate = BehaviourRotate(rotate2_alpha)
        behaviour2_rotate.apply(self)
        pos2_alpha = clutter.Alpha(self.timeline2, self.s2_pos)
        behaviour2_pos = BehaviourPos(pos2_alpha)
        behaviour2_pos.apply(self)
        depth2_alpha = clutter.Alpha(self.timeline2, self.s2_depth)
        behaviour2_depth = BehaviourDepth(depth2_alpha)
        behaviour2_depth.apply(self)
        
        #stage two down
        self.timeline2r = clutter.Timeline(int(self.s2_duration), 30)
        rotate2r_alpha = clutter.Alpha(self.timeline2r, self.s2r_rotate)
        behaviour2r_rotate = BehaviourRotate(rotate2r_alpha)
        behaviour2r_rotate.apply(self)
        pos2r_alpha = clutter.Alpha(self.timeline2r, self.s2r_pos)
        behaviour2r_pos = BehaviourPos(pos2r_alpha)
        behaviour2r_pos.apply(self)
        depth2r_alpha = clutter.Alpha(self.timeline2r, self.s2r_depth)
        behaviour2r_depth = BehaviourDepth(depth2r_alpha)
        behaviour2r_depth.apply(self)
        
        self.stage = 0
    
    def play_timeline_cb(self, old, new):
        old.disconnect_by_func(self.play_timeline_cb)
        new.start()
        print new, "started"
    
    def set_depth(self, depth):
        self.set_scale(1+depth/self.depth_to_scale,1+depth/self.depth_to_scale)
        
    def over(self):
        print "\n################# OVER ###################"
        if not self.timeline2.is_playing():
            self.timeline1.start()
            print "timeline1 started"
        self.stage=1
    
    def out(self):
        print "\n################# OUT ###################"
        if self.stage==2:
            if self.timeline2.is_playing():
                self.timeline2.connect("completed",self.play_timeline_cb,self.timeline2r)
            else:
                self.timeline2r.start()
                print "timeline2r started"
            self.timeline2r.connect("completed",self.play_timeline_cb,self.timeline1r)
        elif self.stage==1:
            if self.timeline1.is_playing():
                self.timeline1.connect("completed",self.play_timeline_cb,self.timeline1r)
            else:
                self.timeline1r.start()
                print "timeline1r started"
        self.stage=0
            
    
    def clicked(self):
        print "\n################# CLICKED ###################"
        if self.stage!=2:
            self.timeline2.start()
            print "timeline2 started"
            self.stage=2
    
    def s2_pos(self,alpha,data):
        timeline = alpha.get_timeline()
        frame = timeline.get_current_frame()
        return int(self.get_x() + (self.square_size*(self.final_depth/self.depth_to_scale+1))/self.s2_duration)
    
    def s2r_pos(self,alpha,data):
        timeline = alpha.get_timeline()
        frame = timeline.get_current_frame()
        return int(self.get_x() - (self.square_size*(self.final_depth/self.depth_to_scale+1))/self.s2_duration)

    def s2_depth(self, alpha, data):
        timeline = alpha.get_timeline()
        frame = timeline.get_current_frame()
        return int(self.middle_depth+((self.final_depth-self.middle_depth)*(frame/self.s2_duration)))
    
    def s2r_depth(self, alpha, data):
        timeline = alpha.get_timeline()
        frame = timeline.get_current_frame()
        return int(self.middle_depth+((self.final_depth-self.middle_depth)*((self.s2_duration-frame)/self.s2_duration)))
    
    def s2_rotate(self,alpha,data):
        timeline = alpha.get_timeline()
        frame = timeline.get_current_frame()
        angle = int(180*(frame/self.s2_duration))
        return angle
    
    def s2r_rotate(self,alpha,data):
        timeline = alpha.get_timeline()
        frame = timeline.get_current_frame()
        return int(180*((self.s2_duration-frame)/self.s2_duration))

    def stage1r_depth(self, alpha, data):
        timeline = alpha.get_timeline()
        frame = timeline.get_current_frame()
        if frame<=self.second_duration:
            depth = int(self.middle_depth*(((self.first_duration+self.second_duration-frame)-self.first_duration)/self.second_duration))
        else:
            depth = 0
        return depth

    def stage1r_rotate(self, alpha, data):
        timeline = alpha.get_timeline()
        frame = timeline.get_current_frame()
        if frame<=self.second_duration:
            angle = int(self.middle_rotation*(frame/self.second_duration))
        else:
            angle =  int(self.middle_rotation*(1-(frame-self.first_duration)/self.second_duration))
        #print str(frame)+":"+str(angle)
        return angle

    def stage1_rotate(self, alpha, data):
        timeline = alpha.get_timeline()
        frame = timeline.get_current_frame()
        if frame>self.first_duration:
            angle =  int(self.middle_rotation*(1-(frame-self.first_duration)/self.second_duration))
        else:
            angle = int(self.middle_rotation*(frame/self.first_duration))
        #print str(frame)+":"+str(angle)
        return angle
    
    def stage1_depth(self, alpha, data):
        timeline = alpha.get_timeline()
        frame = timeline.get_current_frame()
        if frame>self.first_duration:
            depth = int(self.middle_depth*((frame-self.first_duration)/self.second_duration))
        else:
            depth = 0
        return depth
    
    
import sys
import clutter
import actors

class Test:
    def on_key_press(self, stage, event):
        if event.hardware_keycode==24 or event.hardware_keycode==9:
            clutter.main_quit()
        else:
            print event.hardware_keycode

    def on_button_press(self, stage, event):
        actor = stage.get_actor_at_pos(event.x,event.y)
        if not actor==stage:
            actor.get_parent().clicked()
    
    def on_mouse_move(self,stage,event):
        actor = stage.get_actor_at_pos(event.x,event.y)
        if actor and self.over and self.over!=actor.get_parent():
            self.over.out()
            self.over=None
            
        if actor and actor!=stage and self.over!=actor.get_parent():
            self.over = actor.get_parent()
            self.over.over()
            self.over.raise_top()
        

    def main(self, args):
        stage = clutter.stage_get_default()
        stage.set_size(800, 600)
        stage.set_color(clutter.Color(0xff, 0xff, 0xff, 0xff))
        stage.connect('key-press-event', self.on_key_press)
        stage.connect('button-press-event', self.on_button_press)
        stage.connect('motion-event',self.on_mouse_move)
        stage.set_perspective(60.0, 1.0, 0.1, 100.0)
        albums = ["all_in.jpg","another_ride.jpg","deep.jpg"]#,"okay.jpg", "plastic.jpg","rio.jpg", "seven.jpg", "tiny.jpg", "white.jpg"]
        i = 0
        for album in albums:
            self.actor1 = actors.SidestreamAlbum(album)
            self.actor1.set_position(400-125*(len(albums)/6-i/3), 200+(i%3)*125)
            self.actor1.show()
            stage.add(self.actor1)
            i+=1
        
        self.over = None
        stage.show()
        print "clutter main"
        clutter.main()
        return 0

if __name__ == '__main__':
    test = Test()
    sys.exit(test.main(sys.argv[1:]))

Reply via email to