Labsmore / pyuscope

Python machine vision platform
BSD 2-Clause "Simplified" License
80 stars 17 forks source link

Read-only controls are created read-write #427

Open philpem opened 9 months ago

philpem commented 9 months ago

This turned up while I was working on my Pi Camera (picamera2 library) fork, https://github.com/philpem/pyuscope-rpicam .

The Pi Camera auto white balance algorithm provides a read-only estimate of the colour temperature. I thought it would be useful to display on the UI, so I added it to the parameter list with the ro and gui_driven properties set accordingly:

                {
                    # This is the colour temperature (estimated by AWB), and is read-only
                    "prop_name": "ColourTemperature",
                    "disp_name": "Colour temperature (Kelvin, estimated by AWB)",
                    "min": 1000,
                    "max": 10000,

                    # FIXME: For some reason this doesn't work and a hacky fix was added below (search for ColourTempFix)
                    "ro": True,
                    "gui_driven": False,
                }

This was added to the UI okay, but the slider control was left enabled (read-write). If it's clicked, the GUI ends up fighting the camera (if AWB is on) or giving a useless reading (if AWB is off).

I've tried various combinations of ro and gui_driven, but the control stubbornly stayed enabled.

This (added to the ImagerControlScroll subclass) works as a workaround, but it's a bit hacky:

    def _raw_prop_write(self, name, val):
        # self.log(f"PiCam2ICS._RawPropWrite {name} => {val}")

        # Disable read-only indicators
        # FIXME (ColourTempFix): Figure out why this is necessary, gui_driven (in the 'group' OrderedDict) should have done this
        self.set_gui_driven(False, disp_names=['Colour temperature (Kelvin, estimated by AWB)'])