                  cv2.imwrite(imgfile, image)  # pylint: disable=no-member
                  logger.debug("Generated preview for GUI: '%s'", imgfile)
              if self._args.preview:
                  logger.debug("Generating preview for display: '%s'", name)
                  self._preview.add_image(name, image)
                  logger.debug("Generated preview for display: '%s'", name)
          except Exception as err:
              logging.error("could not preview sample")
              raise err
          logger.debug("Updated preview: (name: %s)", name)
 
</s> remove class Preview():
    """ Holds the pop up preview window and options relating to the preview in the window and the
    GUI. Thread safe to take requests from the main thread and the training thread. """
    def __init__(self) -> None:
        self._lock = Lock()
        self._dpi: float = 0.0
        self._triggers: Dict[str, bool] = dict(toggle_mask=False,
                                               full_size=False,
                                               refresh=False,
                                               save=False,
                                               quit=False)
        self._needs_update: bool = False
        self._preview_buffer: Dict[str, np.ndarray] = {}
        self._images: Dict[str, Tuple[figure.Figure, Tuple[float, float]]] = {}
        self._resize_ids: List[Tuple[figure.Figure, int]] = []
        self._callbacks = dict(f="full_size",
                               m="toggle_mask",
                               r="refresh",
                               s="save",
                               enter="quit")
        self._configure_matplotlib()

    def _toggle_size(self) -> None:  # pylint:disable=unused-argument
        """ Toggle between actual size and screen-fit size. """
        self._triggers["full_size"] = not self._triggers["full_size"]
        self._set_resize_callback()

    @classmethod
    def _configure_matplotlib(cls):
        """ Remove `F`, 'S' and 'R' from their default bindings and stop Matplotlib from stealing
        focus """
        rcParams["keymap.fullscreen"] = [k for k in rcParams["keymap.fullscreen"] if k != "f"]
        rcParams["keymap.save"] = [k for k in rcParams["keymap.save"] if k != "s"]
        rcParams["keymap.home"] = [k for k in rcParams["keymap.home"] if k != "r"]
        rcParams["figure.raise_window"] = False
 </s> add class PreviewInterface():
    """ Run the preview window in a thread and interface with it </s> remove 
 </s> add                 retval[trigger] = True </s> remove                 if trigger == "update":
                    print("\n")  # Let log print on different line from loss output
 </s> add                 if trigger == "refresh":
                    print("")  # Let log print on different line from loss output </s> remove         parent_flags = dict(mask_toggle="request_mask_toggle", update="request_refresh")
        for trigger in ("mask_toggle", "update"):
            filename = self._gui_triggers[trigger]
 </s> add         for trigger, filename in self._gui_triggers.items():
                self._preview.buffer.add_image(name, image)
                  cv2.imwrite(imgfile, image)  # pylint: disable=no-member
                  logger.debug("Generated preview for GUI: '%s'", imgfile)
              if self._args.preview:
                  logger.debug("Generating preview for display: '%s'", name)
                self._preview.buffer.add_image(name, image)
                  logger.debug("Generated preview for display: '%s'", name)
          except Exception as err:
              logging.error("could not preview sample")
              raise err
          logger.debug("Updated preview: (name: %s)", name)
keep keep keep keep replace keep keep keep keep keep
 Training - Use custom preview pop-out 
scripts/train.py