我们从Python开源项目中,提取了以下2个代码示例,用于说明如何使用PyQt5.QtWidgets.QFileSystemModel()。
def __init__(self): super().__init__(argv) signal(SIGINT, SIG_DFL) views = dirname(realpath(__file__)) + '/views/' self.welcome = loadUi(views + 'welcome.ui') self.choose_extractor = loadUi(views + 'choose_extractor.ui') self.choose_proto = loadUi(views + 'choose_proto.ui') self.create_endpoint = loadUi(views + 'create_endpoint.ui') self.choose_endpoint = loadUi(views + 'choose_endpoint.ui') self.fuzzer = loadUi(views + 'fuzzer.ui') self.welcome.step1.clicked.connect(self.load_extractors) self.choose_extractor.rejected.connect(partial(self.set_view, self.welcome)) self.choose_extractor.extractors.itemClicked.connect(self.prompt_extractor) self.welcome.step2.clicked.connect(self.load_protos) self.proto_fs = QFileSystemModel() self.choose_proto.protos.setModel(self.proto_fs) self.proto_fs.directoryLoaded.connect(self.choose_proto.protos.expandAll) for i in range(1, self.proto_fs.columnCount()): self.choose_proto.protos.hideColumn(i) self.choose_proto.protos.setRootIndex(self.proto_fs.index(str(BASE_PATH / 'protos'))) self.choose_proto.rejected.connect(partial(self.set_view, self.welcome)) self.choose_proto.protos.clicked.connect(self.new_endpoint) self.create_endpoint.transports.itemClicked.connect(self.pick_transport) self.create_endpoint.loadRespPbBtn.clicked.connect(self.load_another_pb) self.create_endpoint.rejected.connect(partial(self.set_view, self.choose_proto)) self.create_endpoint.buttonBox.accepted.connect(self.write_endpoint) self.welcome.step3.clicked.connect(self.load_endpoints) self.choose_endpoint.rejected.connect(partial(self.set_view, self.welcome)) self.choose_endpoint.endpoints.itemClicked.connect(self.launch_fuzzer) self.fuzzer.rejected.connect(partial(self.set_view, self.choose_endpoint)) self.fuzzer.fuzzFields.clicked.connect(self.fuzz_endpoint) self.fuzzer.deleteThis.clicked.connect(self.delete_endpoint) self.fuzzer.comboBox.activated.connect(self.launch_fuzzer) self.fuzzer.getAdd.clicked.connect(self.add_tab_data) self.fuzzer.urlField.setWordWrapMode(QTextOption.WrapAnywhere) for tree in (self.fuzzer.pbTree, self.fuzzer.getTree): tree.itemEntered.connect(lambda item, _: item.edit() if hasattr(item, 'edit') else None) tree.itemClicked.connect(lambda item, col: item.update_check(col=col)) tree.itemExpanded.connect(lambda item: item.expanded() if hasattr(item, 'expanded') else None) tree.header().setSectionResizeMode(QHeaderView.ResizeToContents) self.welcome.mydirLabel.setText(self.welcome.mydirLabel.text() % BASE_PATH) self.welcome.mydirBtn.clicked.connect(partial(QDesktopServices.openUrl, QUrl.fromLocalFile(str(BASE_PATH)))) self.set_view(self.welcome) self.exec_()
def __init__(self, parent=None): QtWidgets.QWidget.__init__(self, parent) self.setAttribute(QtCore.Qt.WA_DeleteOnClose) self.modes = [] self.modes.append(ImageViewMode(self)) self.modes.append(CloudViewMode(self)) self.modes.append(StarViewMode(self)) self.difference_mode = DifferenceViewMode(self) self.modes.append(self.difference_mode) self.current_mode = 0 self.index = 0 self.files = [] self.ui = Ui_ImageWidget() self.ui.setupUi(self) self.filesystemmodel = QtWidgets.QFileSystemModel(self) self.filesystemmodel.setFilter(QtCore.QDir.NoDotAndDotDot | QtCore.QDir.AllDirs) self.filesystemmodel.setRootPath("/") self.ui.folderView.setModel(self.filesystemmodel) self.ui.folderView.hideColumn(1) self.ui.folderView.hideColumn(2) self.ui.folderView.hideColumn(3) self.ui.folderView.setCurrentIndex(self.filesystemmodel.index(Configuration.default_storage_path)) self.ui.folderView.clicked.connect(self.changePath) self.changePath(self.ui.folderView.currentIndex()) self.ui.imageSelector.valueChanged.connect(self.selectImage) self.ui.firstButton.clicked.connect(self.firstFile) self.ui.previousButton.clicked.connect(self.previousFile) self.ui.nextButton.clicked.connect(self.nextFile) self.ui.lastButton.clicked.connect(self.lastFile) self.ui.rbImage.clicked.connect(self.showImage) self.ui.rbClouds.clicked.connect(self.showClouds) self.ui.rbStars.clicked.connect(self.showStars) self.ui.rbDifference.clicked.connect(self.showDifference) self.ui.cbRefresh.toggled.connect(self.toggleAutoRefresh) self.ui.cbAlgorithm.currentIndexChanged.connect(self.modes[1].setDetector) self.ui.cbStars.currentIndexChanged.connect(self.modes[2].setDetector) self.ui.diffPrevious.clicked.connect(self.previousFile) self.ui.diffNext.clicked.connect(self.nextFile) self.ui.diffPreviousInteresting.clicked.connect(self.previousInteresting) self.ui.diffNextInteresting.clicked.connect(self.nextInteresting) self.timer = QtCore.QTimer(self) self.timer.setInterval(500) self.timer.timeout.connect(self.refresh)