Beispiel #1
0
    def bind_widget(self,
                    model: PresentationModel,
                    path: str,
                    connect_to_model=True) -> None:
        """
        connect_to_model=False means:
        - self: ColorText is created and owned by BoundColorWidget wrapper.
        - Wrapper forwards model changes to self (which updates other widgets).
            (model.update_widget[path] != self)
        - self.gui_changed invokes self.set_model() (which updates model
            AND other widgets).
        - wrapper.gui_changed signal is NEVER emitted.
        """
        try:
            self.default_palette = self.palette()
            self.error_palette = self.calc_error_palette()

            self.pmodel = model
            self.path = path
            self.cfg2gui()

            if connect_to_model:
                # Allow widget to be updated by other events.
                model.update_widget[path] = self.cfg2gui

            # Allow pmodel to be changed by widget.
            self.gui_changed.connect(self.set_model)

        except Exception:
            perr(self)
            perr(path)
            raise
Beispiel #2
0
def verify_res_divisor_rounding(
    target_int: int,
    res_divisor: float,
    speed_hack: bool,
):
    """Ensure that pathological-case float rounding errors
    don't cause inconsistent dimensions and assertion errors."""
    target_dim = target_int + 0.5
    undivided_dim = round(target_dim * res_divisor)

    cfg = RendererConfig(undivided_dim, undivided_dim, res_divisor=res_divisor)
    cfg.before_preview()

    with ExitStack() as stack:
        if speed_hack:
            stack.enter_context(
                patch.object(AbstractMatplotlibRenderer, "_save_background")
            )
            datas = []
        else:
            datas = [RENDER_Y_ZEROS]

        try:
            renderer = Renderer(cfg, LayoutConfig(), datas, None, None)
            if not speed_hack:
                renderer.update_main_lines(datas)
                renderer.get_frame()
        except Exception:
            perr(cfg.divided_width)
            raise