#!/usr/bin/env python# TESTED WITH LATEST CLUTTER SVN + CLUTTER PYTHON BINDINGS SVN# This code illustrates possible bug in Clutter python bindings. This application# create two Clutter Groups and each Group contains one Actor. First we add Group1# to the Stage. By pressing X user can remove Group 1 from stage and add Group 2.# Pressing X again should change Group 1 back to Stage. This seems to fail, because# Group is now NULL.## But group is an attribute of BugExample class, so it shouldn't be unreferenced# When removed from stage. I'm not sure is this what happends, but it looks like it.import clutterclass BugExample: def __init__(self): # Flag that indicates which group is currently on stage (1 or 2) self.current_group = 1 # Create stage self.stage = clutter.stage_get_default() self.stage.connect('key-press-event', self.keyPressAction) self.stage.set_color(clutter.Color(0x00, 0x00, 0x00, 0xff)) self.stage.set_size(200,100) #self.stage.set_title("Bug Example") # Create groups self.g1 = clutter.Group() self.g2 = clutter.Group() # Create actors actor1 = clutter.Label() actor2 = clutter.Label() actor1.set_text("First example text.") actor2.set_text("And the second one too.") actor1.set_color(clutter.Color(255,255,255,255)) actor2.set_color(clutter.Color(255,255,255,255)) actor1.show() actor2.show() # Add actors to groups self.g1.add(actor1) self.g2.add(actor2) self.g1.show() #self.g2.show() # Show stage and start clutter loop self.stage.add(self.g1) self.stage.add(self.g2) self.stage.show() clutter.main() def keyPressAction(self, stage, event): # Switch groups on stage (remove one and add the other) if event.keyval == clutter.keysyms.x: if self.current_group == 1: print "Switch from 1 to 2" self.current_group = 2 self.g1.hide() #self.stage.remove(self.g1) #self.stage.add(self.g2) self.g2.show() else: print "Switch from 2 to 1" self.current_group = 1 self.g2.hide() #self.stage.remove(self.g2) #self.stage.add(self.g1) self.g1.show() # Quit application elif event.keyval == clutter.keysyms.q or event.keyval == clutter.keysyms.Escape: clutter.main_quit()if __name__ == '__main__': BugExample()