`EnabledIf` attribute with custom datatypes (enums) in Python

It seems, there’s an issue with EnabledIf attribute in Python. It works in case a boolean property is used for the condition, but using e.g. an enum causes Cannot emit a CustomAttribute with argument of type Python.Runtime.PyObject. error.

Just in case, we specify it in the following way:
add_attribute(OpenTap.EnabledIf("parameter", Parameter.VALUE1, HideIfDisabled=True))

We’re using Python plugin v3.0.2. It worked fine with Python v2 plugin.

1 Like

Hi @tatiana.boye,

I can see how this would be a problem. There is no obvious way to translate a Python enum in to a C# object, but I guess in the case of attributes we can assume a string. Generally that might cause some trouble later because that string will not be able to translate back into Python.

In v2 it worked because we explicitly translated the object to a C# enum, but in v3 we leave more work to Pythonnet,

In any case the best is probably file an issue on github.

Adding a link to the issue here for traceability: `EnabledIf` attribute with custom datatypes (e.g. enums) · Issue #121 · opentap/OpenTap.Python · GitHub

1 Like

Any updates on the status of this issue?

there is a workaround:

from opentap import property as opentap_property, attribute

...

parameter = opentap_property(Parameter, Parameter.VALUE1) \
        .add_attribute(OpenTap.Display("Parameter Name"))

@opentap_property(String)
@attribute(Browsable(False))
def parameter_str(self) -> str:
    return str(self.parameter)

depending_parameter = opentap_property(Double, 0) \
    .add_attribute(OpenTap.Display("Depending Parameter")) \
    .add_attribute(OpenTap.EnabledIf("parameter_str", "VALUE1", HideIfDisabled=False))
2 Likes