def goToSearch(self, searchString): """ Sets the current row to the item beginning with searchString. Assumes the FileList has previously been sorted by a call to SelectSort(). """ ss = pykdb.SongStruct(searchString, self.songDb.Settings, searchString, searchString, searchString) self.currentRow = bisect.bisect_left(self.songDb.SongList, ss) if self.currentRow == len(self.songDb.SongList): self.currentRow = 0 self.screenDirty = True
def readMarkedSongs(self): """ Reads marked.txt, which lists the files that have been marked by the user for later inspection or adjustment (for instance, to correct a title misspelling or something). """ self.markedSongs = {} self.markedSongsDirty = False pathname = os.path.join(self.songDb.SaveDir, "marked.txt") if not os.path.exists(pathname): return # We need to re-sort by filename in order to look up the # songs properly. self.songDb.SelectSort('filename') file = open(pathname, 'r') for line in file: line = line.decode('utf-8').strip() if line: # Read a line from the list. It describes a song, and # includes filename, title, and artist, though we only # really care about the filename. filename = line.split('\t', 1)[0] # Look up the song in the database. song = pykdb.SongStruct(filename, self.songDb.Settings, '', '', filename) found = False row = bisect.bisect_left(self.songDb.SongList, song) if row != len(self.songDb.SongList): # If we found the song, record that it is marked. song = self.songDb.SongList[row] if song.DisplayFilename == filename: self.markedSongs[song.getMarkKey()] = song found = True if not found: # If we didn't find the song, it follows that # marked.txt is out-of-sync with the database, and # needs to be rewritten. self.markedSongsDirty = True
def __init__(self, song, errorNotifyCallback=None, doneCallback=None, windowTitle=None): """The first parameter, song, may be either a pykdb.SongStruct instance, or it may be a filename. """ # Set the global command-line options if they have not already # been set. if manager.options == None: parser = self.SetupOptions() (manager.options, args) = parser.parse_args() if song is None: if (len(args) != 1): parser.print_help() sys.exit(2) song = args[0] if isinstance(song, types.StringTypes): # We were given a filename. Convert it to a SongStruct. import pykdb song = pykdb.SongStruct(song) # Store the parameters self.Song = song self.WindowTitle = windowTitle # And look up the actual files corresponding to this SongStruct. self.SongDatas = song.GetSongDatas() if windowTitle is None: self.WindowTitle = song.DisplayFilename # Caller can register a callback by which we # print out error information, use stdout if none registered if errorNotifyCallback: self.ErrorNotifyCallback = errorNotifyCallback else: self.ErrorNotifyCallback = self.__defaultErrorPrint # Caller can register a callback by which we # let them know when the song is finished if doneCallback: self.SongFinishedCallback = doneCallback else: self.SongFinishedCallback = None self.State = STATE_INIT self.InternalOffsetTime = 0 # These values are used to keep track of the current position # through the song based on pygame's get_ticks() interface. # It's used only when get_pos() cannot be used or is # unreliable for some reason. self.PlayTime = 0 self.PlayStartTime = 0 # self.PlayStartTime is valid while State == STATE_PLAYING; it # indicates the get_ticks() value at which the song started # (adjusted for any pause intervals that occurred during # play). self.PlayTime is valid while State != STATE_PLAYING; # it indicates the total number of ticks (milliseconds) that # have elapsed in the song so far. # Set this true if the player can zoom font sizes. self.SupportsFontZoom = False