On Feb 7, 2008 10:04 AM, Tero Saarni <[EMAIL PROTECTED]> wrote:
> Here's an another example. It has Screen class based on clutter.Group
> that contains just a label. When pressing a key the old Screen is
> faded out, removed from the stage and finally new Screen enters the
> stage. Old Screens never seem to get garbage collected.
Below is modified version with garbage collection working ok. This
one does not use clutter.effect_fade() helper function but instead
creates clutter.BehaviourOpacity() which is stored in global variable.
That seems to prevent reference cycles.
However when implementing animation in Screen class itself and storing
BehaviourOpacity as a member variable (instead of global variable;
every widget of course needs to have it's own behaviour) I've caused
an reference cycle again...
import clutter
current_screen = None
counter = 1
behaviour = None
class Screen(clutter.Group):
def __init__(self, title_text):
super(Screen, self).__init__()
print 'INIT %s' % self
title = clutter.Label()
title.set_text(title_text)
title.set_font_name('Arial 150px')
title.set_color(clutter.Color(0,0,0))
title.show()
self.add(title)
def __del__(self):
print 'DEL %s' % self
def on_key_press_event(a,b):
global behaviour
timeline = clutter.Timeline(duration=300)
alpha = clutter.Alpha(timeline, clutter.ramp_inc_func)
behaviour = clutter.BehaviourOpacity(alpha=alpha,
opacity_start=255, opacity_end=0)
behaviour.apply(current_screen)
timeline.connect('completed', on_fade_out_completed)
timeline.start()
return True
def on_fade_out_completed(a):
global current_screen
global counter
stage.remove(current_screen)
current_screen = Screen(str(counter))
current_screen.set_position(120,30)
stage.add(current_screen)
current_screen.show()
counter += 1
return True
stage = clutter.stage_get_default()
stage.set_size(320,240)
stage.connect('key-press-event', on_key_press_event)
current_screen = Screen(str(counter))
current_screen.set_position(120,30)
stage.add(current_screen)
counter += 1
stage.show_all()
clutter.main()
--
To unsubscribe send a mail to [EMAIL PROTECTED]