def getDirContents(self, directory): """ Return a tuple of sorted rows (directories, playlists, mediaFiles) for the given directory """ playlists = [] mediaFiles = [] directories = [] for (file, path) in tools.listDir(directory, self.showHiddenFiles): if isdir(path): directories.append( (icons.dirMenuIcon(), tools.htmlEscape(unicode(file, errors='replace')), TYPE_DIR, path)) elif isfile(path): if media.isSupported(file): mediaFiles.append( (icons.mediaFileMenuIcon(), tools.htmlEscape(unicode(file, errors='replace')), TYPE_FILE, path)) elif playlist.isSupported(file): playlists.append( (icons.mediaFileMenuIcon(), tools.htmlEscape(unicode(file, errors='replace')), TYPE_FILE, path)) playlists.sort(key=self.sortKey) mediaFiles.sort(key=self.sortKey) directories.sort(key=self.sortKey) return (directories, playlists, mediaFiles)
def getDirContents(self, directory): """ Return a tuple of sorted rows (directories, playlists, mediaFiles) for the given directory """ playlists = [] mediaFiles = [] directories = [] for (file, path) in tools.listDir(unicode(directory)): # Make directory names prettier junk = ['_'] pretty_name = file for item in junk: pretty_name = pretty_name.replace(item, ' ') if isdir(path): directories.append((icons.dirMenuIcon(), tools.htmlEscape(pretty_name), TYPE_DIR, path)) elif isfile(path): if media.isSupported(file): mediaFiles.append((icons.mediaFileMenuIcon(), tools.htmlEscape(pretty_name), TYPE_FILE, path)) ##elif playlist.isSupported(file): ## playlists.append((icons.mediaFileMenuIcon(), tools.htmlEscape(unicode(file, errors='replace')), TYPE_FILE, path)) # Individually sort each type of file by name playlists.sort(key=self._filename) mediaFiles.sort(key=self._filename) directories.sort(key=self._filename) return (directories, playlists, mediaFiles)
def loadTracks(self, tree, node, fakeChild): """ Initial load of all tracks of the given node, assuming it is of type TYPE_ALBUM """ allTracks = pickleLoad(tree.getItem(node, ROW_FULLPATH)) icon = icons.mediaFileMenuIcon() rows = [(icon, None, '%02u. %s' % (track.getNumber(), htmlEscape(track.getTitle())), TYPE_TRACK, track.getFilePath(), track) for track in allTracks] tree.appendRows(rows, node) tree.removeRow(fakeChild)
def createTree(self, nbTracks): """ Create a temporary explorer tree without disc information """ name = '%s <span size="smaller" foreground="#909090">%s</span>' % (MOD_L10N, _("downloading data...")) self.tree.replaceContent(((icons.cdromMenuIcon(), None, name, None),)) # Append a child for each track self.tree.appendRows( [(icons.mediaFileMenuIcon(), None, _("Track %02u") % (i + 1), None) for i in xrange(nbTracks)], (0,) ) self.tree.expand_all()
def getDirContents(self, directory): """ Return a tuple of sorted rows (directories, playlists, mediaFiles) for the given directory """ playlists = [] mediaFiles = [] directories = [] for (file, path) in tools.listDir(directory, self.showHiddenFiles): if isdir(path): directories.append((icons.dirMenuIcon(), tools.htmlEscape(unicode(file, errors='replace')), TYPE_DIR, path)) elif isfile(path): if media.isSupported(file): mediaFiles.append((icons.mediaFileMenuIcon(), tools.htmlEscape(unicode(file, errors='replace')), TYPE_FILE, path)) elif playlist.isSupported(file): playlists.append((icons.mediaFileMenuIcon(), tools.htmlEscape(unicode(file, errors='replace')), TYPE_FILE, path)) playlists.sort(key=self.sortKey) mediaFiles.sort(key=self.sortKey) directories.sort(key=self.sortKey) return (directories, playlists, mediaFiles)
def onSearchAppend(self, results, query): self._remove_searching_node() # Make sure we never call this method without calling onSearchStart first if not self.displaying_results: return dirs, files = results for path, name in dirs: new_node = self.tree.appendRow((icons.dirMenuIcon(), name, TYPE_DIR, path), None) # add fake child self.tree.appendRow((icons.dirMenuIcon(), '', TYPE_NONE, ''), new_node) for file, name in files: self.tree.appendRow((icons.mediaFileMenuIcon(), name, TYPE_FILE, file), None)
def restoreTreeDump(self, dump, parent=None): """ Recursively restore the dump under the given parent (None for the root of the tree) """ for item in dump: (name, type, path) = item[0] if type == TYPE_FILE: self.tree.appendRow((icons.mediaFileMenuIcon(), name, TYPE_FILE, path), parent) else: newNode = self.tree.appendRow((icons.dirMenuIcon(), name, TYPE_DIR, path), parent) if item[1] is not None: fakeChild = self.tree.appendRow((icons.dirMenuIcon(), '', TYPE_NONE, ''), newNode) if len(item[1]) != 0: # We must expand the row before adding the real children, but this works only if there is already at least one child self.tree.expandRow(newNode) self.restoreTreeDump(item[1], newNode) self.tree.removeRow(fakeChild)
def restoreTreeDump(self, dump, parent=None): """ Recursively restore the dump under the given parent (None for the root of the tree) """ for item in dump: (name, type, path) = item[0] if type == TYPE_FILE: self.tree.appendRow( (icons.mediaFileMenuIcon(), name, TYPE_FILE, path), parent) else: newNode = self.tree.appendRow( (icons.dirMenuIcon(), name, TYPE_DIR, path), parent) if item[1] is not None: fakeChild = self.tree.appendRow( (icons.dirMenuIcon(), '', TYPE_NONE, ''), newNode) if len(item[1]) != 0: # We must expand the row before adding the real children, but this works only if there is already at least one child self.tree.expandRow(newNode) self.restoreTreeDump(item[1], newNode) self.tree.removeRow(fakeChild)