Esempio 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)
Esempio 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]}'
Esempio n. 3
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)
Esempio n. 4
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())
Esempio n. 5
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)