Beispiel #1
0
 def _get_child(self, album):
     """
         Get an album view widget
         @param album as Album
         @return AlbumRow
     """
     if self.destroyed:
         return None
     row = AlbumRow(album, self.__height, self.view_type)
     row.connect("activated", self._on_row_activated)
     row.connect("destroy", self._on_row_destroy)
     row.connect("track-removed", self._on_track_removed)
     row.show()
     self._box.add(row)
     return row
Beispiel #2
0
 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")]
Beispiel #3
0
 def __split_album_row(self, album_row, track_row, direction):
     """
         Split album row at track row with direction
         @param album_row as AlbumRow
         @param track_row as TrackRow
         @param direction as Gtk.DirectionType
         @return AlbumRow
     """
     height = AlbumRow.get_best_height(album_row)
     children = album_row.children
     index = children.index(track_row)
     if direction == Gtk.DirectionType.DOWN:
         index += 1
         if index + 1 > len(children):
             return None
     elif index - 1 < 0:
         return None
     rows = album_row.children[:index]
     split_album = Album(album_row.album.id)
     split_album.set_tracks([row.track for row in rows])
     split_album_row = AlbumRow(split_album, height, self.__view_type)
     split_album_row.reveal()
     split_album_row.show()
     for row in rows:
         empty = album_row.album.remove_track(row.track)
         if empty:
             album_row.destroy()
         row.destroy()
     return split_album_row
Beispiel #4
0
 def __do_drag_and_drop(self, src_rows, dest_row, direction):
     """
         Drag source rows at destination row with direction
         @param src_rows as [Row]
         @param dest_row as Row
         @param direction as Gtk.DirectionType
     """
     indexes = []
     # Build new rows
     new_rows = self.__get_rows_from_rows(
         src_rows, AlbumRow.get_best_height(dest_row))
     # Insert new rows
     if isinstance(dest_row, TrackRow):
         album_row = dest_row.get_ancestor(AlbumRow)
         if album_row is None:
             return
         # Destroy src_rows from album before split
         for row in src_rows:
             if isinstance(row, TrackRow):
                 if row.get_ancestor(AlbumRow) == album_row:
                     album_row.tracks_view.remove_row(row.track)
         indexes.append(album_row.get_index())
         split_album_row = self.__split_album_row(album_row, dest_row,
                                                  direction)
         index = album_row.get_index()
         if split_album_row is not None:
             self.emit("dnd-insert", split_album_row, index)
             index += 1
         elif direction == Gtk.DirectionType.DOWN:
             index += 1
         for row in new_rows:
             self.emit("dnd-insert", row, index)
             index += 1
     else:
         index = dest_row.get_index()
         indexes.append(index)
         if direction == Gtk.DirectionType.DOWN:
             index += 1
         for row in new_rows:
             self.emit("dnd-insert", row, index)
             index += 1
     # Calculate update range
     for row in src_rows:
         if isinstance(row, TrackRow):
             album_row = row.get_ancestor(AlbumRow)
             if album_row is not None:
                 indexes.append(album_row.get_index())
         else:
             indexes.append(row.get_index())
     self.__destroy_rows(src_rows)
     self.__update_album_rows(max(0, min(indexes) - 1), max(indexes) + 1)
Beispiel #5
0
 def __get_rows_from_rows(self, rows, height):
     """
         Build news rows from rows
         @param rows as [TrackRow/AlbumRow]
         @param height as int
         @return [AlbumRow]
     """
     new_rows = []
     for row in rows:
         if isinstance(row, TrackRow):
             # Merge with previous
             if new_rows and new_rows[-1].album.id == row.track.album.id:
                 new_rows[-1].tracks_view.append_row(row.track)
             # Create a new album
             else:
                 new_album = Album(row.track.album.id)
                 new_album.set_tracks([row.track])
                 new_album_row = AlbumRow(new_album, height,
                                          self.__view_type)
                 new_album_row.show()
                 new_album_row.reveal()
                 new_rows.append(new_album_row)
         else:
             # Merge with previous
             if new_rows and new_rows[-1].album.id == row.album.id:
                 new_rows[-1].tracks_view.append_rows(row.album.tracks)
             # Create a new album
             else:
                 new_album = Album(row.album.id)
                 new_album.set_tracks(row.album.tracks)
                 new_album_row = AlbumRow(new_album, height,
                                          self.__view_type)
                 new_album_row.populate()
                 new_album_row.show()
                 new_rows.append(new_album_row)
     return new_rows