def _referenceLineSlot(self, ddict): if ddict['event'] == "returnPressed": current = str(self.referenceLine.text()) current = current.replace(' ', '') if (current == '') or (current.upper() == 'AUTO'): pass elif len(current) == 2: current = current.upper()[0] + current.lower()[1] elif len(current) == 1: current = current.upper()[0] else: self.referenceLine.setText('Auto') msg = qt.QMessageBox(self.referenceLine) msg.setIcon(qt.QMessageBox.Critical) msg.setText("Invalid Element %s" % current) msg.exec_() self.referenceLine.setFocus() return if (current == '') or (current.upper() == 'AUTO'): self.referenceLine.setText('Auto') self._mySignal() elif not Elements.isValidFormula(current): self.referenceLine.setText('Auto') msg = qt.QMessageBox(self.referenceLine) msg.setIcon(qt.QMessageBox.Critical) msg.setText("Invalid Element %s" % current) if QTVERSION < '4.0.0': msg.exec_loop() else: msg.exec_() self.referenceLine.setFocus() else: self.referenceLine.setText(current) self._mySignal()
def __tableSlot(self,row, col): if self.__fillingValues: return item = self.__table.item(row, col) if item is not None: _logger.debug("table item is None") qstring = item.text() else: qstring = "" if col == 0: compound = str(qstring) if Elements.isValidFormula(compound): pass else: matkey = Elements.getMaterialKey(compound) if matkey is not None: item.setText(matkey) else: msg=qt.QMessageBox(self.__table) msg.setIcon(qt.QMessageBox.Critical) msg.setText("Invalid Formula %s" % compound) msg.exec_() self.__table.setCurrentCell(row, col) return else: try: float(str(qstring)) except: msg=qt.QMessageBox(self.__table) msg.setIcon(qt.QMessageBox.Critical) msg.setText("Invalid Float") msg.exec_() self.__table.setCurrentCell(row, col) return self._updateCurrent()
def __tableSlot2(self,row, col): if self.__fillingValues:return if self.__lastRow is None: self.__lastRow = row if self.__lastColumn is None: self.__lastColumn = col item = self.__table.item(self.__lastRow, self.__lastColumn) if item is None: item = qt.QTableWidgetItem("",qt.QTableWidgetItem.Type) self.__table.setItem(self.__lastRow, self.__lastColumn, item) qstring = item.text() if self.__lastColumn == 0: compound = str(qstring) if Elements.isValidFormula(compound): pass else: matkey = Elements.getMaterialKey(compound) if matkey is not None: item = self.__table.item(self.__lastRow, self.__lastColumn) if item is None: item = qt.QTableWidgetItem(matkey, qt.QTableWidgetItem.Type) self.__table.setItem(self.__lastRow, self.__lastColumn, item) else: item.setText(matkey) else: msg=qt.QMessageBox(self.__table) msg.setIcon(qt.QMessageBox.Critical) msg.setText("Invalid Formula %s" % compound) msg.exec_() self.__table.setCurrentCell(self.__lastRow, self.__lastColumn) return else: try: float(str(qstring)) except: msg=qt.QMessageBox(self.__table) msg.setIcon(qt.QMessageBox.Critical) msg.setText("Invalid Float") msg.exec_() self.__table.setCurrentCell(self.__lastRow, self.__lastColumn) return self._updateCurrent()
def validate(self, qstring, pos): text = str(qstring) if text == '-': return (self.Valid, pos) try: # this test is needed even if pyflakes complains! float(text) return (self.Invalid, pos) except: pass if text.endswith(' '): return (self.Invalid, pos) if Elements.isValidFormula(text): return (self.Valid, pos) elif Elements.isValidMaterial(text): return (self.Valid, pos) else: return (self.Invalid,pos)
def _checkDensityThickness(self, text, row): try: currentDensity = float(str(self.text(row, 3))) except: currentDensity = 0.0 try: currentThickness = float(str(self.text(row, 4))) except: currentThickness = 0.0 defaultDensity = -1.0 defaultThickness = -0.1 #check if default density is there if Elements.isValidFormula(text): #check if single element if text in Elements.Element.keys(): defaultDensity = Elements.Element[text]['density'] else: elts = [ w for w in re.split('[0-9]', text) if w != ''] nbs = [ int(w) for w in re.split('[a-zA-Z]', text) if w != ''] if len(elts) == 1 and len(nbs) == 1: defaultDensity = Elements.Element[elts[0]]['density'] elif Elements.isValidMaterial(text): key = Elements.getMaterialKey(text) if key is not None: if 'Density' in Elements.Material[key]: defaultDensity = Elements.Material[key]['Density'] if 'Thickness' in Elements.Material[key]: defaultThickness = Elements.Material[key]['Thickness'] if defaultDensity >= 0.0: self.setText(row, 3, "%g" % defaultDensity) elif currentDensity <= 0: # should not be better to raise an exception if the # entered density or thickness were negative? self.setText(row, 3, "%g" % 1.0) if defaultThickness >= 0.0: self.setText(row, 4, "%g" % defaultThickness) elif currentThickness <= 0.0: # should not be better to raise an exception if the # entered density or thickness were negative? self.setText(row, 4, "%g" % 0.1)
def _checkDensityThickness(self, text, row): try: currentDensity = float(str(self.text(row, 3))) except: currentDensity = 0.0 try: currentThickness = float(str(self.text(row, 4))) except: currentThickness = 0.0 defaultDensity = -1.0 defaultThickness = -0.1 #check if default density is there if Elements.isValidFormula(text): #check if single element if text in Elements.Element.keys(): defaultDensity = Elements.Element[text]['density'] else: elts = [w for w in re.split('[0-9]', text) if w != ''] nbs = [int(w) for w in re.split('[a-zA-Z]', text) if w != ''] if len(elts) == 1 and len(nbs) == 1: defaultDensity = Elements.Element[elts[0]]['density'] elif Elements.isValidMaterial(text): key = Elements.getMaterialKey(text) if key is not None: if 'Density' in Elements.Material[key]: defaultDensity = Elements.Material[key]['Density'] if 'Thickness' in Elements.Material[key]: defaultThickness = Elements.Material[key]['Thickness'] if defaultDensity >= 0.0: self.setText(row, 3, "%g" % defaultDensity) elif currentDensity <= 0: # should not be better to raise an exception if the # entered density or thickness were negative? self.setText(row, 3, "%g" % 1.0) if defaultThickness >= 0.0: self.setText(row, 4, "%g" % defaultThickness) elif currentThickness <= 0.0: # should not be better to raise an exception if the # entered density or thickness were negative? self.setText(row, 4, "%g" % 0.1)
def _mySlot(self, ddict): if ddict['event'] == "returnPressed": current = str(self.currentText()) current = current.replace(' ', '') if (current == '') or (current.upper() == 'AUTO'): pass elif len(current) == 2: current = current.upper()[0] + current.lower()[1] elif len(current) == 1: current = current.upper()[0] else: msg = qt.QMessageBox(self._lineEdit) msg.setIcon(qt.QMessageBox.Critical) msg.setText("Invalid Element %s" % current) msg.exec_() self._lineEdit.setFocus() if not Elements.isValidFormula(current): msg = qt.QMessageBox(self._lineEdit) msg.setIcon(qt.QMessageBox.Critical) msg.setText("Invalid Element %s" % current) msg.exec_() self._lineEdit.setFocus() else: self.setCurrentText(current)
def _mySignal(self, qstring0): qstring = qstring0 text = str(qstring0) if text == '-': return (result, index) = self.ownValidator.validate(qstring,0) if result != self.ownValidator.Valid: qstring = self.ownValidator.fixup(qstring) (result, index) = self.ownValidator.validate(qstring,0) if result != self.ownValidator.Valid: text = str(qstring) if text.endswith(" "): msg = qt.QMessageBox(self) msg.setIcon(qt.QMessageBox.Critical) msg.setText("Invalid Material Name '%s'\n" % text + \ "It ends with a space character.\n") msg.exec_() msg = qt.QMessageBox.No else: try: # this test is needed even if pyflakes complains float(text) msg = qt.QMessageBox(self) msg.setIcon(qt.QMessageBox.Critical) msg.setText("Invalid Material Name %s\n" % text + \ "You cannot use a number as material name.\n" +\ "Hint: You can use _%s_" % text) msg.exec_() msg = qt.QMessageBox.No except: msg=qt.QMessageBox.information( self, "Invalid Material %s" % str(qstring), "The material %s is not a valid Formula " \ "nor a valid Material.\n" \ "Do you want to define the material %s\n" % \ (str(qstring), str(qstring)), qt.QMessageBox.Yes,qt.QMessageBox.No) if msg == qt.QMessageBox.No: self.setCurrentIndex(0) for i in range(self.count()): selftext = self.itemText(i) if selftext == qstring0: self.removeItem(i) return else: qstring = qstring0 text = str(qstring) if Elements.isValidFormula(text): msg = qt.QMessageBox(self) msg.setIcon(qt.QMessageBox.Critical) msg.setText("Invalid Material Name %s\n" % text + \ "The material is a valid Formula.\n " \ "There is no need to define it.") msg.exec_() self.setCurrentIndex(0) for i in range(self.count()): selftext = self.itemText(i) if selftext == qstring0: self.removeItem(i) break return self.setCurrentText(text) self.lastText = text ddict = {} ddict['event'] = 'activated' ddict['row'] = self.row ddict['col'] = self.col ddict['text'] = text if qstring0 != qstring: self.removeItem(self.count()-1) insert = True for i in range(self.count()): selftext = self.itemText(i) if qstring == selftext: insert = False if insert: self.insertItem(self.count(), qstring) self.sigMaterialComboBoxSignal.emit(ddict)