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 _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 setUp(self): '''Set up the test.''' EntertainerTest.setUp(self) self.menu = ImageMenu(0, 0) self.texture = Texture(os.path.join( THIS_DIR, 'data/ImageThumbnailer/test.jpg'))
def setUp(self): """Set up the test""" EntertainerTest.setUp(self) self.filename = os.path.join(THIS_DIR, 'data/ImageThumbnailer/test.jpg') self.texture = Texture(self.filename, 0.1, 0.2)
def create_day(self, day, x, y): """Create the Texture and labels for one day""" self.add(Texture(day["Image"], x, y)) self.add(Label(0.04167, "text", x, y + 0.2, day["Day"], font_weight="bold")) conditions_text = \ _("High: %(high)s Low: %(low)s\nCondition: %(cond)s") % \ {'high': day["High"], 'low': day["Low"], 'cond': day["Condition"]} self.add(Label(0.03, "text", x, y + 0.25, conditions_text))
def setUp(self): '''Set up the test.''' EntertainerTest.setUp(self) self.filename = os.path.join(THIS_DIR, 'data/ImageThumbnailer/test.jpg') self.texture = Texture(self.filename) self.original_ratio = float(self.texture.get_width()) / \ self.texture.get_height() self.item = ImageMenuItem(0.2, 0.1, self.texture)
def get_texture(self): '''Get media's texture. This is a video texture or album art texture.''' if self.media.get_type() == Playable.VIDEO_STREAM: return clutter.Clone(self.video_texture) elif self.media.get_type() == Playable.AUDIO_STREAM: url = self.media.get_album_art_url() if url is not None: texture = Texture(url) return texture else: return None
def _create_aspect_ratio_textures(self): ''' Create textures that which are displayed when user changes aspect ratio. ''' texture_1 = Texture(self.theme.getImage("native_aspect_ratio")) texture_1.hide() self.add(texture_1) texture_2 = Texture(self.theme.getImage("widescreen_aspect_ratio")) texture_2.hide() self.add(texture_2) texture_3 = Texture(self.theme.getImage("zoom_aspect_ratio")) texture_3.hide() self.add(texture_3) texture_4 = Texture(self.theme.getImage("compromise_aspect_ratio")) texture_4.hide() self.add(texture_4) self.aspect_textures = [texture_1, texture_2, texture_3, texture_4] self.timeout_key = None # This is used when canceling timeouts for texture in self.aspect_textures: texture.position = ( float(self.config.stage_width - texture.get_width()) / (self.config.stage_width * 2), 0.67)
def _create_playing_preview(self): '''Create the Now Playing preview sidebar.''' preview = clutter.Group() # Video preview of current media video_texture = self.media_player.get_texture() if video_texture == None: video_texture = Texture(self.theme.getImage("default_album_art")) width, height = video_texture.get_size() x_ratio = (self.PREVIEW_WIDTH - 50) / float(width) y_ratio = (self.PREVIEW_HEIGHT - 50) / float(height) if x_ratio > y_ratio: video_texture.set_scale((self.PREVIEW_HEIGHT - 50) / float(height), (self.PREVIEW_HEIGHT - 50) / float(height)) new_width = int(width * \ ((self.PREVIEW_HEIGHT - 50) / float(height))) new_x = int(((self.PREVIEW_WIDTH - 50) - new_width) / 2.0) video_texture.set_position(int(new_x), 0) # Below are size and position calculations for border rectangle rect_x = new_x -3 rect_y = -3 new_width = (self.PREVIEW_HEIGHT - 50) / float(height) * width new_height = (self.PREVIEW_HEIGHT - 50) / float(height) * height else: video_texture.set_scale((self.PREVIEW_WIDTH - 50) / float(width), (self.PREVIEW_WIDTH - 50) / float(width)) new_height = int(height * \ ((self.PREVIEW_WIDTH - 50) / float(width))) new_y = int(((self.PREVIEW_HEIGHT - 50) - new_height) / 2.0) video_texture.set_position(0, int(new_y)) rect_x = -3 rect_y = new_y -3 # Below are size and position calculations for border rectangle new_width = (self.PREVIEW_WIDTH - 50) / float(width) * width new_height = (self.PREVIEW_WIDTH - 50) / float(width) * height # Video frame rect = clutter.Rectangle() rect.set_size(int(new_width + 6), int(new_height + 6)) rect.set_position(rect_x, rect_y) rect.set_color((128, 128, 128, 192)) preview.add(rect) preview.add(video_texture) self._preview_title = Label(0.03, "text", 0.03, 0.74, "") preview.add(self._preview_title) return preview
def __init__(self, move_to_new_screen_callback, title, images): Screen.__init__(self, 'Photographs', move_to_new_screen_callback) self.images = images # Screen Title (Displayed at the bottom left corner) screen_title = Label(0.13, "screentitle", 0, 0.87, title) self.add(screen_title) # Image Title (over album list) self.image_title = Label(0.04167, "title", 0.0586, 0.7943, " ") self.image_title.set_ellipsize(pango.ELLIPSIZE_END) self.add(self.image_title) self.image_desc = Label(0.04167, "subtitle", 0.0586, 0.9115, " ") self.image_desc.set_line_wrap(True) self.image_desc.set_ellipsize(pango.ELLIPSIZE_END) self.add(self.image_desc) # Display throbber animation while loading photographs self.throbber = LoadingAnimation(0.9, 0.9) self.throbber.show() self.add(self.throbber) # List indicator self.li = None self._create_list_indicator() # Create photomenu self.menu = ImageMenu(0.03, 0.08, 0.12, self.y_for_x(0.12)) self.menu.items_per_col = 3 self.menu.visible_rows = 3 self.menu.visible_cols = 8 self.menu.active = True self.add(self.menu) photos = self.images photos_list = [[Texture(photo.get_thumbnail_url()), photo] \ for photo in photos] self.menu.async_add(photos_list) self.menu.connect("selected", self._handle_select) self.menu.connect('moved', self._update_image_info) self.menu.connect("filled", self._on_menu_filled)
def show_empty_tab_notice(self, title=_("Empty tab"), message_body=_("This tab doesn't contain any elements.")): ''' Create an information box that is displayed if there is no widgets in this tab. This method should be called only from child class as needed. ''' # Create warning icon info_icon = Texture(self.theme.getImage("warning_icon"), 0.28, 0.27) self.add(info_icon) # Create warning title info_title = Label(0.0625, "title", 0.33, 0.27, title) self.add(info_title) # Create warning help text info = Label(0.042, "menuitem_inactive", 0.28, 0.4, message_body) info.width = 0.57 self.add(info)
def async_add_albums(self, items): """ Add asynchronously ImageMenuItem using a list. The created ImageMenuItem fits albums requirements. See also async_add comments. """ if len(items) > 0: item = items[0] if item[1].has_album_art(): texture = Texture(item[0]) else: texture = clutter.Clone(self.album_default) self.add_item(texture, item[1]) # Recursive call, remove first element from the list gobject.timeout_add(10, self.async_add_albums, items[1:]) else: self.emit("filled") return False
def _change_image(self, index): """ Change current image. Display image from given index. """ if self.texture: self.texture.destroy() # Create a new texture and display it image = self.images[index] self.index = index self.texture = Texture(image.get_filename()) self._scale_image(self.texture) timeline = clutter.Timeline(1000) alpha = clutter.Alpha(timeline, clutter.EASE_IN_OUT_SINE) self.opacity_behaviour = clutter.BehaviourOpacity(alpha=alpha, opacity_start=0, opacity_end=255) self.opacity_behaviour.apply(self.texture) self.texture.set_opacity(0) timeline.start() self.add(self.texture)
def _create_no_music_information(self): """ Create textures and labels for information screen. This is displayed instead of artist list if there are no tracks available and it helps users to add new music to the system. """ # Create warning icon warning_icon = Texture(self.theme.getImage("warning_icon"), 0.28, 0.27) self.add(warning_icon) # Create warning title info_title = Label(0.0625, "title", 0.3367, 0.2709, _("No music available!")) self.add(info_title) # Create warning help text message = _( "There are no indexed artists in the Entertainer media " "library. To add music, start the Content management tool " "and open the 'Music' tab. Now click on the 'Add' button and " "select some folders which contain music files.") info = Label(0.0417, "menuitem_inactive", 0.2804, 0.45, message) info.width = 0.5 self.add(info)
def _create_no_photos_information(self): """ Create textures and labels for information screen. This is displayed instead of album list if there are no photos available and it helps users to add new photographs to the system. """ # Create warning icon warning_icon = Texture(self.theme.getImage("warning_icon"), 0.28, 0.27) self.add(warning_icon) # Create warning title info_title = Label(0.0625, "title", 0.3367, 0.2709, _("No photographs available!")) self.add(info_title) # Create warning help text message = _( "There are no indexed photographs in the Entertainer media " "library. To add photographs, start the Content management tool " "and open the 'Images' tab. Now click on the 'Add' button and " "select some folders which contain image files.") info = Label(0.0417, "menuitem_inactive", 0.2804, 0.45, message) info.set_size(0.5, 0.5859) self.add(info)
def __init__(self, x=0, y=0, item_width=0.2, item_height=0.1): GridMenu.__init__(self, x, y, item_width, item_height) self.cursor_below = False self.horizontal = True self.items_per_col = 4 self.visible_rows = 3 self.visible_cols = 5 c = clutter.Rectangle() c.set_size(100, 100) c.set_color((255, 255, 255, 128)) self.cursor = c pix_buffer = gtk.gdk.pixbuf_new_from_file( self.config.theme.getImage("default_movie_art")) self.movie_default = RoundedTexture(0.0, 0.0, 0.1, 0.25, pix_buffer) self.movie_default.hide() self.add(self.movie_default) self.album_default = Texture( self.config.theme.getImage("default_album_art")) self.album_default.hide() self.add(self.album_default)
def _create_navigation_textures(self): '''Create the pause, seek-backward & seek-forward textures.''' self.pause_texture = Texture( self.theme.getImage("media-playback-pause"), 0.5, 0.5) self.pause_texture.set_anchor_point_from_gravity( clutter.GRAVITY_CENTER) self.pause_texture.hide() self.add(self.pause_texture) pause_in_time = clutter.Timeline(1000) in_alpha_pause = clutter.Alpha(pause_in_time, clutter.EASE_IN_OUT_SINE) self.pause_in_opacity = clutter.BehaviourOpacity(alpha=in_alpha_pause, opacity_start=100, opacity_end=255) self.pause_in_scale = clutter.BehaviourScale(1.0, 1.0, 1.4, 1.4, in_alpha_pause) self.pause_in_opacity.apply(self.pause_texture) self.pause_in_scale.apply(self.pause_texture) pause_out_time = clutter.Timeline(1000) out_alpha_pause = clutter.Alpha(pause_out_time, clutter.EASE_IN_OUT_SINE) self.pause_out_opacity = clutter.BehaviourOpacity( alpha=out_alpha_pause, opacity_start=255, opacity_end=100) self.pause_out_scale = clutter.BehaviourScale(1.4, 1.4, 1.0, 1.0, out_alpha_pause) self.pause_out_opacity.apply(self.pause_texture) self.pause_out_scale.apply(self.pause_texture) self.score = clutter.Score() self.score.set_loop(True) self.score.append(timeline=pause_in_time) self.score.append(timeline=pause_out_time, parent=pause_in_time) self.score.start() self.seekbackward_texture = Texture( self.theme.getImage("media-seek-backward"), 0.1, 0.5) self.seekbackward_texture.set_anchor_point_from_gravity( clutter.GRAVITY_CENTER) self.seekbackward_texture.set_opacity(0) self.add(self.seekbackward_texture) self.seekbackward_timeline = clutter.Timeline(1000) alpha_seekbackward = clutter.Alpha(self.seekbackward_timeline, clutter.EASE_IN_OUT_SINE) self.seekbackward_opacity = clutter.BehaviourOpacity( alpha=alpha_seekbackward, opacity_start=255, opacity_end=0) self.seekbackward_opacity.apply(self.seekbackward_texture) self.seekforward_texture = Texture( self.theme.getImage("media-seek-forward"), 0.9, 0.5) self.seekforward_texture.set_anchor_point_from_gravity( clutter.GRAVITY_CENTER) self.seekforward_texture.set_opacity(0) self.add(self.seekforward_texture) self.seekforward_timeline = clutter.Timeline(1000) alpha_seekforward = clutter.Alpha(self.seekforward_timeline, clutter.EASE_IN_OUT_SINE) self.seekforward_opacity = clutter.BehaviourOpacity( alpha=alpha_seekforward, opacity_start=255, opacity_end=0) self.seekforward_opacity.apply(self.seekforward_texture)
def testNoInitPosition(self): """Test that a texture will be displayed at the origin of the display area if no initial position is given""" no_pos_texture = Texture(self.filename) self.assertEqual(no_pos_texture.position, (0, 0))
def create_movie_information(self): '''Create clutter parts related to movie information''' # Movie art texture if self.movie.has_cover_art(): pixbuf = gtk.gdk.pixbuf_new_from_file(self.movie.cover_art_url) else: pixbuf = gtk.gdk.pixbuf_new_from_file( self.theme.getImage("default_movie_art")) movie_art = EyeCandyTexture(0.33, 0.1, 0.1, 0.25, pixbuf) self.add(movie_art) # Movie title title = Label(0.04, "title", 0.47, 0.1, self.movie.title, font_weight="bold") title.set_ellipsize(pango.ELLIPSIZE_END) title.set_size(0.5124, 0.05208) self.add(title) # Movie release year year_text = _("Released in %(year)s") % {'year': self.movie.year} year = Label(0.032, "subtitle", 0.47, 0.3, year_text) year.set_ellipsize(pango.ELLIPSIZE_END) year.set_size(0.5124, 0.05208) self.add(year) # Show only 2 genres (or one if there is only one) genres_list = self.movie.genres if len(genres_list) == 0: genres_text = _("Unknown") else: genres_text = "/".join(genres_list[:2]) # Runtime and genres info_text = _("%(runtime)s min, %(genre)s") % \ {'runtime': self.movie.runtime, 'genre': genres_text} info = Label(0.032, "subtitle", 0.47, 0.24, info_text) info.set_ellipsize(pango.ELLIPSIZE_END) info.set_size(0.5124, 0.05208) self.add(info) # Stars (rating) star = Texture(self.theme.getImage("star")) star.hide() self.add(star) star2 = Texture(self.theme.getImage("star2")) star2.hide() self.add(star2) for i in range(self.movie.rating): tex = clutter.Clone(star) tex.set_position( self.get_abs_x(0.47) + (self.get_abs_x(0.0366) * i), self.get_abs_y(0.17)) tex.set_size(self.get_abs_x(0.024), self.get_abs_y(0.04)) self.add(tex) dark_star = 5 - self.movie.rating for i in range(dark_star): tex = clutter.Clone(star2) tex.set_position(self.get_abs_x(0.47) + (self.get_abs_x(0.0366) * \ (i + self.movie.rating)), self.get_abs_y(0.17)) tex.set_size(self.get_abs_x(0.024), self.get_abs_y(0.04)) self.add(tex) # Plot plot = Label(0.029, "subtitle", 0, 0, self.movie.plot) plot.set_justify(True) plot.set_line_wrap_mode(pango.WRAP_WORD) plot.set_line_wrap(True) plot.width = 0.5124 self.scroll_area = ScrollArea(0.33, 0.38, 0.5124, 0.3516, plot) self.add(self.scroll_area) # Actors self.add(Label(0.032, "title", 0.33, 0.8, _("Starring"))) actors_list = self.movie.actors if len(actors_list) == 0: actors_text = _("Unknown") else: actors_text = ", ".join(actors_list[:5]) actors = Label(0.032, "subtitle", 0.46, 0.8, actors_text) actors.set_ellipsize(pango.ELLIPSIZE_END) actors.set_size(0.5124, 0.05208) self.add(actors) # Directors self.add(Label(0.032, "title", 0.33, 0.86, _("Directed by"))) directors_list = self.movie.directors if len(directors_list) == 0: directors_text = _("Unknown") else: directors_text = ", ".join(directors_list[:2]) directors = Label(0.032, "subtitle", 0.46, 0.86, directors_text) directors.set_ellipsize(pango.ELLIPSIZE_END) directors.set_size(0.5124, 0.05208) self.add(directors) # Writers self.add(Label(0.032, "title", 0.33, 0.92, _("Written by"))) writers_list = self.movie.writers if len(directors_list) == 0: writers_text = _("Unknown") else: writers_text = ", ".join(writers_list[:2]) writers = Label(0.032, "subtitle", 0.46, 0.92, writers_text) writers.set_ellipsize(pango.ELLIPSIZE_END) writers.set_size(0.5124, 0.05208) self.add(writers)