Beispiel #1
0
 def __init__(self, parent, client, options):
     GenericSamplePanel.__init__(self, parent, client, options)
     params = client.eval('session.experiment.sample.cell.cellparams()',
                          None)
     if params:
         lattice = params[:3]
         angles = params[3:6]
     else:
         lattice = [5] * 3
         angles = [90] * 3
     self.latticeEdit = typedvalue.create(self, vec3, lattice)
     self.angleEdit = typedvalue.create(self, vec3, angles)
     self.gridLayout.addWidget(self.latticeEdit, 2, 1)
     self.gridLayout.addWidget(self.angleEdit, 3, 1)
Beispiel #2
0
 def createParameterWidget(self, param, value):
     isUnkownValue = False
     try:
         typ = self.myClass.parameters[param].type
     except (AttributeError, KeyError):
         if isinstance(value, string_types):
             isUnkownValue = False
         else:
             isUnkownValue = True
         typ = type(value)
         if typ is None:
             typ = str
     try:
         myUnit = self.myClass.parameters[param].unit
     except (AttributeError, KeyError):
         myUnit = ''
     newParam = DeviceParam(param, create(self, typ, value, unit=myUnit))
     newParam.isUnknownValue = isUnkownValue
     try:
         newParam.labelParam.setToolTip(
             self.myClass.parameters[param].description)
     except:  # pylint: disable=bare-except
         newParam.labelParam.setToolTip('No info found.')
     try:
         mandatory = self.myClass.parameters[param].mandatory
     except (AttributeError, KeyError):
         mandatory = False
     if mandatory:
         newParam.pushButtonRemove.setVisible(False)
         newParam.placeholder.setVisible(True)
     newParam.editedParam.connect(self.editedDevice.emit)
     newParam.clickedRemoveButton.connect(self.removeParam)
     return newParam
Beispiel #3
0
 def createWidget(self, parent, client):
     self._widget = typedvalue.create(parent,
                                      self._valuetype,
                                      self.value,
                                      allow_enter=False)
     self._widget.valueModified.connect(self._updateValue)
     return self._widget
Beispiel #4
0
    def loadDevice(self, device):
        self.clear()
        errors = []
        try:
            self.myClass = self.getClassOfDevice(device)
        except KeyError as e:
            errors.append('Failed to load class ' + str(e))
        if errors:
            QMessageBox.warning(self, 'Errors', '\n'.join(errors))
            self.pushButtonAdd.setEnabled(False)
            return

        classParam = DeviceParam('Class', create(self, str,
                                                 device.classString))
        classParam.pushButtonRemove.setVisible(False)
        classParam.placeholder.setVisible(True)
        classParam.valueWidget.setEnabled(False)
        self.parametersLayout.addWidget(classParam)
        self.parameters['Class'] = classParam

        mandatoryParams = []
        optionalParams = []
        for param in sorted(device.parameters):
            try:
                mandatory = self.myClass.parameters[param].mandatory
            except (AttributeError, KeyError):
                mandatory = False
            if mandatory:
                mandatoryParams.append(param)
            else:
                optionalParams.append(param)

        for param in mandatoryParams:
            value = device.parameters[param]
            newParam = self.createParameterWidget(param, value)
            self.parametersLayout.addWidget(newParam)
            self.parameters[param] = newParam
        for param in optionalParams:
            value = device.parameters[param]
            newParam = self.createParameterWidget(param, value)
            self.parametersLayout.addWidget(newParam)
            self.parameters[param] = newParam

        self.parametersLayout.addStretch()
        self.setOptimalWidth()