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