class TopBar(gtk.HBox): def __init__(self, parent, player, library): super(TopBar, self).__init__(spacing=3) # play controls t = PlayControls(player, library.librarian) self.volume = t.volume self.pack_start(t, expand=False, fill=False) # song text text = SongInfo(library.librarian, player) self.pack_start(Alignment(text, border=3)) # cover image self.image = CoverImage(resize=True) player.connect('song-started', lambda x, s: self.image.set_song(s)) parent.connect('artwork-changed', self.__song_art_changed, library) self.pack_start(self.image, expand=False) def __song_art_changed(self, player, songs, library): self.image.refresh() refresh_albums = [] for song in songs: # Album browser only (currently): album = library.albums.get(song.album_key, None) if album: album.scan_cover(force=True) refresh_albums.append(album) if refresh_albums: library.albums.refresh(refresh_albums)
class TopBar(Gtk.Toolbar): def __init__(self, parent, player, library): super(TopBar, self).__init__() # play controls control_item = Gtk.ToolItem() self.insert(control_item, 0) t = PlayControls(player, library.librarian) self.volume = t.volume control_item.add(t) self.insert(Gtk.SeparatorToolItem(), 1) info_item = Gtk.ToolItem() self.insert(info_item, 2) info_item.set_expand(True) box = Gtk.Box(spacing=6) info_item.add(box) qltk.add_css(self, "GtkToolbar {padding: 3px;}") # song text info_pattern_path = os.path.join(const.USERDIR, "songinfo") text = SongInfo(library.librarian, player, info_pattern_path) box.pack_start(Align(text, border=3), True, True, 0) # cover image self.image = CoverImage(resize=True) connect_destroy(player, 'song-started', self.__new_song) # FIXME: makes testing easier if app.cover_manager: connect_destroy( app.cover_manager, 'cover-changed', self.__song_art_changed, library) self.image.props.margin = 2 box.pack_start(self.image, False, True, 0) for child in self.get_children(): child.show_all() context = self.get_style_context() context.add_class("primary-toolbar") def __new_song(self, player, song): self.image.set_song(song) def __song_art_changed(self, player, songs, library): self.image.refresh() refresh_albums = [] for song in songs: # Album browser only (currently): album = library.albums.get(song.album_key, None) if album: album.scan_cover(force=True) refresh_albums.append(album) if refresh_albums: library.albums.refresh(refresh_albums)
class TopBar(Gtk.Toolbar): def __init__(self, parent, player, library): super(TopBar, self).__init__() # play controls control_item = Gtk.ToolItem() self.insert(control_item, 0) t = PlayControls(player, library.librarian) self.volume = t.volume control_item.add(t) self.insert(Gtk.SeparatorToolItem(), 1) info_item = Gtk.ToolItem() self.insert(info_item, 2) info_item.set_expand(True) box = Gtk.Box(spacing=6) info_item.add(box) qltk.add_css(self, "GtkToolbar {padding: 3px;}") # song text text = SongInfo(library.librarian, player) box.pack_start(Alignment(text, border=3), True, True, 0) # cover image self.image = CoverImage(resize=True) gobject_weak(player.connect, 'song-started', self.__new_song, parent=self) gobject_weak(parent.connect, 'artwork-changed', self.__song_art_changed, library, parent=self) # CoverImage doesn't behave in a Alignment, so wrap it coverbox = Gtk.Box() coverbox.pack_start(self.image, True, True, 0) box.pack_start(Alignment(coverbox, border=2), False, True, 0) for child in self.get_children(): child.show_all() context = self.get_style_context() context.add_class("primary-toolbar") def __new_song(self, player, song): self.image.set_song(song) def __song_art_changed(self, player, songs, library): self.image.refresh() refresh_albums = [] for song in songs: # Album browser only (currently): album = library.albums.get(song.album_key, None) if album: album.scan_cover(force=True) refresh_albums.append(album) if refresh_albums: library.albums.refresh(refresh_albums)
class TopBar(Gtk.Toolbar): def __init__(self, parent, player, library): super(TopBar, self).__init__() # play controls control_item = Gtk.ToolItem() self.insert(control_item, 0) t = PlayControls(player, library.librarian) self.volume = t.volume # only restore the volume in case it is managed locally, otherwise # this could affect the system volume if not player.has_external_volume: player.volume = config.getfloat("memory", "volume") self.volume.connect("value-changed", self._on_volume_changed) control_item.add(t) self.insert(Gtk.SeparatorToolItem(), 1) info_item = Gtk.ToolItem() self.insert(info_item, 2) info_item.set_expand(True) box = Gtk.Box(spacing=6) info_item.add(box) qltk.add_css(self, "GtkToolbar {padding: 3px;}") # song text info_pattern_path = os.path.join(quodlibet.get_user_dir(), "songinfo") text = SongInfo(library.librarian, player, info_pattern_path) box.pack_start(Align(text, border=3), True, True, 0) # cover image self.image = CoverImage(resize=True) connect_destroy(player, 'song-started', self.__new_song) # FIXME: makes testing easier if app.cover_manager: connect_destroy(app.cover_manager, 'cover-changed', self.__song_art_changed, library) box.pack_start(Align(self.image, border=2), False, True, 0) # On older Gtk+ (3.4, at least) # setting a margin on CoverImage leads to errors and result in the # QL window not beeing visible for some reason. assert self.image.props.margin == 0 for child in self.get_children(): child.show_all() context = self.get_style_context() context.add_class("primary-toolbar") def _on_volume_changed(self, widget, value): config.set("memory", "volume", str(value)) def __new_song(self, player, song): self.image.set_song(song) def __song_art_changed(self, player, songs, library): self.image.refresh() refresh_albums = [] for song in songs: # Album browser only (currently): album = library.albums.get(song.album_key, None) if album: album.scan_cover(force=True) refresh_albums.append(album) if refresh_albums: library.albums.refresh(refresh_albums)
class TopBar(Gtk.Toolbar): def __init__(self, parent, player, library): super(TopBar, self).__init__() # play controls control_item = Gtk.ToolItem() self.insert(control_item, 0) t = PlayControls(player, library.librarian) self.volume = t.volume # only restore the volume in case it is managed locally, otherwise # this could affect the system volume if not player.has_external_volume: player.volume = config.getfloat("memory", "volume") self.volume.connect("value-changed", self._on_volume_changed) control_item.add(t) self.insert(Gtk.SeparatorToolItem(), 1) info_item = Gtk.ToolItem() self.insert(info_item, 2) info_item.set_expand(True) box = Gtk.Box(spacing=6) info_item.add(box) qltk.add_css(self, "GtkToolbar {padding: 3px;}") # song text info_pattern_path = os.path.join(quodlibet.get_user_dir(), "songinfo") text = SongInfo(library.librarian, player, info_pattern_path) box.pack_start(Align(text, border=3), True, True, 0) # cover image self.image = CoverImage(resize=True) connect_destroy(player, 'song-started', self.__new_song) # FIXME: makes testing easier if app.cover_manager: connect_destroy( app.cover_manager, 'cover-changed', self.__song_art_changed, library) box.pack_start(Align(self.image, border=2), False, True, 0) # On older Gtk+ (3.4, at least) # setting a margin on CoverImage leads to errors and result in the # QL window not beeing visible for some reason. assert self.image.props.margin == 0 for child in self.get_children(): child.show_all() context = self.get_style_context() context.add_class("primary-toolbar") def _on_volume_changed(self, widget, value): config.set("memory", "volume", str(value)) def __new_song(self, player, song): self.image.set_song(song) def __song_art_changed(self, player, songs, library): self.image.refresh() refresh_albums = [] for song in songs: # Album browser only (currently): album = library.albums.get(song.album_key, None) if album: album.scan_cover(force=True) refresh_albums.append(album) if refresh_albums: library.albums.refresh(refresh_albums)