          """ Open save dialogue and save preview """
          location = FileHandler("dir", None).return_file
          if not location:
              return
          for preview in self.subnotebook.children.values():
              preview.save_preview(location)
  
  
  class PreviewTrainCanvas(ttk.Frame):  # pylint: disable=too-many-ancestors
      """ Canvas to hold a training preview image
  
      Parameters
      ----------
      parent: :class:`tkinter.ttk.Notebook`
          The notebook that the training image canvas belongs to
      previewname: str
          The name of the preview image displayed in the canvas
      """
      def __init__(self, parent: ttk.Notebook, previewname: str) -> None:
          logger.debug("Initializing %s: (previewname: '%s')", self.__class__.__name__, previewname)
          ttk.Frame.__init__(self, parent)
  
          self.name = previewname
          get_images().resize_image(self.name, None)
          self.previewimage = get_images().previewtrain[self.name][1]
  
          self.canvas = tk.Canvas(self, bd=0, highlightthickness=0)
          self.canvas.pack(side=tk.TOP, fill=tk.BOTH, expand=True)
          self.imgcanvas = self.canvas.create_image(0,
                                                    0,
                                                    image=self.previewimage,
                                                    anchor=tk.NW)
          self.bind("<Configure>", self.resize)
          logger.debug("Initialized %s:", self.__class__.__name__)
  
      def resize(self, event: tk.Event) -> None:
          """  Resize the image to fit the frame, maintaining aspect ratio
  
          Parameters
          ----------
          event: :class:`tkinter.Event`
              The resize event object
 
</s> remove         Parameters
        ----------
        event: :class:`tkinter.Event`
            The resize event object
        """
        logger.trace("Resizing preview image")  # type:ignore
        framesize: Optional[Tuple[int, int]] = (event.width, event.height)
        # Sometimes image is resized before frame is drawn
        framesize = None if framesize == (1, 1) else framesize
        get_images().resize_image(self.name, framesize)
        self.reload()

    def reload(self) -> None:
        """ Reload the preview image """
        logger.trace("Reloading preview image")  # type:ignore
        self.previewimage = get_images().previewtrain[self.name][1]
        self.canvas.itemconfig(self.imgcanvas, image=self.previewimage)

    def save_preview(self, location: str) -> None:
        """ Save the figure to file.

        Parameters
        ----------
        location: str
            The full path to the location to save the preview image
        """
        filename = self.name
        now = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
        filename = os.path.join(location, f"{filename}_{now}.png")
        cast("Image.Image", get_images().previewtrain[self.name][0]).save(filename)
        logger.debug("Saved preview to %s", filename)
        print(f"Saved preview to {filename}")
 </s> add         self._display.save(location) </s> remove         Parameters
        ----------
        tab_id: int
            The index of the tab to update
        name: str
            The name of the tab to update
        """
        logger.debug("Updating preview")
        if self.vars["modified"].get() != get_images().previewtrain[name][2]:
            self.vars["modified"].set(get_images().previewtrain[name][2])
            widget = self.subnotebook_page_from_id(tab_id)
            widget.reload()
 </s> add         logger.debug("Displaying preview")
        self._display = PreviewTk(self._preview.buffer, self.subnotebook, self.optsframe, None)
        self.subnotebook_add_page(self.tabname, widget=self._display.master_frame) </s> remove         logger.trace("Displaying preview")  # type:ignore
        sortednames = sorted(list(get_images().previewtrain.keys()))
        existing = self.subnotebook_get_titles_ids()
        should_update = self.update_preview.get()

        for name in sortednames:
            if name not in existing:
                self.add_child(name)
            elif should_update:
                tab_id = existing[name]
                self.update_child(tab_id, name)

        if should_update:
            self.update_preview.set(False)

    def add_child(self, name: str) -> None:
        """ Add the preview canvas child

        Parameters
        ----------
        name: str
            The name of the notebook tab to add
        """
        logger.debug("Adding child")
        preview = PreviewTrainCanvas(self.subnotebook, name)
        preview = self.subnotebook_add_page(name, widget=preview)
        Tooltip(preview, text=self.helptext, wrap_length=200)
        self.vars["modified"].set(get_images().previewtrain[name][2])

    def update_child(self, tab_id: int, name: str) -> None:
        """ Update the preview canvas
 </s> add         if self.subnotebook.children:
            return </s> remove             widget.configure(image=get_images().previewoutput[1])
 </s> add             widget.configure(image=self._preview.image) </s> remove         Parameters
        ----------
        name: str
            The name of the training image to be resized
        frame_dims: tuple, optional
            The (width (`int`), height (`int`)) of the display panel that will display the preview.
            ``None`` if the frame dimensions are not known.
 </s> add         Should be called when terminating tasks, or when Faceswap starts up or shuts down.
          """ Open save dialogue and save preview """
          location = FileHandler("dir", None).return_file
          if not location:
              return

































  
          Parameters
          ----------
          event: :class:`tkinter.Event`
              The resize event object
keep keep keep keep replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace keep keep keep keep keep
 GUI - Preview updates
  - Training preview. Embed preview pop-out window
  - Bugfix - convert/extract previews 
lib/gui/display_command.py