astra-test/main.py

35 lines
1.3 KiB
Python
Raw Normal View History

2023-10-18 04:16:52 +03:00
import sys
from PyQt5 import QtWidgets, QtCore
class Widget(QtWidgets.QWidget):
def __init__(self, *args, **kwargs):
super(Widget, self).__init__(*args, **kwargs)
self.treeview = QtWidgets.QTreeView()
# делаем домашнюю папку пользователя - начальной
path = QtCore.QDir.homePath()
# dirModel
self.dirModel = QtWidgets.QFileSystemModel()
self.dirModel.setRootPath(path)
# QtCore.QDir.AllEntries - отображение всех файлов
# QtCore.QDir.NoDotAndDotDot - нет точки и двух точек
# QtCore.QDir.Hidden - скрытые файлы
self.dirModel.setFilter(QtCore.QDir.AllEntries | QtCore.QDir.NoDotAndDotDot | QtCore.QDir.Hidden)
self.treeview.setModel(self.dirModel)
self.treeview.setRootIndex(self.dirModel.index(path))
self.treeview.clicked.connect(self.on_clicked_item)
hlay = QtWidgets.QHBoxLayout(self)
hlay.addWidget(self.treeview)
# функция обработки кликов
def on_clicked_item(self, index):
path = self.dirModel.filePath(index)
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
w = Widget()
w.show()
sys.exit(app.exec_())