def set_gui(self, value: Optional[str]): """model2gui""" if self.optional and not value: value = "" else: value = color2hex(value) # raises CorrError if invalid. # Don't write back to model immediately. # Loading is a const process, only editing the GUI should change the model. with qc.QSignalBlocker(self): self.setText(value) # Write to other GUI widgets immediately. self.hex_color.emit(value) # calls button.set_color()
def set_model(self: BoundWidget, value: str): """gui2model""" if self.optional and not value: value = None else: try: value = color2hex(value) except CorrError: self.setPalette(self.error_palette) self.hex_color.emit("") # calls button.set_color() return self.setPalette(self.default_palette) self.hex_color.emit(value or "") # calls button.set_color() self.pmodel[self.path] = value
def __init__(self, channels: List[ChannelConfig]): """ Mutates `channels` and `line_color` for convenience. """ super().__init__() self.channels = channels line_color = "line_color" for cfg in self.channels: t = cfg.trigger if isinstance(t, MainTriggerConfig): if not isinstance(t, CorrelationTriggerConfig): raise CorrError(f"Loading per-channel {obj_name(t)} not supported") trigger_dict = attr.asdict(t) else: trigger_dict = dict(t or {}) if line_color in trigger_dict: trigger_dict[line_color] = color2hex(trigger_dict[line_color]) cfg.trigger = trigger_dict