def updateGui(self): self._editMin1.setText(FloatToQString(self.dimMin[0])) self._editMin2.setText(FloatToQString(self.dimMin[1])) self._editMin3.setText(FloatToQString(self.dimMin[2])) self._editMin4.setText(FloatToQString(self.dimMin[3])) self._editMax1.setText(FloatToQString(self.dimMax[0])) self._editMax2.setText(FloatToQString(self.dimMax[1])) self._editMax3.setText(FloatToQString(self.dimMax[2])) self._editMax4.setText(FloatToQString(self.dimMax[3])) self._editStep1.setText(QString(format(self.dimStep[0], '.3f'))) self._editStep2.setText(QString(format(self.dimStep[1], '.3f')))
def data(self, index, role): if role == QtCore.Qt.EditRole: row = index.row() column = index.column() return QString(format(self.__UB[row][column], '.4f')) elif role == QtCore.Qt.DisplayRole: row = index.row() column = index.column() value = QString(format(self.__UB[row][column], '.4f')) return value elif role == QtCore.Qt.BackgroundRole: if ValidateUB(self.__UB): return QtGui.QBrush(QtCore.Qt.white) else: return QtGui.QBrush(QtCore.Qt.red)
def __init__(self, qtobj, position=None, depends=[], dtype=str, layout=None, **args): if isinstance(qtobj, str): # when given a string, convert to a label qtobj = QtWidgets.QLabel(qtobj) self.dtype = dtype if isinstance(qtobj, QtWidgets.QLineEdit) and dtype != str: if dtype in [float]: # , np.float]: validator = QtGui.QDoubleValidator() qtobj.setValidator(validator) args['validator'] = validator elif dtype in [int]: # , np.int]: validator = QtGui.QIntValidator() qtobj.setValidator(validator) args['validator'] = validator if isinstance(qtobj, QtWidgets.QComboBox) and 'choices' in args: args['choices'] = OrderedDict(args['choices']) for key, val in args['choices'].items(): qtobj.addItem(QString(key), val) super().__init__(qtobj=qtobj, depends=depends, **args) if layout is not None and position is not None: layout.addWidget(qtobj, *position)
def _qfiledialog_wrapper(attr, parent=None, caption='', basedir='', filters='', selectedfilter='', options=None): if options is None: options = QFileDialog.Options(0) try: # PyQt <v4.6 (API #1) from qtpy.QtCore import QString except ImportError: # PySide or PyQt >=v4.6 QString = None # analysis:ignore tuple_returned = True try: # PyQt >=v4.6 func = getattr(QFileDialog, attr+'AndFilter') except AttributeError: # PySide or PyQt <v4.6 func = getattr(QFileDialog, attr) if QString is not None: selectedfilter = QString() tuple_returned = False # Calling QFileDialog static method if sys.platform == "win32": # On Windows platforms: redirect standard outputs _temp1, _temp2 = sys.stdout, sys.stderr sys.stdout, sys.stderr = None, None try: result = func(parent, caption, basedir, filters, selectedfilter, options) except TypeError: # The selectedfilter option (`initialFilter` in Qt) has only been # introduced in Jan. 2010 for PyQt v4.7, that's why we handle here # the TypeError exception which will be raised with PyQt v4.6 # (see Issue 960 for more details) result = func(parent, caption, basedir, filters, options) finally: if sys.platform == "win32": # On Windows platforms: restore standard outputs sys.stdout, sys.stderr = _temp1, _temp2 # Processing output if tuple_returned: # PySide or PyQt >=v4.6 output, selectedfilter = result else: # PyQt <v4.6 (API #1) output = result if QString is not None: # PyQt API #1: conversions needed from QString/QStringList selectedfilter = to_text_string(selectedfilter) if isinstance(output, QString): # Single filename output = to_text_string(output) else: # List of filenames output = [to_text_string(fname) for fname in output] # Always returns the tuple (output, selectedfilter) return output, selectedfilter
def loadMaskFromFile(self): fileName = QtWidgets.QFileDialog.getOpenFileName( self, "Open Mask File", '', "Processed Nexus (*.nxs);;All Files (*)") if not fileName: return if isinstance(fileName, tuple): fileName = fileName[0] self.editMask.setText(QString(fileName)) self.setMaskFile()
def data(self, index, role): #pylint: disable=too-many-branches row = index.row() column = index.column() if role == QtCore.Qt.EditRole or role == QtCore.Qt.DisplayRole: if column==0: value=QString(self.labels[row]) elif column==1: value=QString(self.dirstrings[row]) elif column==2: value=QString(str(self.senses[row])) elif column==3: value=QString(str(self.minvalues[row])) elif column==4: value=QString(str(self.maxvalues[row])) elif column==5: value=QString(str(self.steps[row])) return value elif role == QtCore.Qt.BackgroundRole: brush=QtGui.QBrush(QtCore.Qt.white) if column==0 and len(self.labels[row])>0 and self.labels.count(self.labels[row])==1: pass elif column==1 and self.validDir(self.dirstrings[row]): pass elif column==2 and (self.senses[row]==1 or self.senses[row]==-1): pass elif (column==3 or column==4) and self.minvalues[row]<=self.maxvalues[row]: pass elif column==5 and self.steps[row]>0.1: pass else: brush=QtGui.QBrush(QtCore.Qt.red) return brush
def loadNexusUBDialog(self): # pylint: disable=bare-except try: fname = QtWidgets.QFileDialog.getOpenFileName( self, 'Open Nexus file to extract UB matrix', filter=QString('Nexus file (*.nxs.h5);;All Files (*)')) if isinstance(fname,tuple): fname=fname[0] if not fname: return __tempUB = LoadNexusUB(str(fname)) ol=mantid.geometry.OrientedLattice() ol.setUB(__tempUB) self.UBmodel.updateOL(ol) self.UBmodel.sendSignal() except Exception as e: mantid.logger.error("Could not open the Nexus file, or could not find UB matrix: {}".format(e))
def loadIsawUBDialog(self): # pylint: disable=bare-except try: fname = QtWidgets.QFileDialog.getOpenFileName( self, 'Open ISAW UB file', filter=QString('Mat file (*.mat);;All Files (*)')) if isinstance(fname, tuple): fname = fname[0] if not fname: return __tempws = mantid.simpleapi.CreateSingleValuedWorkspace(0.) mantid.simpleapi.LoadIsawUB(__tempws, str(fname)) ol = mantid.geometry.OrientedLattice( __tempws.sample().getOrientedLattice()) ol.setU(__tempws.sample().getOrientedLattice().getU()) self.UBmodel.updateOL(ol) self.UBmodel.sendSignal() mantid.simpleapi.DeleteWorkspace(__tempws) except Exception as e: mantid.logger.error( "Could not open the file, or not a valid UB matrix: {}".format( e))
def updateGui(self): self._edita.setText(QString(format(self.latt_a, '.5f'))) self._editb.setText(QString(format(self.latt_b, '.5f'))) self._editc.setText(QString(format(self.latt_c, '.5f'))) self._editalpha.setText(QString(format(self.latt_alpha, '.5f'))) self._editbeta.setText(QString(format(self.latt_beta, '.5f'))) self._editgamma.setText(QString(format(self.latt_gamma, '.5f'))) self._editux.setText(QString(format(self.latt_ux, '.5f'))) self._edituy.setText(QString(format(self.latt_uy, '.5f'))) self._edituz.setText(QString(format(self.latt_uz, '.5f'))) self._editvx.setText(QString(format(self.latt_vx, '.5f'))) self._editvy.setText(QString(format(self.latt_vy, '.5f'))) self._editvz.setText(QString(format(self.latt_vz, '.5f')))
def __init__(self, parent=None): # pylint: disable=unused-argument,super-on-old-class super(InstrumentSetupWidget, self).__init__() metrics = QtGui.QFontMetrics(self.font()) self.signaldict = dict() #instrument selector self.instrumentList = [ 'ARCS', 'CNCS', 'DNS', 'EXED', 'FOCUS', 'HET', 'HYSPEC', 'LET', 'MAPS', 'MARI', 'MERLIN', 'SEQUOIA' ] self.combo = QtWidgets.QComboBox(self) for inst in self.instrumentList: self.combo.addItem(inst) defaultInstrument = mantid.config.getInstrument().name() if defaultInstrument in self.instrumentList: self.instrument = defaultInstrument self.combo.setCurrentIndex( self.instrumentList.index(defaultInstrument)) else: self.instrument = self.instrumentList[0] self.combo.setCurrentIndex(0) self.signaldict['instrument'] = self.instrument self.labelInst = QtWidgets.QLabel('Instrument') #S2 and Ei edits self.S2 = 0.0 self.Ei = 10.0 self.signaldict['S2'] = self.S2 self.signaldict['Ei'] = self.Ei self.validatorS2 = QtGui.QDoubleValidator(-90., 90., 5, self) self.validatorEi = QtGui.QDoubleValidator(1., 10000., 5, self) self.labelS2 = QtWidgets.QLabel('S2') self.labelEi = QtWidgets.QLabel('Incident Energy') self.editS2 = QtWidgets.QLineEdit() self.editS2.setValidator(self.validatorS2) self.editEi = QtWidgets.QLineEdit() self.editEi.setValidator(self.validatorEi) self.editS2.setText(QString(format(self.S2, '.2f'))) self.editEi.setText(QString(format(self.Ei, '.1f'))) self.editEi.setFixedWidth(metrics.width("8888.88")) self.editS2.setFixedWidth(metrics.width("888.88")) #fast checkbox self.fast = QtWidgets.QCheckBox("Fast", self) self.fast.toggle() self.updateFast() #masking self.labelMask = QtWidgets.QLabel('Mask file') self.editMask = QtWidgets.QLineEdit() self.buttonMask = QtWidgets.QPushButton("LoadMask") #goniometer settings self.labelGon = QtWidgets.QLabel('Goniometer') self.tableViewGon = QtWidgets.QTableView(self) self.tableViewGon.setMinimumWidth(metrics.width("Minimum ") * 8) self.tableViewGon.horizontalHeader().setSectionResizeMode( QtWidgets.QHeaderView.Stretch) self.tableViewGon.verticalHeader().setSectionResizeMode( QtWidgets.QHeaderView.Stretch) self.goniometerNames = ['psi', 'gl', 'gs'] self.goniometerDirections = ['0,1,0', '0,0,1', '1,0,0'] self.goniometerRotationSense = [1, 1, 1] self.goniometerMin = [0., 0., 0.] self.goniometerMax = [0., 0., 0.] self.goniometerStep = [1., 1., 1.] values = { 'gonioLabels': self.goniometerNames, 'gonioDirs': self.goniometerDirections, 'gonioSenses': self.goniometerRotationSense, 'gonioMinvals': self.goniometerMin, 'gonioMaxvals': self.goniometerMax, 'gonioSteps': self.goniometerStep } self.goniomodel = GonioTableModel(values, self) self.tableViewGon.setModel(self.goniomodel) self.tableViewGon.update() self.signaldict.update(values) #goniometer figure self.figure = Figure(figsize=(2, 3)) self.figure.patch.set_facecolor('white') self.canvas = FigureCanvasQTAgg(self.figure) self.gonfig = None self.updateFigure() #layout self.gridI = QtWidgets.QGridLayout() self.gridI.addWidget(self.labelInst, 0, 0) self.gridI.addWidget(self.combo, 0, 1) self.gridI.addWidget(self.labelEi, 0, 2) self.gridI.addWidget(self.editEi, 0, 3) self.gridI.addWidget(self.labelS2, 0, 4) self.gridI.addWidget(self.editS2, 0, 5) self.gridI.addWidget(self.fast, 0, 6) self.setLayout(QtWidgets.QHBoxLayout()) self.rightside = QtWidgets.QVBoxLayout() self.maskLayout = QtWidgets.QHBoxLayout() self.maskLayout.addWidget(self.labelMask) self.maskLayout.addWidget(self.editMask) self.maskLayout.addWidget(self.buttonMask) self.layout().addLayout(self.rightside) self.rightside.addLayout(self.gridI) self.rightside.addLayout(self.maskLayout) self.rightside.addWidget(self.labelGon) self.rightside.addWidget(self.tableViewGon) self.layout().addWidget(self.canvas) #connections self.editS2.textEdited.connect(self.checkValidInputs) self.editMask.textEdited.connect(self.setMaskFile) self.combo.activated[str].connect(self.instrumentSelected) self.fast.stateChanged.connect(self.updateFast) self.buttonMask.clicked.connect(self.loadMaskFromFile) self.editEi.textEdited.connect(self.checkValidInputs) #call instrumentSelected once self.instrumentSelected(self.instrument) #connect goniometer change with figure self.goniomodel.changed.connect(self.updateFigure) self.updateAll()
def __init__(self, parent=None): # pylint: disable=unused-argument,super-on-old-class super(DimensionSelectorWidget, self).__init__() #validators self.doubleValidator = EmptyOrDoubleValidator(self) self.positiveDoubleValidator = QtGui.QDoubleValidator(self) self.positiveDoubleValidator.setBottom(1e-10) self.V3DValidator = V3DValidator(self) #labels self._labelBasis = QtWidgets.QLabel(' Projection Basis') self._labelBasis1 = QtWidgets.QLabel(' Projection u') self._labelBasis2 = QtWidgets.QLabel(' Projection v') self._labelBasis3 = QtWidgets.QLabel(' Projection w') self._labelMin = QtWidgets.QLabel('Min') self._labelMax = QtWidgets.QLabel('Max') self._labelStep = QtWidgets.QLabel('Step') #lineedits self._editBasis1 = QtWidgets.QLineEdit() self._editBasis1.setValidator(self.V3DValidator) self._editBasis2 = QtWidgets.QLineEdit() self._editBasis2.setValidator(self.V3DValidator) self._editBasis3 = QtWidgets.QLineEdit() self._editBasis3.setValidator(self.V3DValidator) self._editMin1 = QtWidgets.QLineEdit() self._editMin1.setValidator(self.doubleValidator) self._editMin2 = QtWidgets.QLineEdit() self._editMin2.setValidator(self.doubleValidator) self._editMin3 = QtWidgets.QLineEdit() self._editMin3.setValidator(self.doubleValidator) self._editMin4 = QtWidgets.QLineEdit() self._editMin4.setValidator(self.doubleValidator) self._editMax1 = QtWidgets.QLineEdit() self._editMax1.setValidator(self.doubleValidator) self._editMax2 = QtWidgets.QLineEdit() self._editMax2.setValidator(self.doubleValidator) self._editMax3 = QtWidgets.QLineEdit() self._editMax3.setValidator(self.doubleValidator) self._editMax4 = QtWidgets.QLineEdit() self._editMax4.setValidator(self.doubleValidator) self._editStep1 = QtWidgets.QLineEdit() self._editStep1.setValidator(self.positiveDoubleValidator) self._editStep2 = QtWidgets.QLineEdit() self._editStep2.setValidator(self.positiveDoubleValidator) self._comboDim1 = QtWidgets.QComboBox(self) self._comboDim2 = QtWidgets.QComboBox(self) self._comboDim3 = QtWidgets.QComboBox(self) self._comboDim4 = QtWidgets.QComboBox(self) self._comboDim4.setMinimumContentsLength(12) #basis self.basis = ['1,0,0', '0,1,0', '0,0,1'] #default values self.dimNames = ['[H,0,0]', '[0,K,0]', '[0,0,L]', 'DeltaE'] self.dimMin = [-numpy.inf, -numpy.inf, -numpy.inf, -numpy.inf] self.dimMax = [numpy.inf, numpy.inf, numpy.inf, numpy.inf] self.dimStep = [0.05, 0.05, 0.05, 1] self.dimIndex = [0, 1, 2, 3] #layout grid = QtWidgets.QGridLayout() self.setLayout(grid) grid.addWidget(self._labelMin, 0, 1) grid.addWidget(self._labelMax, 0, 2) grid.addWidget(self._labelStep, 0, 3) grid.addWidget(self._labelBasis, 0, 4, 1, 2) grid.addWidget(self._comboDim1, 1, 0) grid.addWidget(self._editMin1, 1, 1) grid.addWidget(self._editMax1, 1, 2) grid.addWidget(self._editStep1, 1, 3) grid.addWidget(self._labelBasis1, 1, 4) grid.addWidget(self._editBasis1, 1, 5) grid.addWidget(self._comboDim2, 2, 0) grid.addWidget(self._editMin2, 2, 1) grid.addWidget(self._editMax2, 2, 2) grid.addWidget(self._editStep2, 2, 3) grid.addWidget(self._labelBasis2, 2, 4) grid.addWidget(self._editBasis2, 2, 5) grid.addWidget(self._comboDim3, 3, 0) grid.addWidget(self._editMin3, 3, 1) grid.addWidget(self._editMax3, 3, 2) grid.addWidget(self._labelBasis3, 3, 4) grid.addWidget(self._editBasis3, 3, 5) grid.addWidget(self._comboDim4, 4, 0) grid.addWidget(self._editMin4, 4, 1) grid.addWidget(self._editMax4, 4, 2) self._editBasis1.setText(QString(self.basis[0])) self._editBasis2.setText(QString(self.basis[1])) self._editBasis3.setText(QString(self.basis[2])) self.updateCombo() self.updateGui() #connections self._editBasis1.textEdited.connect(self.basisChanged) self._editBasis2.textEdited.connect(self.basisChanged) self._editBasis3.textEdited.connect(self.basisChanged) self._editMin1.textEdited.connect(self.limitsChanged) self._editMin2.textEdited.connect(self.limitsChanged) self._editMin3.textEdited.connect(self.limitsChanged) self._editMin4.textEdited.connect(self.limitsChanged) self._editMax1.textEdited.connect(self.limitsChanged) self._editMax2.textEdited.connect(self.limitsChanged) self._editMax3.textEdited.connect(self.limitsChanged) self._editMax4.textEdited.connect(self.limitsChanged) self._editStep1.textEdited.connect(self.stepChanged) self._editStep2.textEdited.connect(self.stepChanged) self._comboDim1.currentIndexChanged.connect(self.comboChanged) self._comboDim2.currentIndexChanged.connect(self.comboChanged) self._comboDim3.currentIndexChanged.connect(self.comboChanged) self._comboDim4.currentIndexChanged.connect(self.comboChanged) self.inhibitSignal = False self.updateChanges()
def FloatToQString(value): if numpy.isfinite(value): return QString(format(value, '.3f')) else: return QString("")
def set_text(self, value): value = QString(str(value)) self['qtobj'].setText(value)