def onSeekChangingValue(self, range, scroll, value): """ The user is moving the seek slider """ self.sclBeingDragged = True if value >= self.currTrackLength: value = self.currTrackLength else: value = int(value) self.lblElapsed.set_label(sec2str(value)) self.lblRemaining.set_label(sec2str(self.currTrackLength - value))
def onNewTrackPosition(self, elapsedTime): """ The track position has changed """ if not self.sclBeingDragged: self.lblElapsed.set_label(sec2str(elapsedTime)) if elapsedTime >= self.currTrackLength: elapsedTime = self.currTrackLength self.lblRemaining.set_label(sec2str(self.currTrackLength - elapsedTime)) # Make sure the handler will not be called self.sclSeek.disconnect(self.seekHandler) self.sclSeek.set_value(elapsedTime) self.seekHandler = self.sclSeek.connect('value-changed', self.onSeekValueChanged)
def onNewTrackPosition(self, seconds): """ The track position has changed """ if not self.sclBeingDragged: self.lblElapsed.set_label(sec2str(seconds)) if seconds >= self.currTrackLength: seconds = self.currTrackLength self.lblRemaining.set_label(sec2str(self.currTrackLength - seconds)) # Make sure the handler will not be called self.sclSeek.handler_block_by_func(self.onSeekValueChanged) self.sclSeek.set_value(seconds) self.sclSeek.handler_unblock_by_func(self.onSeekValueChanged)
def loadAlbums(self, tree, node, fakeChild): """ Initial load of the albums of the given node, assuming it is of type TYPE_ARTIST """ rows = [] path = tree.getItem(node, ROW_FULLPATH) artist = tree.getItem(node, ROW_DATA) allAlbums = pickleLoad(os.path.join(tree.getItem(node, ROW_FULLPATH), 'albums')) # Filter albums if only favorites should be shown if self.showOnlyFavs: allAlbums = [album for album in allAlbums if self.isAlbumInFavorites(artist, album[ALB_NAME])] # Filter artists by genre if needed if self.currGenre is not None: allAlbums = [album for album in allAlbums if album[ALB_NAME] in self.allGenres[self.currGenre][artist]] # The icon depends on whether the album is in the favorites for album in allAlbums: if self.isAlbumInFavorites(artist, album[ALB_NAME]): icon = icons.starDirMenuIcon() else: icon = icons.mediaDirMenuIcon() rows.append((icon, '[%s]' % tools.sec2str(album[ALB_LENGTH], True), '%s' % htmlEscape(album[ALB_NAME]), TYPE_ALBUM, os.path.join(path, album[ALB_INDEX]), album[ALB_NAME])) # Add all the rows, and then add a fake child to each of them tree.appendRows(rows, node) tree.removeRow(fakeChild) for child in tree.iterChildren(node): tree.appendRow(FAKE_CHILD, child)
def __updateStatusbar(self): """ Update the status bar """ # Tracklist count = len(self.tracklist) if count == 0: self.status1.set_label('') else: self.status1.set_label(ngettext('One track in playlist [%(length)s]', '%(count)u tracks in playlist [%(length)s]', count) \ % {'count': count, 'length': tools.sec2str(self.playtime)}) # Selected tracks count = len(self.selTracks) if count == 0: self.status2.set_label('') else: selection = ngettext('One track selected', '%(count)u tracks selected', count) % {'count': count} audioType = self.selTracks[0].getType() for track in self.selTracks[1:]: if track.getType() != audioType: audioType = _('various') break bitrate = self.selTracks[0].getBitrate() for track in self.selTracks[1:]: if track.getBitrate() != bitrate: bitrate = _('various') break self.status2.set_label(_('%(selection)s (Type: %(type)s, Bitrate: %(bitrate)s)') % {'selection': selection, 'type': audioType, 'bitrate': bitrate})
def updateTree(self, discInfo): """ Update the tree using disc information from the cache, if any """ cddb = self.getDiscFromCache(discInfo) # Create fake CDDB information if needed if cddb is None: cddb = {"DTITLE": "%s / %s" % (consts.UNKNOWN_ARTIST, consts.UNKNOWN_ALBUM)} for i in xrange(discInfo[DISC_NB_TRACKS]): cddb["TTITLE%u" % i] = consts.UNKNOWN_TITLE # Compute the length of each track trackLen = [ int(round((discInfo[DISC_FRAME1 + i + 1] - discInfo[DISC_FRAME1 + i]) / 75.0)) for i in xrange(discInfo[DISC_NB_TRACKS] - 1) ] trackLen.append(discInfo[DISC_LENGTH] - int(round(discInfo[DISC_FRAMEn] / 75.0))) # Update the root of the tree disc = cddb["DTITLE"].strip().decode("iso-8859-15", "replace") artist, album = disc.split(" / ") self.tree.setItem((0,), ROW_NAME, "%s" % tools.htmlEscape(disc)) self.tree.setItem((0,), ROW_LENGTH, "[%s]" % sec2str(sum(trackLen))) # Update the explorer name modules.postMsg( consts.MSG_CMD_EXPLORER_RENAME, {"modName": MOD_L10N, "expName": self.expName, "newExpName": disc} ) self.expName = disc # Optional information try: date = int(cddb["DYEAR"].strip().decode("iso-8859-15", "replace")) except: date = None try: genre = cddb["DGENRE"].strip().decode("iso-8859-15", "replace") except: genre = None # Update each track for i, child in enumerate(self.tree.iterChildren((0,))): title = cddb["TTITLE%u" % i].strip().decode("iso-8859-15", "replace") # Create the corresponding Track object track = CDTrack(str(i + 1)) track.setTitle(title) track.setAlbum(album) track.setArtist(artist) track.setLength(trackLen[i]) track.setNumber(i + 1) # Optional information if date is not None: track.setDate(date) if genre is not None: track.setGenre(genre) # Fill the tree self.tree.setItem(child, ROW_NAME, "%02u. %s" % (i + 1, tools.htmlEscape(title))) self.tree.setItem(child, ROW_TRACK, track)
def onNewTracklist(self, count, playtime): """ A new tracklist has been set """ if count == 0: text = '' else: text = ngettext('One track in playlist [%(length)s]', '%(count)u tracks in playlist [%(length)s]', count) \ % {'count': count, 'length': tools.sec2str(playtime)} self.statusbar.pop(self.contextId) self.statusbar.push(self.contextId, text)
def loadAlbums(self, tree, node, fakeChild): """ Initial load of all albums of the given node, assuming it is of type TYPE_ARTIST """ allAlbums = pickleLoad(os.path.join(tree.getItem(node, ROW_FULLPATH), 'albums')) path = tree.getItem(node, ROW_FULLPATH) rows = [(consts.icoMediaDir, '[%s]' % tools.sec2str(album[ALB_LENGTH], True), '%s' % cgi.escape(album[ALB_NAME]), TYPE_ALBUM, os.path.join(path, album[ALB_INDEX]), None) for album in allAlbums] # Add all the rows, and then add a fake child to each of them tree.freeze_child_notify() tree.appendRows(rows, node) tree.removeRow(fakeChild) for child in tree.iterChildren(node): tree.appendRow((None, None, '', TYPE_NONE, '', None), child) tree.thaw_child_notify()
def format(self, fmtString): """ Replace the special fields in the given string by their corresponding value """ result = fmtString result = result.replace( '{path}', self.getFilePath() ) result = result.replace( '{album}', self.getAlbum() ) result = result.replace( '{track}', str(self.getNumber()) ) result = result.replace( '{title}', self.getTitle() ) result = result.replace( '{artist}', self.getArtist() ) result = result.replace( '{genre}', self.getGenre() ) result = result.replace( '{date}', str(self.getDate()) ) result = result.replace( '{disc}', str(self.getDiscNumber()) ) result = result.replace( '{bitrate}', self.getBitrate() ) result = result.replace( '{sample_rate}', str(self.getSampleRate()) ) result = result.replace( '{duration_sec}', str(self.getLength()) ) result = result.replace( '{duration_str}', sec2str(self.getLength()) ) return result
def get_label(self, parent_label=None, playing=False): """ Return a treeview representation """ title = self.tags.get(TAG_TIT, '') artist = self.tags.get(TAG_ART, '') album = self.getExtendedAlbum() if album == consts.UNKNOWN_ALBUM: album = '' number = self.tags.get(TAG_NUM, '') length = self.getLength() if number: number = str(number).zfill(2) # Delete whitespace at the end connectors = ['the', 'and', '&', ',', '.', '?', '!', "'", ':', '-', ' '] if parent_label: parent_label = parent_label.lower() short_album = album.lower() short_artist = artist.lower() for connector in connectors: parent_label = parent_label.replace(connector, '') short_album = short_album.replace(connector, '') short_artist = short_artist.replace(connector, '') if short_album.strip() in parent_label: album = '' if short_artist.strip() in parent_label: artist = '' if title: label = ' - '.join([part for part in [artist, album, number, title] if part]) else: label = self.getBasename() label = tools.htmlEscape(label) if playing: label = '<b>%s</b>' % label #label += ' <span foreground="gray">[%s]</span>' % tools.sec2str(length) label += ' [%s]' % tools.sec2str(length) return label
def formatHTMLSafe(self, fmtString): """ Replace the special fields in the given string by their corresponding value Also ensure that the fields don't contain HTML special characters (&, <, >) """ result = fmtString result = result.replace( '{path}', tools.htmlEscape(self.getFilePath()) ) result = result.replace( '{album}', tools.htmlEscape(self.getAlbum()) ) result = result.replace( '{track}', str(self.getNumber()) ) result = result.replace( '{title}', tools.htmlEscape(self.getTitle()) ) result = result.replace( '{artist}', tools.htmlEscape(self.getArtist()) ) result = result.replace( '{genre}', tools.htmlEscape(self.getGenre()) ) result = result.replace( '{date}', str(self.getDate()) ) result = result.replace( '{disc}', str(self.getDiscNumber()) ) result = result.replace( '{bitrate}', self.getBitrate() ) result = result.replace( '{sample_rate}', self.getSampleRate() ) result = result.replace( '{duration_sec}', str(self.getLength()) ) result = result.replace( '{duration_str}', sec2str(self.getLength()) ) return result
def fmtLength(self, col, cll, mdl, it): cll.set_property('text', tools.sec2str(mdl.get_value(it, ROW_LEN))) def __getNextTrackIdx(self):
def __fmtLengthColumn(self, col, cll, mdl, it): """ Format the column showing the length of the track (e.g., show 1:23 instead of 83) """ cll.set_property('text', tools.sec2str(mdl.get_value(it, ROW_LEN))) self.__fmtColumnColor(col, cll, mdl, it)
def set_time(self, seconds): elapsed = sec2str(seconds) #remaining = sec2str(self.currTrackLength - seconds) total = sec2str(self.currTrackLength) self.sclSeek.set_tooltip_text('%s / %s' % (elapsed, total))
def __setTitle(self, title, length=None): """ Change the title of the current track """ title = cgi.escape(title) if length is None: self.txtTitle.set_markup('<span size="larger"><b>%s</b></span>' % title) else: self.txtTitle.set_markup('<span size="larger"><b>%s</b></span> [%s]' % (title, tools.sec2str(length)))