-
Notifications
You must be signed in to change notification settings - Fork 0
/
dir_explr.py
65 lines (51 loc) · 1.93 KB
/
dir_explr.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import sys
from PyQt5.QtWidgets import (QApplication, QFileSystemModel,
QTreeView, QListView, QWidget,
QTableView, QHBoxLayout)
# from PyQt5.QtGui import QIcon
from PyQt5.QtCore import QDir
class DirectoryTree(QWidget):
def __init__(self):
super().__init__()
self.title = 'PyQt5 file system view'
self.left = 10
self.top = 10
self.width = 640
self.height = 480
self.initUI()
def initUI(self):
self.setWindowTitle(self.title)
self.setGeometry(self.left, self.top, self.width, self.height)
self.model = QFileSystemModel()
self.model.setRootPath(QDir.rootPath())
self.model.setFilter(QDir.AllDirs | QDir.NoDotAndDotDot)
self.tree = QTreeView()
self.tree.setModel(self.model)
self.tree.hideColumn(1)
self.tree.hideColumn(2)
self.tree.hideColumn(3)
self.tree.setAnimated(False)
self.tree.setIndentation(20)
self.tree.setSortingEnabled(True)
self.tree.setWindowTitle("Dir View")
self.tree.resize(640, 480)
self.fileModel = QFileSystemModel()
self.fileModel.setRootPath(QDir.rootPath())
self.list = QTableView()
self.list.setModel(self.fileModel)
self.list.setShowGrid(False)
self.list.verticalHeader().setVisible(False)
self.list.setSelectionBehavior(QTableView().SelectRows)
self.tree.clicked.connect(self.onClicked)
windowLayout = QHBoxLayout()
windowLayout.addWidget(self.tree)
windowLayout.addWidget(self.list)
self.setLayout(windowLayout)
self.show()
def onClicked(self, index):
path = self.model.fileInfo(index).absoluteFilePath()
self.list.setRootIndex(self.fileModel.setRootPath(path))
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = DirectoryTree()
sys.exit(app.exec_())