class Group(Clutter.Group): def __init__(self, r, g, b, a): Clutter.Group.__init__(self) self.rectangle = Clutter.Rectangle(color=Clutter.Color(r, g, b, a)) self.hand = Clutter.Texture(filename="../data/redhand.png") for actor in self.rectangle, self.hand: actor.set_size(ACTOR_WIDTH, ACTOR_HEIGHT) self.add(self.rectangle, self.hand) if __name__ == "__main__": stage = Clutter.Stage() layout_state = Clutter.State() stage.set_color(Clutter.Color.from_string("#000000")) stage.set_title("State Machine") stage.set_size(STAGE_WIDTH, STAGE_HEIGHT) stage.connect("destroy", Clutter.main_quit) stage.connect("button-press-event", press_event, layout_state) stage.connect("button-release-event", release_event, layout_state) for i in range(TOTAL): row = i / COLS col = i % COLS actor = Group( 255 * (1.0 * col / COLS), 50,
box.add_actor(rect) # text for the button text = Clutter.Text.new_full("Sans 10pt", "Hover me", Clutter.Color.from_string("white")) text.set_line_alignment(Pango.Alignment.CENTER) # NB don't set the height, so the actor assumes the height of the text; # then when added to the bin layout, it gets centred on it; # also if you don't set the width, the layout goes gets really wide; # the 10pt text fits inside the 30px height of the rectangle text.set_width(100) layout.add(text, Clutter.BinAlignment.CENTER, Clutter.BinAlignment.CENTER) # animations transitions = Clutter.State() transitions.set_key(None, "fade-out", box, "opacity", Clutter.AnimationMode.LINEAR, 180) # NB you can't use an easing mode where alpha > 1.0 if you're # animating to a value of 255, as the value you're animating # to will possibly go > 255 transitions.set_key(None, "fade-in", box, "opacity", Clutter.AnimationMode.LINEAR, 255) transitions.set_duration(None, None, 200) transitions.warp_to_state("fade-out") box.connect("enter-event", pointer_enter_cb, transitions) box.connect("leave-event", pointer_leave_cb, transitions)