def _get_disc_information(self): """ Fetch album information from the Internet and create widgets based on received data. """ try: disc = self.music_library.get_compact_disc_information() title = disc.title artist = disc.artist tracks = disc.tracks self.playlist = Playlist(tracks) self._create_album_info(title, artist, tracks, disc.length) self.track_menu = self._create_track_menu(tracks) self.add(self.track_menu) self._create_album_cover_texture(artist, title) self.li = ListIndicator(0.75, 0.8, 0.2, 0.045, ListIndicator.VERTICAL) self.li.set_maximum(len(tracks)) self.add(self.li) art_file = os.path.join(self.config.ALBUM_ART_DIR, artist + " - " + title + ".jpg") if artist != "Unknown artist" and not os.path.exists(art_file): art_search = AlbumArtDownloader(title, artist, self.config.ALBUM_ART_DIR, self._update_albumart) art_search.start() except cdrom.error: # No disc in drive self.has_disc = False no_disc = Label(0.05, "title", 0.5, 0.5, _("No audio disc in drive")) no_disc.set_anchor_point_from_gravity(clutter.GRAVITY_CENTER) self.add(no_disc) # Remove loading animation self.throbber.hide() self.remove(self.throbber) del self.throbber # This function should be called only once (gobject timeout) return False
def _lyrics_search_callback(self, lyrics_text): '''This function is called when lyrics search is over.''' self.throbber.hide() # Save the results to help determine if the tab can activate. self.lyrics_text = lyrics_text if lyrics_text == "": no_lyrics = Label(0.037, "title", 0.7, 0.5, _("No lyrics found for this track")) no_lyrics.set_anchor_point_from_gravity(clutter.GRAVITY_CENTER) self.add(no_lyrics) else: lyrics = Label(0.037, "subtitle", 0, 0, lyrics_text) lyrics.set_line_wrap_mode(pango.WRAP_WORD) lyrics.width = 0.366 self.lyrics_area = ScrollArea(0.5, 0.23, 0.4, 0.57, lyrics) self.lyrics_area.connect("activated", self._on_activated) self.add(self.lyrics_area) self.library.save_lyrics(self.track, lyrics_text)
def __init__(self): Screen.__init__(self, 'Weather') # Screen Title self.add(Label(0.13, "screentitle", 0, 0.87, _("Weather"))) self.weather = Weather(self.config.weather_location) location = Label(0.04167, "text", 0.50, 0.13, self.weather.location, font_weight="bold") location.set_anchor_point_from_gravity(clutter.GRAVITY_CENTER) self.add(location) # Show today's weather self.create_day(self.weather.forecasts[0], 0.1, 0.15) # Show tomorrow's weather self.create_day(self.weather.forecasts[1], 0.1, 0.5) # Show day 3 self.create_day(self.weather.forecasts[2], 0.4, 0.5) # Show day 4 self.create_day(self.weather.forecasts[3], 0.7, 0.5)
class ListIndicator(Base, clutter.Group): """ ListIndicator displays 'current / maximum' value label and arrows. """ # Direction # HORIZONTAL layout: ARROW_LEFT current / maximum ARROW_RIGHT # VERITCAL layout: current / maximum ARROW_UP ARROW_DOWN HORIZONTAL = 0 VERTICAL = 1 def __init__(self, x, y, width, height, direction): Base.__init__(self) clutter.Group.__init__(self) self.config = Configuration() # Size self.width = self.get_abs_x(width) self.height = self.get_abs_y(height) self.direction = direction self.delimiter = " | " self.current = 1 self.maximum = 1 self.theme = self.config.theme self.fg = self.theme.get_color("arrow_foreground") self.bg = self.theme.get_color("arrow_background") if direction == ListIndicator.VERTICAL: text_x_pos = width / 3 else: text_x_pos = width / 2 self.text = Label( height * 0.8, "text", text_x_pos, height / 2, str(self.maximum) + self.delimiter + str(self.maximum)) self.text.set_anchor_point_from_gravity(clutter.GRAVITY_CENTER) self.add(self.text) # Create arrows and calculate positions on screen if direction == ListIndicator.VERTICAL: self.arrow1 = ArrowTexture(5 * width / 7, height / 2, height / 2, self.fg, self.bg, ArrowTexture.UP) self.arrow2 = ArrowTexture(6 * width / 7, height / 2, height / 2, self.fg, self.bg, ArrowTexture.DOWN) elif direction == ListIndicator.HORIZONTAL: self.arrow1 = ArrowTexture(height / 2, height / 2, height / 2, self.fg, self.bg, ArrowTexture.LEFT) self.arrow2 = ArrowTexture(6 * width / 7, height / 2, height / 2, self.fg, self.bg, ArrowTexture.RIGHT) self.add(self.arrow1) self.add(self.arrow2) self.set_position(self.get_abs_x(x), self.get_abs_y(y)) def set_current(self, value): """ Set current value @param number: Current value (between 1 - maximum) """ if value > 0 and value <= self.maximum: self.current = value self._update_text() # Bounce arrow if user has reached the limit if self.current == 1: self.arrow1.bounce() elif self.current == self.maximum: self.arrow2.bounce() def get_current(self): """ Get current value @return Current value (integer) """ return self.current def set_maximum(self, value): """ Set maximum value of the indicator @param number: Set maximum value """ self.maximum = value self._update_text() def get_maximum(self): """ Get maximum value. @return Max value (integer) """ return self.maximum def set_delimiter(self, delimiter): """ Set delimiter text that is displayed between current and maximum value. Default delimiter text is ' / ' spaces included. @param delimiter: delimiter text """ self.delimiter = delimiter self._update_text() def show_position(self): """ Show position text that indicates the current position of the content. """ self.text.show() def hide_position(self): """ Hide position text that indicates the current position of the content. If this is called then indicator shows only arrows. """ self.text.hide() def _update_text(self): """Update the text label""" self.text.set_text( str(self.current) + self.delimiter + str(self.maximum))
class ListIndicator(Base, clutter.Group): """ ListIndicator displays 'current / maximum' value label and arrows. """ # Direction # HORIZONTAL layout: ARROW_LEFT current / maximum ARROW_RIGHT # VERITCAL layout: current / maximum ARROW_UP ARROW_DOWN HORIZONTAL = 0 VERTICAL = 1 def __init__(self, x, y, width, height, direction): Base.__init__(self) clutter.Group.__init__(self) self.config = Configuration() # Size self.width = self.get_abs_x(width) self.height = self.get_abs_y(height) self.direction = direction self.delimiter = " | " self.current = 1 self.maximum = 1 self.theme = self.config.theme self.fg = self.theme.get_color("arrow_foreground") self.bg = self.theme.get_color("arrow_background") if direction == ListIndicator.VERTICAL: text_x_pos = width / 3 else: text_x_pos = width / 2 self.text = Label(height * 0.8, "text", text_x_pos, height / 2, str(self.maximum) + self.delimiter + str(self.maximum)) self.text.set_anchor_point_from_gravity(clutter.GRAVITY_CENTER) self.add(self.text) # Create arrows and calculate positions on screen if direction == ListIndicator.VERTICAL: self.arrow1 = ArrowTexture(5 * width / 7, height / 2, height / 2, self.fg, self.bg, ArrowTexture.UP) self.arrow2 = ArrowTexture(6 * width / 7, height / 2, height / 2, self.fg, self.bg, ArrowTexture.DOWN) elif direction == ListIndicator.HORIZONTAL: self.arrow1 = ArrowTexture(height / 2, height / 2, height / 2, self.fg, self.bg, ArrowTexture.LEFT) self.arrow2 = ArrowTexture(6 * width / 7, height / 2, height / 2, self.fg, self.bg, ArrowTexture.RIGHT) self.add(self.arrow1) self.add(self.arrow2) self.set_position(self.get_abs_x(x), self.get_abs_y(y)) def set_current(self, value): """ Set current value @param number: Current value (between 1 - maximum) """ if value > 0 and value <= self.maximum: self.current = value self._update_text() # Bounce arrow if user has reached the limit if self.current == 1: self.arrow1.bounce() elif self.current == self.maximum: self.arrow2.bounce() def get_current(self): """ Get current value @return Current value (integer) """ return self.current def set_maximum(self, value): """ Set maximum value of the indicator @param number: Set maximum value """ self.maximum = value self._update_text() def get_maximum(self): """ Get maximum value. @return Max value (integer) """ return self.maximum def set_delimiter(self, delimiter): """ Set delimiter text that is displayed between current and maximum value. Default delimiter text is ' / ' spaces included. @param delimiter: delimiter text """ self.delimiter = delimiter self._update_text() def show_position(self): """ Show position text that indicates the current position of the content. """ self.text.show() def hide_position(self): """ Hide position text that indicates the current position of the content. If this is called then indicator shows only arrows. """ self.text.hide() def _update_text(self): """Update the text label""" self.text.set_text( str(self.current) + self.delimiter + str(self.maximum))