def _add_tracks(self, widget, tracks, position=0): """ Add tracks to widget @param widget as Gtk.ListBox @param tracks as [Track] """ for track in tracks: track.set_number(position + 1) row = TrackRow(track, [], self.view_type) row.show() widget.add(row) position += 1
def requested_height(self): """ Requested height: Internal tracks or at least cover @return (minimal: int, maximal: int) """ from lollypop.widgets_row_track import TrackRow track_height = TrackRow.get_best_height(self) minimal_height = maximal_height = track_height + 20 count = self._album.tracks_count mid_tracks = int(0.5 + count / 2) left_height = track_height * mid_tracks right_height = track_height * (count - mid_tracks) if left_height > right_height: minimal_height += left_height else: minimal_height += right_height maximal_height += left_height + right_height # Add height for disc label if len(self._album.discs) > 1: minimal_height += track_height maximal_height += track_height # 26 is for loved and rating cover_height = ArtSize.BIG + 26 if minimal_height < cover_height: return (cover_height, cover_height) else: return (minimal_height, maximal_height)
def _add_tracks(self, widget, tracks, position=0): """ Add tracks to widget @param widget as Gtk.ListBox @param tracks as [Track] """ for track in tracks: # If user does not want to show real tracknumber and we are # in album view, calculate a fake tracknumber if not self.__show_tag_tracknumber and\ self.view_type & (ViewType.ALBUM | ViewType.ARTIST): track.set_number(position + 1) row = TrackRow(track, self.__album.artist_ids, self.view_type) row.show() row.connect("removed", self.__on_track_row_removed) widget.add(row) position += 1
def requested_height(self): """ Requested height: Internal tracks @return (minimal: int, maximal: int) """ from lollypop.widgets_row_track import TrackRow track_height = TrackRow.get_best_height(self) # See Banner and row spacing minimal_height = maximal_height = ArtSize.BANNER + 40 + 2 count = len(self._album.tracks) mid_tracks = int(0.5 + count / 2) left_height = track_height * mid_tracks right_height = track_height * (count - mid_tracks) if left_height > right_height: minimal_height += left_height else: minimal_height += right_height maximal_height += left_height + right_height # Add height for disc label if len(self._album.discs) > 1: minimal_height += track_height maximal_height += track_height return (minimal_height, maximal_height)
def __on_insert_track(self, row, new_track_id, down): """ Insert a new row at position @param row as PlaylistRow @param new_track_id as int @param down as bool """ track = Track(new_track_id) # If same album, add track to album if track.album.id == row.track.album.id: position = self.children.index(row) new_row = TrackRow(track, track.album.artist_ids, self._view_type) new_row.connect("destroy", self.__on_row_destroy) new_row.connect("insert-track", self.__on_insert_track) new_row.connect("insert-album", self.__on_insert_album) new_row.connect("remove-track", self.__on_remove_track) new_row.connect("do-selection", self.__on_do_selection) new_row.show() if down: position += 1 new_row.set_previous_row(row) new_row.set_next_row(row.next_row) if row.next_row is not None: row.next_row.set_previous_row(new_row) row.set_next_row(new_row) else: new_row.set_previous_row(row.previous_row) new_row.set_next_row(row) if row.previous_row is not None: row.previous_row.set_next_row(new_row) row.set_previous_row(new_row) new_row.update_number(position + 1) row.get_parent().insert(new_row, position) row.track.album.insert_track(track, position) if new_row.previous_row is not None and\ new_row.previous_row.track.id ==\ App().player.current_track.id: App().player.set_next() App().player.set_prev() # Else, we need to insert a new album with the track else: # Backup album as __destroy_split() will unset it album = row.track.album split_album = Album(album.id) split_tracks = self.__get_split_tracks(row, down) # Create new album track.album.set_tracks([track]) # We use DNDRow because we know that if tracks are DND # we are DND. Little hack if len(self.children) == len(split_tracks): if self.previous_row is not None: album = self.previous_row.album else: album = Album() elif not split_tracks: if self.next_row is not None: album = self.next_row.album else: album = Album() if album.id == track.album.id: track.set_album(album) if down: self.next_row.prepend_rows([track]) else: self.previous_row.append_rows([track]) else: self.emit("insert-album-after", album, track.album) # Create split album if split_tracks: split_album.set_tracks(split_tracks) if album.id == track.album.id: self.emit("insert-album-after", album, split_album) else: self.emit("insert-album-after", track.album, split_album) self.__destroy_split(row, down)
def __add_tracks(self, widgets, disc_number, previous_row=None): """ Add tracks for to tracks widget @param widgets as OrderedDict @param disc number as int @param previous_row as TrackRow """ if self.__cancellable.is_cancelled(): return widget = next(iter(widgets)) widgets.move_to_end(widget) tracks = widgets[widget] if not tracks: if len(self.__discs_to_load) == 0: self.__populated = True self._on_tracks_populated(disc_number) self._tracks_widget_left[disc_number].show() self._tracks_widget_right[disc_number].show() if self._view_type & ViewType.DND: self.__linking() return (track, position) = tracks.pop(0) if not App().settings.get_value("show-tag-tracknumber"): track.set_number(position + 1) row = TrackRow(track, self._album.artist_ids, self._view_type) if self._view_type & ViewType.DND: row.set_previous_row(previous_row) if previous_row is not None: previous_row.set_next_row(row) row.connect("destroy", self.__on_row_destroy) row.connect("insert-track", self.__on_insert_track) row.connect("insert-album", self.__on_insert_album) row.connect("remove-track", self.__on_remove_track) row.connect("do-selection", self.__on_do_selection) row.show() widget.insert(row, position) GLib.idle_add(self.__add_tracks, widgets, disc_number, row)