SentioProberDev / SentioProberControl

Python bindings for controlling MPI probe stations
https://ast.mpi-corporation.com/
BSD 2-Clause "Simplified" License
5 stars 6 forks source link

Support with String input #9

Closed BRDMYuhan closed 5 months ago

BRDMYuhan commented 6 months ago

Hi MPI developers,

Thanks for developing such exceptional drivers for probers. I would suggest an enhancement that could further improve the usability and accessibility of your drivers. I have developed some code modifications that I believe will make the drivers more intuitive and user-friendly, both for beginners and advanced users alike. Is it something on your schedule or I can open a PR.

for example:

def get_probe_xy(
        self,
        probe: Union[ProbeSentio, str],
        ref: Union[ProbeXYReference, str, None] = ProbeXYReference.Home,
    ) -> Tuple[float, float]:
"""Get probe xy position in micrometer.

        Args:
            probe: The probe to get the position for.
            ref: The position reference for the returned values. Default Home

        Returns:
            A tuple containing the x and y position in micrometer.

        Notes:
            str input can allow all attributes of ProbeSentio and/or ProbeXYReference. (Case Sensitive)

        """
        if isinstance(probe, str):
            probe = getattr(ProbeSentio, probe)
        if isinstance(ref, str):
            ref = getattr(ProbeXYReference, ref)

        self.__comm.send(
            "get_positioner_xy {0},{1}".format(probe.toSentioAbbr(), ref.toSentioAbbr())
        )
        resp = Response.check_resp(self.__comm.read_line())
        tok = resp.message().split(",")
        return float(tok[0]), float(tok[1])
beltoforion commented 5 months ago

The decision to limit the arguments to an enumerator was deliberate because it makes submitting something invalid more unlikely. When accepting strings it would not be immediately obvious what the valid strings are and wether strings are case sensitive or not.

Did you have an issue with wanting to submit something that is not available in the enumerator?

BRDMYuhan commented 5 months ago

No, actually I have no issue when submitting what is in the enumerator. However, it is not quite easy for beginners to understand what should they put in and makes the scripts less readable. Actually, if accepting strings, we can rely on getattr() to check if the stings are problematic or not.

beltoforion commented 5 months ago

Thanks for your feedback. We choose the enumerator because an editor like visual studio code should give you auto complete functionality for the enumerations.

Then its pretty much just using auto complete and select the proper value from a combo box. However this would require to import all enums like:

from sentio_prober_control.Sentio.Enumerations import *