Exemplo n.º 1
0
 def _select_editability_for_resolvertype(self, editable):
     if editable is not ParameterEditability.NotEditable():
         if self.type == ResolverTypes.Static():
             self.set_value_editability(ParameterEditability.Editable)
         elif self.type == ResolverTypes.Local():
             self.set_value_editability(ParameterEditability.Selectable)
         else:
             self.set_value_editability(ParameterEditability.Editable)
Exemplo n.º 2
0
    def _prepare_input_parameter(value, type):
        if type == ResolverTypes.Static() or ResolverTypes.Remote() in type:
            return value
        else:
            if PARAM_PREFIX in value:
                return value

            value_parts = value.split('.')
            return f'{PARAM_PREFIX}{value_parts[0]}.op.{value_parts[1]}'
Exemplo n.º 3
0
    def _set_validity_flag(self, type):
        convertable = True
        try:
            float(self.value.get_value())
        except Exception:
            convertable = False

        self.value.set_validity(ParameterState.Valid())
        if type == ResolverTypes.Static() and not convertable:
            self.value.set_value(self.default.get_value())
        if type == ResolverTypes.Local() and convertable:
            self.value.set_validity(ParameterState.Invalid())
        if ResolverTypes.Remote() in type:
            self.value.set_validity(ParameterState.Valid())
Exemplo n.º 4
0
    def get_value(self):
        # we do not need to format the value in case of type local as it is not
        # a decimal number
        if self.type.get_value() == ResolverTypes.Local():
            return self.value.get_value()

        return float(self.format_value(self.value))
Exemplo n.º 5
0
    def set_value(self, value):
        self.value.set_validity(ParameterState.Valid())
        if self.type.get_value() == ResolverTypes.Static():
            resolver_type = ResolverTypes.Static()
            formatted = self.format_value(value)
            self.value.set_value(formatted)

            if self.min > float(value) or float(value) > self.max:
                self.value.set_validity(ParameterState.Invalid())
        elif self.type.get_value() == ResolverTypes.Local():
            resolver_type = ResolverTypes.Local()
            self.value.set_value(value)
        else:
            # Remote!
            resolver_type = self.type.get_value()
            self.value(value)

        self._set_validity_flag(resolver_type)
Exemplo n.º 6
0
    def __init__(self, name, input_params):
        editable = ParameterEditability.Editable()

        if name == 'Temperature':
            editable = ParameterEditability.NotEditable()

        self.name = ParameterField(name)
        self.min = ParameterField(input_params['Min'])
        self.max = ParameterField(input_params['Max'])
        self.format = ParameterField(input_params['fmt'])
        self.unit = ParameterField(input_params['Unit'])
        self.exponent = ParameterField(input_params['10рхА'])
        self.type = self.InputParameterFieldType(
            ResolverTypes.Static()
            if input_params.get('type') is None else input_params['type'],
            editable=editable)
        self.default = ParameterField(self.format_value(
            input_params['Default']),
                                      editable=editable)
        self.value = copy.deepcopy(self.default) if input_params.get(
            'value') is None else ParameterField(self._get_value(input_params))
        self.valid = True

        self._select_editability_for_resolvertype(editable)
Exemplo n.º 7
0
 def _get_validator_type(self) -> str:
     if ResolverTypes.Remote() in self.type.get_value():
         return ValidatorTypes.NoValidation
     else:
         return ValidatorTypes.FloatValidation