Exemplo n.º 1
0
class getFilesDlg(QDialog):

	# sendPaths is a signal emitted by getPaths containing a list of file paths from
	# the users selection via this dialog.
	sendPaths = Signal(list)

	def __init__(self, parent=None):
		super(getFilesDlg, self).__init__(parent)

		self.setMinimumSize(500,500)

		self.fileDlgPaths = []

		layout = QVBoxLayout()

		self.btnBox = QDialogButtonBox(QDialogButtonBox.Ok |
			QDialogButtonBox.Cancel)
		
		self.btnBox.accepted.connect(self.getPaths)
		self.btnBox.rejected.connect(self.close)

		self.fsModel = QFileSystemModel()
		
		self.treeView = QTreeView()
		self.treeView.setSelectionMode(QTreeView.ExtendedSelection)
		
		self.treeView.setModel(self.fsModel)
		self.treeView.setColumnWidth(0, 361)
		self.treeView.setColumnHidden(1, True)
		self.treeView.setColumnHidden(3, True)

		layout.addWidget(self.treeView)
		layout.addWidget(self.btnBox)
		self.setLayout(layout)

		self.fsModel.setRootPath(environ['HOMEPATH'])
		# self.treeView.setRootIndex(self.fsModel.index("\\"))
		self.treeView.expand(self.treeView.rootIndex())


	def getPaths(self):
		# For some reason duplicates were being returned when they weren't supposed to.
		# This obtains the selected files from the dialog and only returns individual
		# paths.
		indexes = self.treeView.selectedIndexes()
		if indexes:
			self.fileDlgPaths = []
			for i in indexes:
				
				# Possible permission error occuring here
				# unable to replicate at this time
				path = self.fsModel.filePath(i)
				if path not in self.fileDlgPaths:
					self.fileDlgPaths.append(path.replace('/','\\'))
			self.close() # To close the dialog on an accept signal
			self.sendPaths.emit(self.fileDlgPaths)