def openFiles(self, fileNames=None, rtiRegItem=None, caption=None, fileMode=None): """ Lets the user select on or more files and opens it. :param fileNames: If None an open-file dialog allows the user to select files, otherwise the files are opened directly. :param rtiRegItem: Open the files as this type of registered RTI. None=autodetect. :param caption: Optional caption for the file dialog. :param fileMode: is passed to the file dialog. :rtype fileMode: QtWidgets.QFileDialog.FileMode constant """ check_is_a_sequence(fileNames, allow_none=True) if fileNames is None: dialog = QtWidgets.QFileDialog(self, caption=caption) if rtiRegItem is None: nameFilter = 'All files (*);;' # Default show all files. nameFilter += self.argosApplication.rtiRegistry.getFileDialogFilter() if fileMode == QtWidgets.QFileDialog.Directory: rtiRegItemName = 'Directory' else: rtiRegItemName = '' else: nameFilter = rtiRegItem.getFileDialogFilter() nameFilter += ';;All files (*)' rtiRegItemName = rtiRegItem.name dialog.setNameFilter(nameFilter) if fileMode: dialog.setFileMode(fileMode) if dialog.exec_() == QtWidgets.QFileDialog.Accepted: fileNames = dialog.selectedFiles() else: fileNames = [] # Only add files that were added via the dialog box (not via the command line). self._argosApplication.addToRecentFiles(fileNames, rtiRegItemName) fileRootIndex = None logger.debug("Opening file names: {}".format(fileNames)) for fileName in fileNames: fileRootIndex = self.argosApplication.repo.loadFile(fileName, rtiRegItem=rtiRegItem) self.repoWidget.repoTreeView.setExpanded(fileRootIndex, True) # Select last opened file if fileRootIndex is not None: self.repoWidget.repoTreeView.setCurrentIndex(fileRootIndex)
def openFiles(self, fileNames=None, rtiRegItem=None, caption=None, fileMode=None): """ Lets the user select on or more files and opens it. :param fileNames: If None an open-file dialog allows the user to select files, otherwise the files are opened directly. :param rtiRegItem: Open the files as this type of registered RTI. None=autodetect. :param caption: Optional caption for the file dialog. :param fileMode: is passed to the file dialog. :rtype fileMode: QtWidgets.QFileDialog.FileMode constant """ if fileNames is None: dialog = QtWidgets.QFileDialog(self, caption=caption) if rtiRegItem is None: nameFilter = 'All files (*);;' # Default show all files. nameFilter += self.argosApplication.rtiRegistry.getFileDialogFilter( ) else: nameFilter = rtiRegItem.getFileDialogFilter() nameFilter += ';;All files (*)' dialog.setNameFilter(nameFilter) if fileMode: dialog.setFileMode(fileMode) if dialog.exec_() == QtWidgets.QFileDialog.Accepted: fileNames = dialog.selectedFiles() else: fileNames = [] fileRootIndex = None for fileName in fileNames: rtiClass = rtiRegItem.getClass( tryImport=True) if rtiRegItem else None fileRootIndex = self.argosApplication.repo.loadFile( fileName, rtiClass=rtiClass) self.repoWidget.repoTreeView.setExpanded(fileRootIndex, True) # Select last opened file if fileRootIndex is not None: self.repoWidget.repoTreeView.setCurrentIndex(fileRootIndex)