def _addMeshInList(self, file_name): """ Tab1: add input new meshes in the listbox and case. """ (d, m) = os.path.split(file_name) index = -1 if self.mesh_dirs[0] != None: index = d.find(self.mesh_dirs[0]) if index == 0: d = d[len(self.mesh_dirs[0]) + 1:] if d == '': d = None mesh = (m, d) # 1) Verify that the new mesh is not already in the case if mesh in self.mdl.getMeshList(): title = self.tr("Warning") msg = self.tr("Warning, the following input is already " \ "uploaded in the list:\n\n" + file_name) QMessageBox.information(self, title, msg) else: # 2) Update View and model format = MeshModel().getMeshFormat(mesh[0]) self.mdl.addMesh(mesh) self.modelMeshes.addRow(mesh, format) self._tableViewLayout()
def __init__(self, parent=None, updateLayout=None): super(MeshFormatDelegate, self).__init__(parent) self.parent = parent self.updateLayout = updateLayout self.lst = MeshModel().getBuildFormatList() # Compute width based on longest possible string and font metrics fm = self.parent.fontMetrics() self.textSize = fm.size(Qt.TextSingleLine, 'I-deas universal') self.textSize.setHeight(1) for i in range(len(self.lst)): w = fm.size(Qt.TextSingleLine, str(self.lst[i][1])).width() if w > self.textSize.width(): self.textSize.setWidth(w)
def __init__(self, mdl): """ """ QStandardItemModel.__init__(self) self.mdl = mdl self.dataMeshes = [] # list of items to be disabled in the QTableView self.disabledItem = [] lst = MeshModel().getBuildFormatList() self.formatDict = {'': ''} for i in range(len(lst)): self.formatDict[lst[i][0]] = lst[i][1] self.populateModel() self.headers = [ self.tr("File name"), self.tr("Format"), self.tr("Numbers"), self.tr("Reorient"), self.tr("Add face groups"), self.tr("Add cell groups"), self.tr("Path") ] self.tooltip = [ self.tr("Preprocessor option: --mesh"), self.tr("Preprocessor sub-option: --format"), self.tr("Preprocessor sub-option: --num"), self.tr("Preprocessor sub-option: --reorient"), self.tr("Preprocessor sub-option: --grp-fac"), self.tr("Preprocessor sub-option: --grp-cel"), self.tr("Preprocessor option: --mesh") ] self.setColumnCount(len(self.headers)) # Initialize the flags for row in range(self.rowCount()): for column in range(self.columnCount()): role = Qt.DisplayRole index = self.index(row, column) value = self.data(index, role) if column != 1: self.setData(index, value) else: self.setData(index, self.dataMeshes[row][1])
def selectMeshFiles(self): """ Open a File Dialog in order to select mesh files. """ mesh_files = [] title = self.tr("Select input mesh file(s)") default = self.mesh_dirs[0] if default == None: default = os.path.split(self.case['case_path'])[0] if hasattr(QFileDialog, 'ReadOnly'): options = QFileDialog.DontUseNativeDialog | QFileDialog.ReadOnly else: options = QFileDialog.DontUseNativeDialog l_mesh_dirs = [] for i in range(0, len(self.mesh_dirs)): if self.mesh_dirs[i] != None: l_mesh_dirs.append(QUrl.fromLocalFile(self.mesh_dirs[i])) filetypes = "" for Format in MeshModel().getFileFormatList(): filetypes += "%s (%s);;" % (Format[0], Format[1]) dialog = QFileDialog() dialog.setWindowTitle(title) dialog.setDirectory(default) dialog.setNameFilter(filetypes) if hasattr(dialog, 'setOptions'): dialog.setOptions(options) dialog.setSidebarUrls(l_mesh_dirs) dialog.setFileMode(QFileDialog.ExistingFiles) if dialog.exec_() == 1: s = dialog.selectedFiles() count = len(s) for i in range(count): el = str(s[0]) s = s[1:] mesh_files.append(el) return mesh_files