Source code for prettyqt.widgets.filesystemmodel

# -*- coding: utf-8 -*-
"""
@author: Philipp Temminghoff
"""

import pathlib

from qtpy import QtCore, QtWidgets

from prettyqt import core


QtWidgets.QFileSystemModel.__bases__ = (core.AbstractItemModel,)


[docs]class FileSystemModel(QtWidgets.QFileSystemModel): """ Class to populate a filesystem treeview """ DATA_ROLE = QtCore.Qt.UserRole + 33 content_type = "files" def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.setReadOnly(False) self.setRootPath(QtCore.QDir.rootPath())
[docs] def data(self, index, role=QtCore.Qt.DisplayRole): if role == self.DATA_ROLE: path = index.data(self.FilePathRole) return pathlib.Path(path) return super().data(index, role)
def yield_child_indexes(self, index): if not self.hasChildren(index): return None path = self.filePath(index) flags = self.filter() | QtCore.QDir.NoDotAndDotDot for it in core.DirIterator(path, flags): yield self.index(it)