def __init__(self, genre_ids, artist_ids, view_type): """ Init widget @param genre_ids as int @param artist_ids as int @param view_type as ViewType """ LazyLoadingView.__init__(self, StorageType.ALL, view_type) self.__genre_ids = genre_ids self.__artist_ids = artist_ids self.__reveals = [] # Calculate default album height based on current pango context # We may need to listen to screen changes self.__height = AlbumRow.get_best_height(self) self._box = ListBox() self._box.set_margin_bottom(MARGIN) self._box.set_margin_end(MARGIN) self._box.get_style_context().add_class("trackswidget") self._box.set_vexpand(True) self._box.set_selection_mode(Gtk.SelectionMode.NONE) self._box.show() GesturesHelper.__init__(self, self._box) if view_type & ViewType.DND: from lollypop.helper_dnd import DNDHelper self.__dnd_helper = DNDHelper(self._box, view_type) self.__dnd_helper.connect("dnd-insert", self.__on_dnd_insert) return [(App().player, "current-changed", "_on_current_changed"), (App().player, "duration-changed", "_on_duration_changed"), (App().art, "album-artwork-changed", "_on_artwork_changed")]
def __init__(self, album, storage_type, view_type): """ Init ArtistView @param album as Album @param storage_type as StorageType @param view_type as ViewType """ LazyLoadingView.__init__(self, storage_type, view_type) self.__tracks_view = None self.__album = album self.__others_boxes = [] self.__grid = Gtk.Grid() self.__grid.show() self.__grid.set_row_spacing(10) self.__grid.set_orientation(Gtk.Orientation.VERTICAL) self.__banner = AlbumBannerWidget(self.__album, self.storage_type, self.view_type) self.__banner.show() self.add_widget(self.__grid, self.__banner) return [ (App().scanner, "scan-finished", "_on_scan_finished"), (App().scanner, "updated", "_on_collection_updated"), (App().player, "current-changed", "_on_current_changed"), (App().player, "duration-changed", "_on_duration_changed"), ]
def _handle_width_allocate(self, allocation): """ Update artwork @param allocation as Gtk.Allocation @return bool """ if SizeAllocationHelper._handle_width_allocate(self, allocation): if allocation.width != self.__width: self.__width = allocation.width boxes_count = self.__width // self.__column_width if boxes_count < 1: boxes_count = 1 if self.__boxes_count == boxes_count: return # Rework content if self.is_populated: children = self.__get_children_sorted() self.__remove_children() self.__boxes_count = boxes_count self.__populate(children) else: self.__boxes_count = boxes_count album_ids = App().albums.get_ids(self.__genre_ids, self.__artist_ids, self.storage_type, True) self.__albums_count = len(album_ids) LazyLoadingView.populate(self, album_ids) return True return False
def __init__(self, base_mask): """ Init Selection list ui @param base_mask as SelectionListMask """ LazyLoadingView.__init__(self, StorageType.ALL, ViewType.DEFAULT) self.__selection_pending_ids = [] self.__base_mask = base_mask self.__mask = SelectionListMask.NONE self.__animation_timeout_id = None self.__height = SelectionListRow.get_best_height(self) self._box = Gtk.ListBox() self._box.set_selection_mode(Gtk.SelectionMode.MULTIPLE) self._box.show() GesturesHelper.__init__(self, self._box) self.__scrolled = Gtk.ScrolledWindow() self.__scrolled.show() self.__scrolled.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC) self.__viewport = Gtk.Viewport() self.__scrolled.add(self.__viewport) self.__viewport.show() self.__viewport.add(self._box) self.connect("initialized", self.__on_initialized) self.get_style_context().add_class("sidebar") self.__scrolled.set_vexpand(True) if base_mask & SelectionListMask.FASTSCROLL: self.__overlay = Gtk.Overlay.new() self.__overlay.show() self.__overlay.add(self.__scrolled) self.__fastscroll = FastScroll(self._box, self.__scrolled) self.__overlay.add_overlay(self.__fastscroll) self.add(self.__overlay) App().settings.connect("changed::artist-artwork", self.__on_artist_artwork_changed) App().art.connect("artist-artwork-changed", self.__on_artist_artwork_changed) else: self.__overlay = None App().settings.connect("changed::show-sidebar-labels", self.__on_show_sidebar_labels_changed) self.add(self.__scrolled) self.__menu_button = Gtk.Button.new_from_icon_name( "view-more-horizontal-symbolic", Gtk.IconSize.BUTTON) self.__menu_button.set_property("halign", Gtk.Align.CENTER) self.__menu_button.get_style_context().add_class("no-border") self.__menu_button.connect("clicked", lambda x: self.__popup_menu(None, x)) self.__menu_button.show() self.add(self.__menu_button) if base_mask & SelectionListMask.SIDEBAR: App().window.container.widget.connect("notify::folded", self.__on_container_folded) self.__on_container_folded(None, App().window.folded) else: self.__base_mask |= SelectionListMask.LABEL self.__base_mask |= SelectionListMask.ELLIPSIZE self.__set_rows_mask(self.__base_mask | self.__mask)
def populate(self, albums): """ Populate widget with album rows @param albums as [Album] """ for child in self._box.get_children(): self._box.remove(child) LazyLoadingView.populate(self, albums)
def populate(self, values): """ Populate view with values @param [(int, str, optional str)], will be deleted """ self._box.set_sort_func(None) self.__scrolled.get_vadjustment().set_value(0) self.clear() LazyLoadingView.populate(self, values)
def populate(self): """ Populate list """ album_ids = App().albums.get_ids(self.__genre_ids, self.__artist_ids, self.storage_type, True) LazyLoadingView.populate(self, album_ids)
def _on_populated(self, widget): """ Add another album/disc @param widget as AlbumWidget/TracksView """ if widget.album in self.__reveals: widget.reveal() self.__reveals.remove(widget.album) else: LazyLoadingView._on_populated(self, widget)
def add_value(self, album): """ Insert item @param album as Album """ # Merge album if previous is same if self.children and self.children[-1].album.id == album.id: track_ids = self.children[-1].album.track_ids for track in album.tracks: if track.id not in track_ids: self.children[-1].tracks_view.append_row(track) else: LazyLoadingView.populate(self, [album])
def __init__(self, genre_ids, artist_ids, storage_type, view_type): """ Init ArtistView @param genre_ids as [int] @param artist_ids as [int] @param storage_type as StorageType @param view_type as ViewType """ LazyLoadingView.__init__( self, storage_type, view_type | ViewType.OVERLAY | ViewType.ARTIST) self.__boxes = [] self.__others_boxes = [] self.__width = 0 self.__boxes_count = 0 self.__current_box = 0 self.__albums_count = 0 self.__hovered_child = None self.__genre_ids = genre_ids self.__artist_ids = artist_ids self.__storage_type = storage_type self.__banner = ArtistBannerWidget(genre_ids, artist_ids, storage_type, self.view_type) self.__banner.show() self.__main_grid = Gtk.Grid.new() self.__main_grid.show() self.__main_grid.set_orientation(Gtk.Orientation.VERTICAL) self.__boxes_grid = Gtk.Grid.new() self.__boxes_grid.show() self.__boxes_grid.set_valign(Gtk.Align.START) self.__boxes_grid.set_halign(Gtk.Align.CENTER) self.__main_grid.add(self.__boxes_grid) self.add_widget(self.__main_grid, self.__banner) self.connect("populated", self.__on_populated) if App().settings.get_value("force-single-column"): self.__column_width = 1200 else: self.__column_width = 600 if App().animations: self.__event_controller = Gtk.EventControllerMotion.new(self) self.__event_controller.connect("motion", self.__on_motion) SizeAllocationHelper.__init__(self)
def __init__(self, genre_ids, artist_ids, storage_type, view_type): """ Init ArtistView @param genre_ids as [int] @param artist_ids as [int] @param storage_type as StorageType @param view_type as ViewType """ LazyLoadingView.__init__(self, storage_type, view_type | ViewType.OVERLAY | ViewType.ARTIST) self.__others_boxes = [] self.__genre_ids = genre_ids self.__artist_ids = artist_ids self.__storage_type = storage_type self.__banner = ArtistBannerWidget(genre_ids, artist_ids, storage_type, self.view_type) self.__banner.show() self.__list = Gtk.Box.new(Gtk.Orientation.VERTICAL, MARGIN * 4) self.__list.show() self.add_widget(self.__list, self.__banner) self.connect("populated", self.__on_populated)