def _change_preview_image(self): """ Run a timeline that crossfades preview images. This method is a callback that is called every 4 seconds. """ if len(self.preview_textures) <= 1: self.preview_textures[0].set_opacity(255) elif self.config.show_effects: #Fade out timeline fade_out = clutter.Timeline(500) alpha_out = clutter.Alpha(fade_out, clutter.EASE_IN_OUT_SINE) self.out_behaviour = clutter.BehaviourOpacity(255, 0, alpha_out) self.out_behaviour.apply(self.preview_textures[0]) # Fade in timeline fade_in = clutter.Timeline(500) alpha_in = clutter.Alpha(fade_in, clutter.EASE_IN_OUT_SINE) self.in_behaviour = clutter.BehaviourOpacity(0, 255, alpha_in) self.in_behaviour.apply(self.preview_textures[1]) # Start animation fade_out.start() fade_in.start() else: self.preview_textures[0].set_opacity(0) self.preview_textures[1].set_opacity(255) # Scroll images self.preview_textures = self.preview_textures[1:] + \ self.preview_textures[:1] return True
def __init__(self, theme): clutter.Group.__init__(self) self.animate_selector = False selector_filename = theme.getImage("selector") glow_filename = theme.getImage("selector_glow") # Set selector base texture self.selector = Texture(selector_filename) self.selector.set_opacity(200) self.add(self.selector) # Set selector GLOW texture self.glow = Texture(glow_filename) self.glow.set_opacity(0) self.add(self.glow) # Animate selector (Glow effect with glow overlay texture) self.in_time = clutter.Timeline(1500) self.in_alpha = clutter.Alpha(self.in_time, clutter.EASE_IN_OUT_SINE) self.in_behaviour = clutter.BehaviourOpacity(0, 255, self.in_alpha) self.in_behaviour.apply(self.glow) self.out_time = clutter.Timeline(1500) self.out_alpha = clutter.Alpha(self.out_time, clutter.EASE_IN_OUT_SINE) self.out_behaviour = clutter.BehaviourOpacity(255, 0, self.out_alpha) self.out_behaviour.apply(self.glow) self.score = clutter.Score() self.score.set_loop(True) self.score.append(timeline=self.in_time) # Link the out Timeline so that there is a smooth fade out. self.score.append(timeline=self.out_time, parent=self.in_time)
def forward_effect(self, from_screen, to_screen): """ Fade out all components from the "from_screen" and fade in all components of the "to_screen". @param from_screen: Screen object (Currently displayed screen) @param to_screen: Screen object (Screen displayed after transition) """ # Initialize to_screen for animation to_screen.set_opacity(0x00) to_screen.show() # Fade out current screen if from_screen is not None: fade_out = clutter.Timeline(20, 60) alpha_out = clutter.Alpha(fade_out, clutter.smoothstep_inc_func) self.out_behaviour = clutter.BehaviourOpacity( 0xff, 0x00, alpha_out) self.out_behaviour.apply(from_screen) if self.direction == self.BACKWARD: self.direction = self.FORWARD # Reset value fade_out.connect('completed', self._remove_from_stage_callback, from_screen) # Fade in timeline fade_in = clutter.Timeline(20, 60) alpha_in = clutter.Alpha(fade_in, clutter.smoothstep_inc_func) self.in_behaviour = clutter.BehaviourOpacity(0x00, 0xff, alpha_in) self.in_behaviour.apply(to_screen) # Start transition animation if from_screen is not None: fade_out.start() fade_in.start()
def _update_albumart(self, artist, title): """ Search album art for current audio disc. This function is called only if album art doesn't exist already. If album art is found then we replace current disc icon with the new album art. @param artist: Artist name @param title: Album title """ art_file = os.path.join(self.config.ALBUM_ART_DIR, artist + " - " + title + ".jpg") if os.path.exists(art_file): clutter.threads_enter() self.art2 = Texture(art_file, 0.1, 0.165) clutter.threads_leave() self.art2.set_size(self.get_abs_x(0.3148), self.get_abs_y(0.5599)) self.art2.set_opacity(0) self.add(self.art2) timeline_in = clutter.Timeline(35, 26) alpha_in = clutter.Alpha(timeline_in, clutter.smoothstep_inc_func) self.in_behaviour = clutter.BehaviourOpacity(0, 255, alpha_in) self.in_behaviour.apply(self.art2) timeline_out = clutter.Timeline(35, 26) alpha_out = clutter.Alpha(timeline_out, clutter.smoothstep_inc_func) self.out_behaviour = clutter.BehaviourOpacity(255, 0, alpha_out) self.out_behaviour.apply(self.art) timeline_out.start() timeline_in.start()
def __init__(self, theme): """Initialize overlay texture.""" Texture.__init__(self, filename=theme.getImage("menu_overlay")) self.timeline = clutter.Timeline(500) self.alpha = clutter.Alpha(self.timeline, clutter.EASE_IN_OUT_SINE) self.behaviour = clutter.BehaviourOpacity(255, 0, self.alpha) self.behaviour.apply(self)
def __init__ (self, nhands=6): clutter.Group.__init__(self) self.n_hands = nhands self.timeline = clutter.Timeline(5000) self.timeline.set_loop(True) self.timeline.connect('new-frame', self.on_new_frame) def sine_wave (alpha): return math.sin(alpha.get_timeline().get_progress() * math.pi) self.alpha = clutter.Alpha(self.timeline) self.alpha.set_func(sine_wave) self.scalers = [] self.scalers.append(clutter.BehaviourScale(0.5, 0.5, 1.0, 1.0, self.alpha)) self.scalers.append(clutter.BehaviourScale(1.0, 1.0, 0.5, 0.5, self.alpha)) self.stage = clutter.Stage(default=True) self.stage.set_size(1024, 768) self.stage.connect('button-press-event', self.on_button_press) self.stage.connect('key-press-event', self.on_key_press) self.create_hands()
def main(): stage_color = clutter.Color(0, 0, 0, 255) rect_color = clutter.Color(255, 255, 255, 153) # Get the stage and set its size and color stage = clutter.Stage() stage.set_size(200, 200) stage.set_color(stage_color) # Add a rectangle to the stage rect = clutter.Rectangle(rect_color) rect.set_size(70, 70) rect.set_position(50, 100) stage.add(rect) rect.show() # Show the stage stage.connect('destroy', clutter.main_quit) stage.show() timeline = clutter.Timeline(5000) # milliseconds timeline.add_marker_at_time("clutter-tutorial", 2000) # milliseconds timeline.connect('new-frame', on_timeline_new_frame, rect) timeline.connect('marker-reached', on_timeline_marker_reached) timeline.set_loop(True) timeline.start() # Start the main loop, so we can respond to events clutter.main() return 0
def __init__(self, *args, **kwargs): self._stage = clutter.Stage() self._stage.set_color(clutter.Color(0, 0, 0, 255)) self._stage.set_size(300, 300) self._stage.connect('key-press-event', clutter.main_quit) rect = clutter.Rectangle() rect.set_color(clutter.Color(255, 255, 255, 0x99)) rect.set_size(100, 100) rect.set_position(100, 100) self._stage.add(rect) rect = clutter.Rectangle() rect.set_color(clutter.Color(255, 255, 255, 255)) rect.move_anchor_point_from_gravity(clutter.GRAVITY_CENTER) rect.set_size(100, 100) rect.set_position(100, 100) self._stage.add(rect) self._gravity = clutter.GRAVITY_NORTH_WEST self._rect = rect self._timeline = clutter.Timeline(duration=500) self._timeline.set_loop(True) self._timeline.connect('completed', self.on_timeline_completed, self) alpha = clutter.Alpha(self._timeline, clutter.LINEAR) self._behave = clutter.BehaviourScale(0.0, 0.0, 1.0, 1.0, alpha=alpha) self._behave.apply(rect) self._stage.show_all()
def __init__(self, name, title="Untitled tab", callback=None): Base.__init__(self) clutter.Group.__init__(self) self.name = name self.title = title self.callback = callback self.theme = self.config.theme self.dispatch = { UserEvent.NAVIGATE_UP : self._handle_up, UserEvent.NAVIGATE_DOWN : self._handle_down, UserEvent.NAVIGATE_LEFT : self._handle_left, UserEvent.NAVIGATE_RIGHT : self._handle_right, UserEvent.NAVIGATE_SELECT : self._handle_select, } # show/hide animation on the Tab self.timeline = clutter.Timeline(500) self.timeline.connect('completed', self._on_timeline_completed) self.alpha = clutter.Alpha(self.timeline, clutter.EASE_IN_OUT_SINE) self.behaviour = clutter.BehaviourOpacity(0, 255, self.alpha) self.behaviour.apply(self) # Tabs are created deactivated and invisible self._active = None self._visible = False self.set_opacity(0) self.hide()
def __init__(self, item_gap, item_height, font_size, color_name): clutter.Group.__init__(self) self._motion_buffer = MotionBuffer() self._items = [] self._item_gap = item_gap self._item_height = item_height self._item_font_size = font_size self._item_color_name = color_name self._selected_index = 1 self._visible_items = 5 self._event_mode = -1 self._animation_progression = 0 self._animation_start_index = 1 self._animation_end_index = 1 self._active = False self._motion_handler = 0 self._timeline = clutter.Timeline(300) self._alpha = clutter.Alpha(self._timeline, clutter.EASE_IN_OUT_SINE) # preparation to pointer events handling self.set_reactive(True) self.connect('scroll-event', self._on_scroll_event) self.connect('button-press-event', self._on_button_press_event) self.connect('button-release-event', self._on_button_release_event)
def __init__(self, message): self.stage = clutter.Stage() self.stage.set_color(clutter.color_from_string('DarkSlateGrey')) self.stage.set_size(800, 600) self.stage.set_title('My First Clutter Application') self.stage.connect('key-press-event', clutter.main_quit) self.stage.connect('button-press-event', self.on_button_press_event) color = clutter.Color(0xff, 0xcc, 0xcc, 0xdd) self.label = clutter.Text() self.label.set_font_name('Mono 32') self.label.set_text(message) self.label.set_color(color) (label_width, label_height) = self.label.get_size() label_x = self.stage.get_width() - label_width - 50 label_y = self.stage.get_height() - label_height self.label.set_position(label_x, label_y) self.stage.add(self.label) self.cursor = clutter.Rectangle() self.cursor.set_color(color) self.cursor.set_size(20, label_height) cursor_x = self.stage.get_width() - 50 cursor_y = self.stage.get_height() - label_height self.cursor.set_position(cursor_x, cursor_y) self.stage.add(self.cursor) self.timeline = clutter.Timeline(500) self.timeline.set_loop(True) alpha = clutter.Alpha(self.timeline, clutter.LINEAR) self.behaviour = clutter.BehaviourOpacity(0xdd, 0, alpha) self.behaviour.apply(self.cursor)
def _update_album_preview(self, album): """ Update album preview. Display preview images from the current album. @param album: Currently selected album in menu """ if self.preview_fade is not None: gobject.source_remove(self.preview_fade) new = self._create_album_preview(album) if self.config.show_effects: old = self.preview new.set_opacity(0) self.preview = new self.add(self.preview) #Fade out timeline timeline1 = clutter.Timeline(500) alpha1 = clutter.Alpha(timeline1, clutter.EASE_IN_OUT_SINE) self.out_opacity = clutter.BehaviourOpacity(255, 0, alpha1) self.out_opacity.apply(old) timeline1.connect('completed', self._change_preview_timeline_ended, old) # Fade in timeline timeline2 = clutter.Timeline(500) alpha2 = clutter.Alpha(timeline2, clutter.EASE_IN_OUT_SINE) self.in_opacity = clutter.BehaviourOpacity(0, 255, alpha2) self.in_opacity.apply(new) # Start animation timeline1.start() timeline2.start() else: # Do it without animation if self.preview is not None: self.remove(self.preview) self.preview = new self.add(self.preview) if len(self.preview_textures) > 1: self.preview_fade = gobject.timeout_add(6000, self._change_preview_image) return False # see gobject.timeout_add() doc
def hide(self): '''Hide throbber smoothly and stop animation.''' timeline = clutter.Timeline(2000) alpha = clutter.Alpha(timeline, clutter.EASE_IN_OUT_SINE) self.behaviour = clutter.BehaviourOpacity(255, 0, alpha) self.behaviour.apply(self) timeline.start() gobject.timeout_add(5, self._stop_rotating, timeline)
def _setupPageTurning(self): self.pageTurnTl = clutter.Timeline(200) self.pageTurnAlpha = clutter.Alpha(self.pageTurnTl, clutter.EASE_IN_CIRC) self.fadeIn = self._fadeInOpac self.fadeOut = self._fadeOutOpac # page turn complete notifications self.pageShownCB = None self.pageTurnTl.connect('completed', self._pageTurnDoneCB) self.oldPage = None
def main(): stage_color = clutter.Color(176, 176, 176, 255) # light gray # Get the stage and set its size and color stage = clutter.Stage() stage.set_size(800, 600) stage.set_color(stage_color) # Create and add a label actor, hidden at first global label_filename label_filename = clutter.Text() label_color = clutter.Color(96, 96, 144, 255) # blueish label_filename.set_color(label_color) label_filename.set_font_name("Sans 24") label_filename.set_position(10, 10) label_filename.set_opacity(0) stage.add(label_filename) label_filename.show() # Add a plane under the ellipse of images rect_color = clutter.Color(255, 255, 255, 255) # white rect = clutter.Rectangle(rect_color) rect.set_height(ELLIPSE_HEIGHT + 20) rect.set_width(stage.get_width() + 100) # Position it so that its center is under the images rect.set_position(-(rect.get_width() - stage.get_width()) / 2, ELLIPSE_Y + IMAGE_HEIGHT - (rect.get_height() / 2)) # Rotate it around its center rect.set_rotation(clutter.X_AXIS, -90, 0, rect.get_height() / 2, 0) stage.add(rect) rect.show() # show the stage stage.connect("destroy", clutter.main_quit) stage.show_all() global timeline_rotation timeline_rotation = clutter.Timeline(2000) # milliseconds timeline_rotation.connect('completed', on_timeline_rotation_completed) # Add an actor for each image load_images("images") add_image_actors(stage) # timeline_rotation.set_loop(True) # Move them a bit to start with global list_items if list_items: rotate_all_until_item_is_at_front(list_items[0]) # Start the main loop, so we can respond to events clutter.main() return 0
def __init__(self, x, y, width, height, color="title"): Base.__init__(self) clutter.Group.__init__(self) self.width = self.get_abs_x(width) self.height = self.get_abs_y(height) self.bar_width = int(self.width * self.BAR_LENGTH) self.bar_x = int(self.width * self.INFO_LENGTH) self.media_length_x = (1 - self.INFO_LENGTH + 0.05) * width self.set_position(self.get_abs_x(x), self.get_abs_y(y)) self._color = self._color_to_cairo_color( self.config.theme.get_color(color)) self._background = clutter.CairoTexture(self.bar_width, self.height) self._draw_background() self._background.set_position(self.bar_x, 0) self.add(self._background) self._foreground = clutter.CairoTexture(self.height, self.height) self._foreground.set_anchor_point_from_gravity(clutter.GRAVITY_CENTER) self._draw_foreground() self._foreground.set_position(self.bar_x, 0) self.add(self._foreground) self.media_position = Label(0.037, "title", 0, 0, "") self.add(self.media_position) self.media_length = Label(0.037, "title", self.media_length_x, 0, "") self.add(self.media_length) self._media_player = None self._progress_bar_moving = False self._hide_timeout_key = None self.auto_display = False self._visible = None self._timeline = clutter.Timeline(500) self._alpha = clutter.Alpha(self._timeline, clutter.EASE_IN_OUT_SINE) self._behaviour = clutter.BehaviourOpacity(0, 255, self._alpha) self._behaviour.apply(self) self._progress = None # Call the property setter to initialize the displayed position. self.progress = 0 # Preparation to pointer events handling. self._motion_handler = 0 self.set_reactive(True) self.connect('scroll-event', self._on_scroll_event) self.connect('button-press-event', self._on_button_press_event) self.connect('button-release-event', self._on_button_release_event) self.connect('enter-event', self._on_enter_event) self.connect('leave-event', self._on_leave_event)
def __init__(self, pb, mieru, name="", fitOnStart=True): # clutter.Texture.__init__(self,imagePath,load_data_async=True) page.Page.__init__(self) clutter.Texture.__init__(self) if pb.props.has_alpha: bpp = 4 else: bpp = 3 self.set_from_rgb_data( pb.get_pixels(), pb.props.has_alpha, pb.props.width, pb.props.height, pb.props.rowstride, bpp, 0) del pb self.originalSize = self.get_size() self.mieru = mieru self.initialPosition = (0,0) self.motionCallbackId = None if fitOnStart: self.setFitMode(self.mieru.get('fitMode', 'original')) # implement current fit mode self._color = clutter.color_from_string('White') self.isPressed = False self.pressStart = (0,0) self.lastMotion = None self.lastMotionTimestamp = 0 self.lastDTDXDY = (0,0,0) self.clickCount = 0 self.msButtonLastReleaseTimestamp = 0 self.decelTl = clutter.Timeline(3000) self.decelTl.connect('new_frame', self._decelerateCB) self.stopDecel = True self._resetDecel() """first number id for the horizontal and second for the vertical axis, 0 means movement in this axis is disabled, 1 means movement is enabled""" self.movementEnabled = (1,1) # the page is fit to screen so it should not be move self.zoomIn=True self.msButtonLastPressTimestamp = None self.pressLength = 100 self.connect('button-press-event', self.do_button_press_event) self.connect('button-release-event', self.do_button_release_event) self.resizeCallbackId = None self.set_keep_aspect_ratio(True) # we want to preserve the aspect ratio
def __init__(self, width, height, text, extra_text=None): TextMenuItem.__init__(self, width, height, text, extra_text) self.move_anchor_point_from_gravity(clutter.GRAVITY_WEST) self.font_size = 0.03 self.update() self.timeline = clutter.Timeline(200) alpha = clutter.Alpha(self.timeline, clutter.EASE_IN_OUT_SINE) self.behaviour = FontSizeBehaviour(alpha) self.behaviour.apply(self)
def main(): stage_color = clutter.Color(0, 0, 0, 255) rect_color = clutter.Color(255, 255, 255, 153) # Get the stage and set its size and color stage = clutter.Stage() stage.set_size(200, 200) stage.set_color(stage_color) # Add a rectangle to the stage global rect rect = clutter.Rectangle(rect_color) rect.set_size(70, 70) rect.set_position(50, 100) stage.add(rect) rect.show() # Show the stage stage.connect('destroy', clutter.main_quit) stage.show() # Create a score and add two timelines to it, # so the second timeline starts when the first one stops score = clutter.Score() score.set_loop(True) timeline_rotation = clutter.Timeline(5000) # milliseconds timeline_rotation.connect('new-frame', on_timeline_rotation_new_frame) score.append(timeline=timeline_rotation) timeline_move = clutter.Timeline(5000) # milliseconds timeline_move.connect('new-frame', on_timeline_move_new_frame) score.append(parent=timeline_rotation, timeline=timeline_move) score.start() # Start the main loop, so we can respond to events clutter.main() return 0
def forward_effect(self, from_screen, to_screen): """ Fade+zoom out all components from the "from_screen" and fade+zoom in all components of the "to_screen". @param from_screen: Screen object (Currently displayed screen) @param to_screen: Screen object (Screen displayed after transition) """ # Initialize to_screen for animation to_screen.set_opacity(0) to_screen.show() # Fade out current screen if from_screen is not None: fade_out = clutter.Timeline(22, 85) alpha_out = clutter.Alpha(fade_out, clutter.smoothstep_inc_func) self.out_fade = clutter.BehaviourOpacity(255, 0, alpha_out) self.out_fade.apply(from_screen) #from_screen.set_anchor_point_from_gravity( # clutter.GRAVITY_CENTER) self.out_zoom = clutter.BehaviourScale(1.0, 1.0, 1.2, 1.2, alpha_out) #from_screen.set_anchor_point(0,0) self.out_zoom.apply(from_screen) # Fade in timeline fade_in = clutter.Timeline(22, 85) alpha_in = clutter.Alpha(fade_in, clutter.smoothstep_inc_func) self.in_behaviour = clutter.BehaviourOpacity(0, 255, alpha_in) self.in_behaviour.apply(to_screen) #to_screen.set_anchor_point_from_gravity( # clutter.GRAVITY_CENTER) self.in_zoom = clutter.BehaviourScale(0.8, 0.8, 1.0, 1.0, alpha_in) #to_screen.set_anchor_point(0,0) self.in_zoom.apply(to_screen) # Start transition animation if from_screen is not None: fade_out.start() fade_in.start()
def __init__(self): #create a clutter stage self.stage = clutter.Stage() #set the stage size in x,y pixels self.stage.set_size(500, 200) #define some clutter colors in rgbo (red,green,blue,opacity) color_black = clutter.Color(0, 0, 0, 255) color_green = clutter.Color(0, 255, 0, 255) color_blue = clutter.Color(0, 0, 255, 255) #set the clutter stages bg color to our black self.stage.set_color(color_black) #we will need to check on the key presses from the user self.stage.connect('key-press-event', self.parseKeyPress) #create a clutter label, is there documentation for creating a clutterlabel? self.label = clutter.Label() #set the labels font self.label.set_font_name('Mono 32') #add some text to the label self.label.set_text("Hello") #make the label green self.label.set_color(color_green) #put the label in the center of the stage (label_width, label_height) = self.label.get_size() label_x = (self.stage.get_width() / 2) - label_width / 2 label_y = (self.stage.get_height() / 2) - label_height / 2 self.label.set_position(label_x, label_y) #make a second label similar to the first label self.label2 = clutter.Label() self.label2.set_font_name('Mono 32') self.label2.set_text("World!") self.label2.set_color(color_blue) (label2_width, label2_height) = self.label2.get_size() label2_x = (self.stage.get_width() / 2) - label2_width / 2 label2_y = (self.stage.get_height() / 2) - label2_height / 2 self.label2.set_position(label2_x, label2_y) #hide the label2 self.label2.set_opacity(0) #create a timeline for the animations that are going to happen self.timeline = clutter.Timeline(fps=20, duration=500) #how will the animation flow? ease in? ease out? or steady? #ramp_inc_func will make the animation steady labelalpha = clutter.Alpha(self.timeline, clutter.ramp_inc_func) #make some opacity behaviours that we will apply to the labels self.hideBehaviour = clutter.BehaviourOpacity(255, 0x00, labelalpha) self.showBehaviour = clutter.BehaviourOpacity(0x00, 255, labelalpha) #add the items to the stage self.stage.add(self.label2) self.stage.add(self.label) #show all stage items and enter the clutter main loop self.stage.show_all() clutter.main()
def _do_slide(self, from_screen, to_screen, direction, remove_screen): '''Execute the common sliding logic needed by each direction. Direction will set the sign of width to determine which way to slide.''' width = self.config.stage_width * direction # Initialize to_screen for animation to_screen.set_position(-width, 0) to_screen.show() # Slide out timeline if from_screen is not None: slide_out = clutter.Timeline(500) alpha_out = clutter.Alpha(slide_out, clutter.EASE_IN_OUT_SINE) out_path = clutter.Path() out_path.add_move_to(0, 0) out_path.add_line_to(width, 0) self.out_behaviour = clutter.BehaviourPath(alpha_out, out_path) self.out_behaviour.apply(from_screen) if remove_screen: slide_out.connect('completed', self._remove_from_stage_callback, from_screen) # Slide in timeline slide_in = clutter.Timeline(500) alpha_in = clutter.Alpha(slide_in, clutter.EASE_IN_OUT_SINE) in_path = clutter.Path() in_path.add_move_to(-width, 0) in_path.add_line_to(0, 0) self.in_behaviour = clutter.BehaviourPath(alpha_in, in_path) self.in_behaviour.apply(to_screen) # Start transition animating if from_screen is not None: slide_out.start() slide_in.start()
def __init__(self, actor, function, duration, target, start=None): self.actor = actor self.function = function self.duration = duration if start is None: self.startValue = actor.get_opacity() else: self.startValue = start self.targetValue = target self.timeline = clutter.Timeline(self.duration) self.alpha = clutter.Alpha(self.timeline, self.function) self.BehOp = clutter.BehaviourOpacity(self.startValue, self.targetValue, self.alpha) self.BehOp.apply(actor)
def backward_effect(self, from_screen, to_screen): """ Do the same as forward_effect, but zoom backwards. This gives an illusion of going back. @param from_screen: Screen object (Currently displayed screen) @param to_screen: Screen object (Screen displayed after transition) """ # Initialize to_screen for animation to_screen.set_opacity(0x00) to_screen.show() # Fade out current screen fade_out = clutter.Timeline(22, 85) alpha_out = clutter.Alpha(fade_out, clutter.smoothstep_inc_func) self.out_fade = clutter.BehaviourOpacity(255, 0, alpha_out) self.out_fade.apply(from_screen) #from_screen.set_anchor_point_from_gravity( # clutter.GRAVITY_CENTER) self.out_zoom = clutter.BehaviourScale(1.0, 1.0, 0.8, 0.8, alpha_out) self.out_zoom.apply(from_screen) fade_out.connect('completed', self._remove_from_stage_callback, from_screen) # Fade in timeline fade_in = clutter.Timeline(22, 85) alpha_in = clutter.Alpha(fade_in, clutter.smoothstep_inc_func) self.in_behaviour = clutter.BehaviourOpacity(0, 255, alpha_in) self.in_behaviour.apply(to_screen) #to_screen.set_anchor_point_from_gravity( # clutter.GRAVITY_CENTER) self.in_zoom = clutter.BehaviourScale(1.2, 1.2, 1.0, 1.0, alpha_in) self.in_zoom.apply(to_screen) # Start transition animation if from_screen is not None: fade_out.start() fade_in.start()
def __init__(self, x, y, width, height, content): Base.__init__(self) clutter.Group.__init__(self) self._motion_buffer = MotionBuffer() self._offset = 0 # Drives the content motion. self._offset_max = 0 # Maximum value of offset (equal on bottom). self._old_offset = 0 # Stores the old value of offset on motions. self._motion_handler = 0 self._active = None self.step_size = self.get_abs_y(self.STEP_SIZE_PERCENT) # Allowed area for the widget's scrolling content. self.area_width = self.get_abs_x(width) self.area_height = self.get_abs_y(height) # Create content position indicator self.indicator = ListIndicator(3 * width / 4, height, 0.2, 0.045, ListIndicator.VERTICAL) self.indicator.hide_position() self.indicator.set_maximum(2) self.add(self.indicator) # A clipped Group to receive the content. self._fixed_group = clutter.Group() self._fixed_group.set_clip(0, 0, self.area_width, self.area_height) self.add(self._fixed_group) self.content = None self._motion_timeline = clutter.Timeline(500) self._motion_timeline.connect('completed', self._motion_timeline_callback, None) self._motion_alpha = clutter.Alpha(self._motion_timeline, clutter.EASE_OUT_SINE) self._motion_behaviour = LoopedPathBehaviour(self._motion_alpha) self.set_content(content) self.active = None # Preparation to pointer events handling. self.set_reactive(True) self.connect('button-press-event', self._on_button_press_event) self.connect('button-release-event', self._on_button_release_event) self.connect('scroll-event', self._on_scroll_event) self.set_position(self.get_abs_x(x), self.get_abs_y(y))
def main(args): stage = clutter.Stage() stage.set_size(800, 600) stage.set_color(clutter.Color(0xcc, 0xcc, 0xcc, 0xff)) stage.connect('key-press-event', clutter.main_quit) stage.connect('destroy', clutter.main_quit) rect = clutter.Rectangle() rect.set_position(0, 0) rect.set_size(150, 150) rect.set_color(clutter.Color(0x33, 0x22, 0x22, 0xff)) rect.set_border_color(clutter.color_from_string('white')) rect.set_border_width(15) rect.show() knots = ( \ ( 0, 0 ), \ ( 300, 0 ), \ ( 300, 300 ), \ ( 0, 300 ), \ ) path = clutter.Path('M 0 0 L 300 0 L 300 300 L 0 300') timeline = clutter.Timeline(3000) timeline.set_loop(True) alpha = clutter.Alpha(timeline, clutter.EASE_OUT_SINE) o_behaviour = clutter.BehaviourOpacity(alpha=alpha, opacity_start=0x33, opacity_end=255) o_behaviour.apply(rect) p_behaviour = clutter.BehaviourPath(alpha, path) path.add_move_to(0, 0) p_behaviour.apply(rect) r_behaviour = BehaviourRotate(alpha) r_behaviour.apply(rect) stage.add(rect) stage.show() timeline.start() clutter.main() return 0
def main(): stage_color = clutter.Color(0, 0, 0, 255) rect_color = clutter.Color(255, 255, 255, 153) # Get the stage and set its size and color stage = clutter.Stage() stage.set_size(200, 200) stage.set_color(stage_color) # Add a rectangle to the stage rect = clutter.Rectangle(rect_color) rect.set_size(40, 40) rect.set_position(10, 10) stage.add(rect) rect.show() # Show the stage stage.connect('destroy', clutter.main_quit) stage.show() timeline = clutter.Timeline(5000) # milliseconds timeline.set_loop(True) timeline.start() # Create a clutter alpha for the animation alpha = clutter.Alpha(timeline) alpha.set_func(on_alpha, None) # Create an animation to change the properties # XXX: There is a bug in pygobject that will refuse to convert between # ints and chars. This should be fixed when clutter 1.2 is out and # pyclutter targets it. The result is that the opacity won't be animated # the bug report is https://bugzilla.gnome.org/show_bug.cgi?id=591800 # and shall be fixed in the next release, so perhaps by the time you read # this is already fixed. rect.animate_with_alpha(alpha, 'x', 150.0, 'y', 150.0, 'opacity', 0.0) # Start the main loop, so we can respond to events clutter.main() return 0
def __init__(self, obj): super(BlinkingText, self).__init__( settings.SCROLLING_TEXT_FONT, obj.__str__() ) self.obj = obj # Setup text attributes self.set_color(FONT_COLOR) self.set_opacity(FONT_OPACITY) self.set_property('scale-gravity', clutter.GRAVITY_CENTER) self.set_line_alignment(ALIGN_CENTER) self.set_line_wrap(True) # Setup blinking timeline. self.timeline = clutter.Timeline(duration=settings.BLINKING_TEXT_RATE) self.timeline.set_loop(True) self.alpha = clutter.Alpha(self.timeline, clutter.LINEAR) self.blink = clutter.BehaviourOpacity(alpha=self.alpha, opacity_start=FONT_OPACITY, opacity_end=255) self.timeline.connect('completed', self.on_blink_completed)
def _update_preview_area(self): '''Update the preview area to display the current menu item.''' self.preview.remove_all() item = self.menu.get_selected() self.preview.set_opacity(0x00) update = True if item.get_name() == "playing": self.preview.add(self._create_playing_preview()) else: update = False # If the preview was updated fade it in. if update: fade_in = clutter.Timeline(500) alpha_in = clutter.Alpha(fade_in, clutter.EASE_IN_OUT_SINE) self.behaviour = clutter.BehaviourOpacity(0, 255, alpha_in) self.behaviour.apply(self.preview) fade_in.start()
def main(args): stage = clutter.Stage() stage.set_color(clutter.Color(0, 0, 0, 255)) stage.set_title('TextureReflection') stage.connect('button-press-event', clutter.main_quit) stage.connect('destroy', clutter.main_quit) group = clutter.Group() stage.add(group) try: tex = clutter.Texture(filename=args[0]) except Exception: print "Unable to load the texture file" return 1 reflect = TextureReflection(tex) reflect.set_opacity(100) x_pos = float((stage.get_width() - tex.get_width()) / 2) group.add(tex, reflect) group.set_position(x_pos, 20.0) reflect.set_position(0.0, (tex.get_height() + 20)) timeline = clutter.Timeline(duration=3000) timeline.set_loop(True) alpha = clutter.Alpha(timeline, clutter.LINEAR) behaviour = clutter.BehaviourRotate(clutter.Y_AXIS, 0.0, 360.0, alpha, clutter.ROTATE_CW) behaviour.set_center(int(group.get_width() / 2), 0, 0) behaviour.apply(group) stage.show() timeline.start() clutter.main() return 0