def onStopped(self): """ Playback has been stopped """ if self.list.hasMark(): currTrack = self.list.getMark() if self.list.getItem(currTrack, ROW_ICO) != icons.errorMenuIcon(): self.list.setItem(currTrack, ROW_ICO, icons.nullMenuIcon()) self.list.clearMark()
def set_track_playing(self, iter, playing): if not iter: return track = self.tree.getTrack(iter) if not track: return for parent in self.tree.get_all_parents(iter): parent_label = self.tree.getLabel(parent) parent_label = tools.htmlUnescape(parent_label) is_bold = parent_label.startswith('<b>') and parent_label.endswith('</b>') if playing and not is_bold: parent_label = tools.htmlEscape(parent_label) self.tree.setLabel(parent, '<b>%s</b>' % parent_label) elif not playing and is_bold: parent_label = tools.htmlEscape(parent_label[3:-4]) self.tree.setLabel(parent, parent_label) parent = self.tree.store.iter_parent(iter) parent_label = self.tree.getLabel(parent) if parent else None label = track.get_label(parent_label=parent_label, playing=playing) if playing: self.tree.setLabel(iter, label) self.tree.setItem(iter, ROW_ICO, icons.playMenuIcon()) self.tree.expand(iter) else: self.tree.setLabel(iter, label) icon = self.tree.getItem(iter, ROW_ICO) has_error = (icon == icons.errorMenuIcon()) is_dir = (icon == icons.mediaDirMenuIcon()) if not is_dir and not has_error: self.tree.setItem(iter, ROW_ICO, icons.nullMenuIcon())
def __getPreviousTrackIter(self): """ Return the index of the previous track, or -1 if there is none """ prev = None while True: prev = self.tree.get_prev_iter(prev) if not prev: return None # Check track error = self.tree.getItem(prev, ROW_ICO) == icons.errorMenuIcon() track = self.tree.getItem(prev, ROW_TRK) if track and not error: # Row is not a directory return prev
def __getNextTrackIter(self): """ Return the index of the next track, or -1 if there is none """ next = None while True: next = self.tree.get_next_iter(next) if not next: return None # Check track error = self.tree.getItem(next, ROW_ICO) == icons.errorMenuIcon() track = self.tree.getItem(next, ROW_TRK) if track and not error: # Row is not a directory return next
def onTrackEnded(self, withError): """ The current track has ended, jump to the next one if any """ currIdx = self.list.getMark() # If an error occurred with the current track, flag it as such if withError: self.list.setItem(currIdx, ROW_ICO, icons.errorMenuIcon()) # Find the next 'playable' track (not already flagged) if self.btnRepeat.get_active(): nbTracks = len(self.list) else: nbTracks = len(self.list) - 1 - currIdx for i in xrange(nbTracks): currIdx = (currIdx + 1) % len(self.list) if self.list.getItem(currIdx, ROW_ICO) != icons.errorMenuIcon(): track = self.list.getItem(currIdx, ROW_TRK).getURI() self.jumpTo(currIdx, track != self.bufferedTrack, forced = False) self.bufferedTrack = None return self.bufferedTrack = None modules.postMsg(consts.MSG_CMD_STOP)
def loadArtists(self, tree, name): """ Load the given library """ libPath = os.path.join(ROOT_PATH, name) # Make sure the version number is the good one if not os.path.exists(os.path.join(libPath, 'VERSION_%u' % VERSION)): logger.error('[%s] Version number does not match, loading of library "%s" aborted' % (MOD_INFO[modules.MODINFO_NAME], name)) error = _('This library is deprecated, please refresh it.') tree.replaceContent([(icons.errorMenuIcon(), None, error, TYPE_NONE, None, None)]) return rows = [] icon = icons.dirMenuIcon() prevChar = '' allArtists = pickleLoad(os.path.join(libPath, 'artists')) self.allGenres = pickleLoad(os.path.join(libPath, 'genres')) # Filter artists by genre if needed if self.currGenre is not None: allArtists = [artist for artist in allArtists if artist[ART_NAME] in self.allGenres[self.currGenre]] rows.append((icons.infoMenuIcon(), None, '<b>%s</b>' % self.currGenre.capitalize(), TYPE_GENRE_BANNER, None, None)) else: rows.append((icons.infoMenuIcon(), None, '<b>%s</b>' % _('All genres'), TYPE_GENRE_BANNER, None, None)) # Filter artists by favorites if needed if self.showOnlyFavs: allArtists = [artist for artist in allArtists if self.isArtistInFavorites(artist[ART_NAME])] rows.append((icons.starMenuIcon(), None, '<b>%s</b>' % _('My Favorites'), TYPE_FAVORITES_BANNER, None, None)) # Create the rows for artist in allArtists: if len(artist[ART_NAME]) != 0: currChar = unicode(artist[ART_NAME], errors='replace')[0].lower() else: currChar = prevChar if prevChar != currChar and not (prevChar.isdigit() and currChar.isdigit()): prevChar = currChar if currChar.isdigit(): rows.append((None, None, '<b>0 - 9</b>', TYPE_HEADER, None, None)) else: rows.append((None, None, '<b>%s</b>' % currChar.upper(), TYPE_HEADER, None, None)) rows.append((icon, None, htmlEscape(artist[ART_NAME]), TYPE_ARTIST, os.path.join(libPath, artist[ART_INDEX]), artist[ART_NAME])) # Insert all rows, and then add a fake child to each artist tree.replaceContent(rows) for node in tree.iterChildren(None): if tree.getItem(node, ROW_TYPE) == TYPE_ARTIST: tree.appendRow(FAKE_CHILD, node)
def onTrackEnded(self, withError): """ The current track has ended, jump to the next one if any """ current_iter = self.tree.getMark() # If an error occurred with the current track, flag it as such if withError and current_iter: self.tree.setItem(current_iter, ROW_ICO, icons.errorMenuIcon()) # Find the next 'playable' track (not already flagged) next = self.__getNextTrackIter() if next: send_play_msg = True if current_iter: track_name = self.tree.getTrack(current_iter).getURI() send_play_msg = (track_name != self.bufferedTrack) self.jumpTo(next, sendPlayMsg=send_play_msg, forced=False) self.bufferedTrack = None return self.bufferedTrack = None modules.postMsg(consts.MSG_CMD_STOP)
def jumpTo(self, trackIdx, sendPlayMsg = True, forced = True): """ Jump to the track located at the given index """ if self.list.hasMark() and self.list.getItem(self.list.getMark(), ROW_ICO) != icons.errorMenuIcon(): self.list.setItem(self.list.getMark(), ROW_ICO, icons.nullMenuIcon()) self.list.setMark(trackIdx) self.list.scroll_to_cell(trackIdx) self.list.setItem(trackIdx, ROW_ICO, icons.playMenuIcon()) if sendPlayMsg: modules.postMsg(consts.MSG_CMD_PLAY, {'uri': self.list.getItem(trackIdx, ROW_TRK).getURI(), 'forced': forced}) modules.postMsg(consts.MSG_EVT_NEW_TRACK, {'track': self.list.getRow(trackIdx)[ROW_TRK]}) modules.postMsg(consts.MSG_EVT_TRACK_MOVED, {'hasPrevious': self.__hasPreviousTrack(), 'hasNext': self.__hasNextTrack()})