balthazarneveu / interactive_pipe

create interactive image processing pipeline with friendly sliders
The Unlicense
8 stars 1 forks source link

Match widget with pipeline.parameters back & forth #18

Open balthazarneveu opened 1 year ago

balthazarneveu commented 1 year ago

To force a value back in the UI when reloading a tuning, you need to update the Control values... not only the parameters dictionary.

Need to get rid of this ugly bit of code in mpl & qt

    def load_parameters(self):
        """import parameters dictionary from a yaml/json file on disk"""
        super().load_parameters()
        self.window.need_redraw = True
        # @TODO: issue #18 - https://github.com/balthazarneveu/interactive_pipe/issues/18
        # Requires mapping the parameters back into each Control objects
        print("------------")
        for widget_idx, widget in self.window.ctrl.items():
            matched = False
            for filtname, params in self.pipeline.parameters.items():
                for param_name in params.keys():
                    if param_name == widget.parameter_name_to_connect:
                        print(f"MATCH & update {filtname} {widget_idx} with {self.pipeline.parameters[filtname][param_name]}")
                        self.window.ctrl[widget_idx].update(self.pipeline.parameters[filtname][param_name])
                        matched = True
            assert matched, f"could not match widget {widget_idx} with parameter to connect {widget.parameter_name_to_connect}"
        print("------------")
        self.window.reset_sliders()
balthazarneveu commented 1 year ago

To clarify things right now, each GUI has a self.ctrl which is basically a different view (a dict) of self.pipeline.slider


self.ctrl = {slider_name1: slider1 , ... } where slider_name1 = slider1.name self.pipeline.slider = [ slider1, slider2, ....]