def _add_tracks(self, tracks, widget, pos, previous_album_id=None):
        """
            Add tracks to list
            @param tracks id as array of [int]
            @param widget TracksWidget
            @param track position as int
            @param pos as int
            @param previous album id as int
        """
        if self._loading == Loading.STOP:
            self._loading = Loading.NONE
            return
        if not tracks:
            if widget == self._tracks_widget_right:
                self._loading |= Loading.RIGHT
            elif widget == self._tracks_widget_left:
                self._loading |= Loading.LEFT
            if self._loading == Loading.ALL:
                self.emit('populated')
            self._locked_widget_right = False
            return

        track = Track(tracks.pop(0))
        row = PlaylistRow(track.id, pos,
                          track.album.id != previous_album_id)
        row.connect('track-moved', self._on_track_moved)
        row.show()
        widget.insert(row, pos)
        GLib.idle_add(self._add_tracks, tracks, widget,
                      pos + 1, track.album.id)
    def __add_tracks(self, tracks, widget, pos, previous_album_id=None):
        """
            Add tracks to list
            @param tracks id as array of [int]
            @param widget TracksWidget
            @param track position as int
            @param pos as int
            @param previous album id as int
        """
        if self.__loading == Loading.STOP:
            self.__loading = Loading.NONE
            return
        if not tracks:
            if widget == self.__tracks_widget_right:
                self.__loading |= Loading.RIGHT
            elif widget == self.__tracks_widget_left:
                self.__loading |= Loading.LEFT
            if self.__loading == Loading.ALL:
                self.emit("populated")
            self.__locked_widget_right = False
            return

        track = Track(tracks.pop(0))
        row = PlaylistRow(track.id, pos, track.album.id != previous_album_id)
        row.connect("track-moved", self.__on_track_moved)
        row.show()
        widget.insert(row, pos)
        GLib.idle_add(self.__add_tracks, tracks, widget, pos + 1,
                      track.album.id)
Exemple #3
0
    def _add_tracks(self, tracks, widget, pos, previous_album_id=None):
        """
            Add tracks to list
            @param tracks id as array of [int]
            @param widget TracksWidget
            @param track position as int
            @param pos as int
            @param previous album id as int
        """
        if not tracks or self._stop:
            if widget == self._tracks_widget_right:
                self._stop = False
            else:
                self._locked_widget2 = False
            return

        track = Track(tracks.pop(0))
        row = PlaylistRow(track.id, pos,
                          track.album.id != previous_album_id)
        row.connect('track-moved', self._on_track_moved)
        row.show()
        widget.insert(row, pos)
        GLib.idle_add(self._add_tracks, tracks, widget,
                      pos + 1, track.album.id)
    def _add_tracks(self, tracks, widget, pos, previous_album_id=None):
        """
            Add tracks to list
            @param tracks id as array of [int]
            @param widget TracksWidget
            @param track position as int
            @param pos as int
            @param previous album id as int
        """
        if not tracks or self._stop:
            if widget == self._tracks_widget_right:
                self._stop = False
            else:
                self._locked_widget2 = False
            return

        track = Track(tracks.pop(0))
        row = PlaylistRow(track.id, pos, track.album.id != previous_album_id)
        row.connect('track-moved', self._on_track_moved)
        row.show()
        widget.insert(row, pos)
        GLib.idle_add(self._add_tracks, tracks, widget, pos + 1,
                      track.album.id)
Exemple #5
0
 def _move_track(self, dst, src, up):
     """
         Move track from src to row
         @param dst as int
         @param src as int
         @param up as bool
         @return (dst_widget as TracksWidget,
                  src index as int, dst index as int)
     """
     tracks1_len = len(self._tracks1)
     tracks2_len = len(self._tracks2)
     if src in self._tracks1:
         src_widget = self._tracks_widget_left
         src_index = self._tracks1.index(src) - 1
     else:
         src_widget = self._tracks_widget_right
         src_index = self._tracks2.index(src) - 1
     if tracks1_len == 0 or dst in self._tracks1:
         dst_widget = self._tracks_widget_left
         dst_tracks = self._tracks1
     elif tracks2_len == 0 or dst in self._tracks2:
         dst_widget = self._tracks_widget_right
         dst_tracks = self._tracks2
     else:
         return
     # Remove src from src_widget
     for child in src_widget.get_children():
         if child.get_id() == src:
             child.destroy()
             break
     src_track = Track(src)
     prev_track = Track()
     name = escape(src_track.name)
     index = 0
     # Get previous track
     if dst != -1:
         for child in dst_widget.get_children():
             if child.get_id() == dst:
                 break
             index += 1
         if not up:
             index += 1
         # Get previous track (in dst context)
         prev_index = dst_tracks.index(dst)
         if up:
             prev_index -= 1
         prev_track = Track(dst_tracks[prev_index])
         # If we are listening to a compilation, prepend artist name
         if (src_track.album.artist_id == Type.COMPILATIONS or
                 len(src_track.artist_ids) > 1 or
                 src_track.album.artist_id not in src_track.artist_ids):
             name = "<b>%s</b>\n%s" % (escape(", ".join(src_track.artists)),
                                       name)
         self._tracks1.insert(index, src_track.id)
     row = PlaylistRow(src_track.id,
                       index,
                       index == 0 or
                       src_track.album.id != prev_track.album.id)
     row.connect('track-moved', self._on_track_moved)
     row.show()
     dst_widget.insert(row, index)
     return (src_widget, dst_widget, src_index, index)
 def _move_track(self, dst, src, up):
     """
         Move track from src to row
         @param dst as int
         @param src as int
         @param up as bool
         @return (dst_widget as TracksWidget,
                  src index as int, dst index as int)
     """
     tracks1_len = len(self._tracks1)
     tracks2_len = len(self._tracks2)
     if src in self._tracks1:
         src_widget = self._tracks_widget_left
         src_index = self._tracks1.index(src) - 1
     else:
         src_widget = self._tracks_widget_right
         src_index = self._tracks2.index(src) - 1
     if tracks1_len == 0 or dst in self._tracks1:
         dst_widget = self._tracks_widget_left
         dst_tracks = self._tracks1
     elif tracks2_len == 0 or dst in self._tracks2:
         dst_widget = self._tracks_widget_right
         dst_tracks = self._tracks2
     else:
         return
     # Remove src from src_widget
     for child in src_widget.get_children():
         if child.get_id() == src:
             child.destroy()
             break
     src_track = Track(src)
     prev_track = Track()
     name = escape(src_track.name)
     index = 0
     # Get previous track
     if dst != -1:
         for child in dst_widget.get_children():
             if child.get_id() == dst:
                 break
             index += 1
         if not up:
             index += 1
         # Get previous track (in dst context)
         prev_index = dst_tracks.index(dst)
         if up:
             prev_index -= 1
         prev_track = Track(dst_tracks[prev_index])
         # If we are listening to a compilation, prepend artist name
         if (src_track.album.artist_id == Type.COMPILATIONS
                 or len(src_track.artist_ids) > 1
                 or src_track.album.artist_id not in src_track.artist_ids):
             name = "<b>%s</b>\n%s" % (escape(", ".join(
                 src_track.artists)), name)
         self._tracks1.insert(index, src_track.id)
     row = PlaylistRow(
         src_track.id, index, index == 0
         or src_track.album.id != prev_track.album.id)
     row.connect('track-moved', self._on_track_moved)
     row.show()
     dst_widget.insert(row, index)
     return (src_widget, dst_widget, src_index, index)