Re: [clutter] Animation in PyClutter
On Thu, 2007-11-08 at 08:32 +1100, Josh Stewart wrote: Not sure what has changed, but in Ubuntu Feisty it appears that behaviours do not need to be global variables to function. I even reinstalled Feisty on my machine just to prove the point and it definitely seems to be the case. is feisty still shipped with python 2.4 by default? afair, python 2.4 did not garbage collect very well, and this might lead to objects being kept artificially alive, leaking memory and possibly creating unwanted side effects. ciao, Emmanuele. -- Emmanuele Bassi, OpenedHand Ltd. Unit R, Homesdale Business Centre 216-218 Homesdale Rd., Bromley - BR12QZ http://www.o-hand.com -- To unsubscribe send a mail to [EMAIL PROTECTED]
Re: [clutter] Animation in PyClutter
hi; On Wed, 2007-11-07 at 21:19 +0100, Johan Mårtenson wrote: def key_event(stage, event): timeline = clutter.Timeline(100, 26) alpha = clutter.Alpha(timeline, clutter.sine_func ) path_forward = clutter.BehaviourPath(alpha, ((0, 0), (100, 100))) # Up if event.keyval == 65362: menu = stage.get_nth_child(0) path_forward.apply(menu) timeline.start () the timeline, alpha and path_forward objects go out of scope when control reaches the end of the key_event signal handler; hence, you see no behaviour running because python will simply garbage collect those objects. you should either declare path_forward as a global variable or, going down the object oriented path, as an instance member of your application class. ciao, Emmanuele. -- Emmanuele Bassi, OpenedHand Ltd. Unit R, Homesdale Business Centre 216-218 Homesdale Rd., Bromley - BR12QZ http://www.o-hand.com -- To unsubscribe send a mail to [EMAIL PROTECTED]
Re: [clutter] Animation in PyClutter
Hi again, On 11/7/07, Emmanuele Bassi [EMAIL PROTECTED] wrote: hi; On Wed, 2007-11-07 at 21:19 +0100, Johan Mårtenson wrote: def key_event(stage, event): timeline = clutter.Timeline(100, 26) alpha = clutter.Alpha(timeline, clutter.sine_func ) path_forward = clutter.BehaviourPath(alpha, ((0, 0), (100, 100))) # Up if event.keyval == 65362: menu = stage.get_nth_child(0) path_forward.apply(menu) timeline.start () the timeline, alpha and path_forward objects go out of scope when control reaches the end of the key_event signal handler; hence, you see no behaviour running because python will simply garbage collect those objects. I forgot about that, thanks. you should either declare path_forward as a global variable or, going down the object oriented path, as an instance member of your application class. And indeed you're right. Just making the variables global fixes it. ciao, Emmanuele. Thanks, Johan -- Emmanuele Bassi, OpenedHand Ltd. Unit R, Homesdale Business Centre 216-218 Homesdale Rd., Bromley - BR12QZ http://www.o-hand.com -- To unsubscribe send a mail to [EMAIL PROTECTED]
Re: [clutter] Animation in PyClutter
Just to add my 2c with this, the variable scope for behaviours seems to have changed in Ubuntu Gutsy from Feisty. I'm not sure if you saw my email the other day saying I was having problems with timelines executing in Gutsy (Thinking it was an Intel problem, boy was THAT a dumb theory), but it was this issue. Not sure what has changed, but in Ubuntu Feisty it appears that behaviours do not need to be global variables to function. I even reinstalled Feisty on my machine just to prove the point and it definitely seems to be the case. -Josh On 11/8/07, Johan Mårtenson [EMAIL PROTECTED] wrote: Hi again, On 11/7/07, Emmanuele Bassi [EMAIL PROTECTED] wrote: hi; On Wed, 2007-11-07 at 21:19 +0100, Johan Mårtenson wrote: def key_event(stage, event): timeline = clutter.Timeline(100, 26) alpha = clutter.Alpha(timeline, clutter.sine_func ) path_forward = clutter.BehaviourPath(alpha, ((0, 0), (100, 100))) # Up if event.keyval == 65362: menu = stage.get_nth_child(0) path_forward.apply(menu) timeline.start () the timeline, alpha and path_forward objects go out of scope when control reaches the end of the key_event signal handler; hence, you see no behaviour running because python will simply garbage collect those objects. I forgot about that, thanks. you should either declare path_forward as a global variable or, going down the object oriented path, as an instance member of your application class. And indeed you're right. Just making the variables global fixes it. ciao, Emmanuele. -- To unsubscribe send a mail to [EMAIL PROTECTED]
Re: [clutter] Animation in PyClutter
On Wed, 2007-11-07 at 22:14 +0100, Johan Mårtenson wrote: And indeed you're right. Just making the variables global fixes it. Actually, I still don't get the behavior I'm expecting. In the attached program, I want the HBox menu to slide to the middle and stay there but once it gets there it instead slides back again. What am I getting wrong? the alpha function you're using is a sine wave, so you'll get the return when the wave decreases. you should probably use sine_inc_func instead. Also, is there a nicer way of comparing keys than using b.keyval == 65362 for arrow up and 113 for q? sure: clutter.keysyms.q for 'q' and clutter.keysyms.uparrow for 'arrow up'. ciao, Emmanuele. -- Emmanuele Bassi, OpenedHand Ltd. Unit R, Homesdale Business Centre 216-218 Homesdale Rd., Bromley - BR12QZ http://www.o-hand.com -- To unsubscribe send a mail to [EMAIL PROTECTED]
Re: [clutter] Animation in PyClutter
Hi once again... :-) On 11/7/07, Johan Mårtenson [EMAIL PROTECTED] wrote: Hi again, On 11/7/07, Emmanuele Bassi [EMAIL PROTECTED] wrote: hi; On Wed, 2007-11-07 at 21:19 +0100, Johan Mårtenson wrote: def key_event(stage, event): timeline = clutter.Timeline(100, 26) alpha = clutter.Alpha(timeline, clutter.sine_func ) path_forward = clutter.BehaviourPath(alpha, ((0, 0), (100, 100))) # Up if event.keyval == 65362: menu = stage.get_nth_child(0) path_forward.apply(menu) timeline.start () the timeline, alpha and path_forward objects go out of scope when control reaches the end of the key_event signal handler; hence, you see no behaviour running because python will simply garbage collect those objects. I forgot about that, thanks. you should either declare path_forward as a global variable or, going down the object oriented path, as an instance member of your application class. And indeed you're right. Just making the variables global fixes it. Actually, I still don't get the behavior I'm expecting. In the attached program, I want the HBox menu to slide to the middle and stay there but once it gets there it instead slides back again. What am I getting wrong? Also, is there a nicer way of comparing keys than using b.keyval == 65362 for arrow up and 113 for q? ciao, Emmanuele. Thanks, Johan Thanks, Johan -- Emmanuele Bassi, OpenedHand Ltd. Unit R, Homesdale Business Centre 216-218 Homesdale Rd., Bromley - BR12QZ http://www.o-hand.com -- To unsubscribe send a mail to [EMAIL PROTECTED] #! /usr/bin/python import clutter def key_event(stage, b): global timeline global alpha global path_forward timeline = clutter.Timeline(100, 26) alpha = clutter.Alpha(timeline, clutter.ramp_func) path_forward = clutter.BehaviourPath(alpha, ((0, 0), (100, 100))) # Up if b.keyval == 65362: menu = stage.get_nth_child(0) path_forward.apply(menu) timeline.start() # q if b.keyval == 113: clutter.main_quit() return True def build_scene(): label = clutter.Label() label.set_text('Some label') label.show() menu = clutter.HBox() menu.add(label) menu.set_position(0, 0) menu.show() stage = clutter.stage_get_default() stage.set_size(300, 300) stage.set_color(clutter.color_parse(#7F7F7F)) stage.add(menu) stage.show() return stage def main(): stage = build_scene() stage.connect(key-press-event, key_event) clutter.main() if __name__ == '__main__': main()