              cache = samples[-num_images:]
          else:
              logger.debug("Appending to existing cache")
              cache = np.concatenate((cache, samples))[-num_images:]
          self.previewcache["images"] = cache
          logger.debug("Cache shape: %s", self.previewcache["images"].shape)
  
      @staticmethod
      def get_preview_samples(imagefiles, num_images, thumbnail_size):
          """ Return a subset of the imagefiles images
              Exclude final file so we don't accidentally load a file that is being saved """
          logger.debug("num_images: %s", num_images)
          samples = list()
          start_idx = len(imagefiles) - (num_images + 1)
          end_idx = len(imagefiles) - 1
          logger.debug("start_idx: %s, end_idx: %s", start_idx, end_idx)
          show_files = sorted(imagefiles, key=os.path.getctime)[start_idx: end_idx]
          for fname in show_files:
              img = Image.open(fname)
              width, height = img.size
              scaling = thumbnail_size / max(width, height)
              logger.debug("image width: %s, height: %s, scaling: %s", width, height, scaling)
              img = img.resize((int(width * scaling), int(height * scaling)))
              if img.size[0] != img.size[1]:
                  # Pad to square
                  new_img = Image.new("RGB", (thumbnail_size, thumbnail_size))
                  new_img.paste(img, ((thumbnail_size - img.size[0])//2,
                                      (thumbnail_size - img.size[1])//2))
                  img = new_img
              draw = ImageDraw.Draw(img)
              draw.rectangle(((0, 0), (thumbnail_size, thumbnail_size)), outline="#E5E5E5", width=1)
              samples.append(np.array(img))
          samples = np.array(samples)
          logger.debug("Samples shape: %s", samples.shape)
          return show_files, samples
  
      def place_previews(self, frame_dims):
          """ Stack the preview images to fit display """
          if self.previewcache.get("images", None) is None:
              logger.debug("No images in cache. Returning None")
              return None
          samples = self.previewcache["images"].copy()
          num_images, thumbnail_size = samples.shape[:2]
          if self.previewcache["placeholder"] is None:
 
</s> remove         start_idx = len(imagefiles) - num_images if len(imagefiles) > num_images else 0
        show_files = sorted(imagefiles, key=os.path.getctime)[start_idx:]
 </s> add         start_idx = len(image_files) - num_images if len(image_files) > num_images else 0
        show_files = sorted(image_files, key=os.path.getctime)[start_idx:] </s> remove         samples = self.previewcache["images"].copy()
 </s> add         samples = self._previewcache["images"].copy() </s> remove         self.previewcache["filenames"] = (self.previewcache["filenames"] +
                                          show_files)[-num_images:]
        cache = self.previewcache["images"]
 </s> add         self._previewcache["filenames"] = (self._previewcache["filenames"] +
                                           show_files)[-num_images:]
        cache = self._previewcache["images"] </s> remove         if self.previewcache["placeholder"] is None:
            self.create_placeholder(thumbnail_size)
 </s> add         if self._previewcache["placeholder"] is None:
            self._create_placeholder(thumbnail_size) </s> remove         self.previewcache["placeholder"] = placeholder
 </s> add         self._previewcache["placeholder"] = placeholder
        self._previewcache["images"] = cache
        logger.debug("Cache shape: %s", self._previewcache["images"].shape)

    def _place_previews(self, frame_dims):
        """ Format the preview thumbnails stored in the cache into a grid fitting the display
        panel.

        Parameters
        ----------
        frame_dims: tuple
            The (width (`int`), height (`int`)) of the display panel that will display the preview

        Returns
        :class:`PIL.Image`:
            The final preview display image
        """
        if self._previewcache.get("images", None) is None:
              cache = samples[-num_images:]
          else:
              logger.debug("Appending to existing cache")
              cache = np.concatenate((cache, samples))[-num_images:]
        self._previewcache["images"] = cache
        logger.debug("Cache shape: %s", self._previewcache["images"].shape)

    def _place_previews(self, frame_dims):
        """ Format the preview thumbnails stored in the cache into a grid fitting the display
        panel.

        Parameters
        ----------
        frame_dims: tuple
            The (width (`int`), height (`int`)) of the display panel that will display the preview

        Returns
        :class:`PIL.Image`:
            The final preview display image
        """
        if self._previewcache.get("images", None) is None:
        self._previewcache["images"] = cache
        logger.debug("Cache shape: %s", self._previewcache["images"].shape)

    def _place_previews(self, frame_dims):
        """ Format the preview thumbnails stored in the cache into a grid fitting the display
        panel.

        Parameters
        ----------
        frame_dims: tuple
            The (width (`int`), height (`int`)) of the display panel that will display the preview

        Returns
        :class:`PIL.Image`:
            The final preview display image
        """
        if self._previewcache.get("images", None) is None:
        self._previewcache["images"] = cache
        logger.debug("Cache shape: %s", self._previewcache["images"].shape)

    def _place_previews(self, frame_dims):
        """ Format the preview thumbnails stored in the cache into a grid fitting the display
        panel.

        Parameters
        ----------
        frame_dims: tuple
            The (width (`int`), height (`int`)) of the display panel that will display the preview

        Returns
        :class:`PIL.Image`:
            The final preview display image
        """
        if self._previewcache.get("images", None) is None:
        self._previewcache["images"] = cache
        logger.debug("Cache shape: %s", self._previewcache["images"].shape)

    def _place_previews(self, frame_dims):
        """ Format the preview thumbnails stored in the cache into a grid fitting the display
        panel.

        Parameters
        ----------
        frame_dims: tuple
            The (width (`int`), height (`int`)) of the display panel that will display the preview

        Returns
        :class:`PIL.Image`:
            The final preview display image
        """
        if self._previewcache.get("images", None) is None:
        self._previewcache["images"] = cache
        logger.debug("Cache shape: %s", self._previewcache["images"].shape)

    def _place_previews(self, frame_dims):
        """ Format the preview thumbnails stored in the cache into a grid fitting the display
        panel.

        Parameters
        ----------
        frame_dims: tuple
            The (width (`int`), height (`int`)) of the display panel that will display the preview

        Returns
        :class:`PIL.Image`:
            The final preview display image
        """
        if self._previewcache.get("images", None) is None:
        self._previewcache["images"] = cache
        logger.debug("Cache shape: %s", self._previewcache["images"].shape)

    def _place_previews(self, frame_dims):
        """ Format the preview thumbnails stored in the cache into a grid fitting the display
        panel.

        Parameters
        ----------
        frame_dims: tuple
            The (width (`int`), height (`int`)) of the display panel that will display the preview

        Returns
        :class:`PIL.Image`:
            The final preview display image
        """
        if self._previewcache.get("images", None) is None:
        self._previewcache["images"] = cache
        logger.debug("Cache shape: %s", self._previewcache["images"].shape)

    def _place_previews(self, frame_dims):
        """ Format the preview thumbnails stored in the cache into a grid fitting the display
        panel.

        Parameters
        ----------
        frame_dims: tuple
            The (width (`int`), height (`int`)) of the display panel that will display the preview

        Returns
        :class:`PIL.Image`:
            The final preview display image
        """
        if self._previewcache.get("images", None) is None:
        self._previewcache["images"] = cache
        logger.debug("Cache shape: %s", self._previewcache["images"].shape)

    def _place_previews(self, frame_dims):
        """ Format the preview thumbnails stored in the cache into a grid fitting the display
        panel.

        Parameters
        ----------
        frame_dims: tuple
            The (width (`int`), height (`int`)) of the display panel that will display the preview

        Returns
        :class:`PIL.Image`:
            The final preview display image
        """
        if self._previewcache.get("images", None) is None:
        self._previewcache["images"] = cache
        logger.debug("Cache shape: %s", self._previewcache["images"].shape)

    def _place_previews(self, frame_dims):
        """ Format the preview thumbnails stored in the cache into a grid fitting the display
        panel.

        Parameters
        ----------
        frame_dims: tuple
            The (width (`int`), height (`int`)) of the display panel that will display the preview

        Returns
        :class:`PIL.Image`:
            The final preview display image
        """
        if self._previewcache.get("images", None) is None:
        self._previewcache["images"] = cache
        logger.debug("Cache shape: %s", self._previewcache["images"].shape)

    def _place_previews(self, frame_dims):
        """ Format the preview thumbnails stored in the cache into a grid fitting the display
        panel.

        Parameters
        ----------
        frame_dims: tuple
            The (width (`int`), height (`int`)) of the display panel that will display the preview

        Returns
        :class:`PIL.Image`:
            The final preview display image
        """
        if self._previewcache.get("images", None) is None:
        self._previewcache["images"] = cache
        logger.debug("Cache shape: %s", self._previewcache["images"].shape)

    def _place_previews(self, frame_dims):
        """ Format the preview thumbnails stored in the cache into a grid fitting the display
        panel.

        Parameters
        ----------
        frame_dims: tuple
            The (width (`int`), height (`int`)) of the display panel that will display the preview

        Returns
        :class:`PIL.Image`:
            The final preview display image
        """
        if self._previewcache.get("images", None) is None:
        self._previewcache["images"] = cache
        logger.debug("Cache shape: %s", self._previewcache["images"].shape)

    def _place_previews(self, frame_dims):
        """ Format the preview thumbnails stored in the cache into a grid fitting the display
        panel.

        Parameters
        ----------
        frame_dims: tuple
            The (width (`int`), height (`int`)) of the display panel that will display the preview

        Returns
        :class:`PIL.Image`:
            The final preview display image
        """
        if self._previewcache.get("images", None) is None:
        self._previewcache["images"] = cache
        logger.debug("Cache shape: %s", self._previewcache["images"].shape)

    def _place_previews(self, frame_dims):
        """ Format the preview thumbnails stored in the cache into a grid fitting the display
        panel.

        Parameters
        ----------
        frame_dims: tuple
            The (width (`int`), height (`int`)) of the display panel that will display the preview

        Returns
        :class:`PIL.Image`:
            The final preview display image
        """
        if self._previewcache.get("images", None) is None:
        self._previewcache["images"] = cache
        logger.debug("Cache shape: %s", self._previewcache["images"].shape)

    def _place_previews(self, frame_dims):
        """ Format the preview thumbnails stored in the cache into a grid fitting the display
        panel.

        Parameters
        ----------
        frame_dims: tuple
            The (width (`int`), height (`int`)) of the display panel that will display the preview

        Returns
        :class:`PIL.Image`:
            The final preview display image
        """
        if self._previewcache.get("images", None) is None:
        self._previewcache["images"] = cache
        logger.debug("Cache shape: %s", self._previewcache["images"].shape)

    def _place_previews(self, frame_dims):
        """ Format the preview thumbnails stored in the cache into a grid fitting the display
        panel.

        Parameters
        ----------
        frame_dims: tuple
            The (width (`int`), height (`int`)) of the display panel that will display the preview

        Returns
        :class:`PIL.Image`:
            The final preview display image
        """
        if self._previewcache.get("images", None) is None:
        self._previewcache["images"] = cache
        logger.debug("Cache shape: %s", self._previewcache["images"].shape)

    def _place_previews(self, frame_dims):
        """ Format the preview thumbnails stored in the cache into a grid fitting the display
        panel.

        Parameters
        ----------
        frame_dims: tuple
            The (width (`int`), height (`int`)) of the display panel that will display the preview

        Returns
        :class:`PIL.Image`:
            The final preview display image
        """
        if self._previewcache.get("images", None) is None:
        self._previewcache["images"] = cache
        logger.debug("Cache shape: %s", self._previewcache["images"].shape)

    def _place_previews(self, frame_dims):
        """ Format the preview thumbnails stored in the cache into a grid fitting the display
        panel.

        Parameters
        ----------
        frame_dims: tuple
            The (width (`int`), height (`int`)) of the display panel that will display the preview

        Returns
        :class:`PIL.Image`:
            The final preview display image
        """
        if self._previewcache.get("images", None) is None:
        self._previewcache["images"] = cache
        logger.debug("Cache shape: %s", self._previewcache["images"].shape)

    def _place_previews(self, frame_dims):
        """ Format the preview thumbnails stored in the cache into a grid fitting the display
        panel.

        Parameters
        ----------
        frame_dims: tuple
            The (width (`int`), height (`int`)) of the display panel that will display the preview

        Returns
        :class:`PIL.Image`:
            The final preview display image
        """
        if self._previewcache.get("images", None) is None:
        self._previewcache["images"] = cache
        logger.debug("Cache shape: %s", self._previewcache["images"].shape)

    def _place_previews(self, frame_dims):
        """ Format the preview thumbnails stored in the cache into a grid fitting the display
        panel.

        Parameters
        ----------
        frame_dims: tuple
            The (width (`int`), height (`int`)) of the display panel that will display the preview

        Returns
        :class:`PIL.Image`:
            The final preview display image
        """
        if self._previewcache.get("images", None) is None:
        self._previewcache["images"] = cache
        logger.debug("Cache shape: %s", self._previewcache["images"].shape)

    def _place_previews(self, frame_dims):
        """ Format the preview thumbnails stored in the cache into a grid fitting the display
        panel.

        Parameters
        ----------
        frame_dims: tuple
            The (width (`int`), height (`int`)) of the display panel that will display the preview

        Returns
        :class:`PIL.Image`:
            The final preview display image
        """
        if self._previewcache.get("images", None) is None:
        self._previewcache["images"] = cache
        logger.debug("Cache shape: %s", self._previewcache["images"].shape)

    def _place_previews(self, frame_dims):
        """ Format the preview thumbnails stored in the cache into a grid fitting the display
        panel.

        Parameters
        ----------
        frame_dims: tuple
            The (width (`int`), height (`int`)) of the display panel that will display the preview

        Returns
        :class:`PIL.Image`:
            The final preview display image
        """
        if self._previewcache.get("images", None) is None:
        self._previewcache["images"] = cache
        logger.debug("Cache shape: %s", self._previewcache["images"].shape)

    def _place_previews(self, frame_dims):
        """ Format the preview thumbnails stored in the cache into a grid fitting the display
        panel.

        Parameters
        ----------
        frame_dims: tuple
            The (width (`int`), height (`int`)) of the display panel that will display the preview

        Returns
        :class:`PIL.Image`:
            The final preview display image
        """
        if self._previewcache.get("images", None) is None:
        self._previewcache["images"] = cache
        logger.debug("Cache shape: %s", self._previewcache["images"].shape)

    def _place_previews(self, frame_dims):
        """ Format the preview thumbnails stored in the cache into a grid fitting the display
        panel.

        Parameters
        ----------
        frame_dims: tuple
            The (width (`int`), height (`int`)) of the display panel that will display the preview

        Returns
        :class:`PIL.Image`:
            The final preview display image
        """
        if self._previewcache.get("images", None) is None:
        self._previewcache["images"] = cache
        logger.debug("Cache shape: %s", self._previewcache["images"].shape)

    def _place_previews(self, frame_dims):
        """ Format the preview thumbnails stored in the cache into a grid fitting the display
        panel.

        Parameters
        ----------
        frame_dims: tuple
            The (width (`int`), height (`int`)) of the display panel that will display the preview

        Returns
        :class:`PIL.Image`:
            The final preview display image
        """
        if self._previewcache.get("images", None) is None:
        self._previewcache["images"] = cache
        logger.debug("Cache shape: %s", self._previewcache["images"].shape)

    def _place_previews(self, frame_dims):
        """ Format the preview thumbnails stored in the cache into a grid fitting the display
        panel.

        Parameters
        ----------
        frame_dims: tuple
            The (width (`int`), height (`int`)) of the display panel that will display the preview

        Returns
        :class:`PIL.Image`:
            The final preview display image
        """
        if self._previewcache.get("images", None) is None:
        self._previewcache["images"] = cache
        logger.debug("Cache shape: %s", self._previewcache["images"].shape)

    def _place_previews(self, frame_dims):
        """ Format the preview thumbnails stored in the cache into a grid fitting the display
        panel.

        Parameters
        ----------
        frame_dims: tuple
            The (width (`int`), height (`int`)) of the display panel that will display the preview

        Returns
        :class:`PIL.Image`:
            The final preview display image
        """
        if self._previewcache.get("images", None) is None:
        self._previewcache["images"] = cache
        logger.debug("Cache shape: %s", self._previewcache["images"].shape)

    def _place_previews(self, frame_dims):
        """ Format the preview thumbnails stored in the cache into a grid fitting the display
        panel.

        Parameters
        ----------
        frame_dims: tuple
            The (width (`int`), height (`int`)) of the display panel that will display the preview

        Returns
        :class:`PIL.Image`:
            The final preview display image
        """
        if self._previewcache.get("images", None) is None:
        self._previewcache["images"] = cache
        logger.debug("Cache shape: %s", self._previewcache["images"].shape)

    def _place_previews(self, frame_dims):
        """ Format the preview thumbnails stored in the cache into a grid fitting the display
        panel.

        Parameters
        ----------
        frame_dims: tuple
            The (width (`int`), height (`int`)) of the display panel that will display the preview

        Returns
        :class:`PIL.Image`:
            The final preview display image
        """
        if self._previewcache.get("images", None) is None:
        self._previewcache["images"] = cache
        logger.debug("Cache shape: %s", self._previewcache["images"].shape)

    def _place_previews(self, frame_dims):
        """ Format the preview thumbnails stored in the cache into a grid fitting the display
        panel.

        Parameters
        ----------
        frame_dims: tuple
            The (width (`int`), height (`int`)) of the display panel that will display the preview

        Returns
        :class:`PIL.Image`:
            The final preview display image
        """
        if self._previewcache.get("images", None) is None:
        self._previewcache["images"] = cache
        logger.debug("Cache shape: %s", self._previewcache["images"].shape)

    def _place_previews(self, frame_dims):
        """ Format the preview thumbnails stored in the cache into a grid fitting the display
        panel.

        Parameters
        ----------
        frame_dims: tuple
            The (width (`int`), height (`int`)) of the display panel that will display the preview

        Returns
        :class:`PIL.Image`:
            The final preview display image
        """
        if self._previewcache.get("images", None) is None:
        self._previewcache["images"] = cache
        logger.debug("Cache shape: %s", self._previewcache["images"].shape)

    def _place_previews(self, frame_dims):
        """ Format the preview thumbnails stored in the cache into a grid fitting the display
        panel.

        Parameters
        ----------
        frame_dims: tuple
            The (width (`int`), height (`int`)) of the display panel that will display the preview

        Returns
        :class:`PIL.Image`:
            The final preview display image
        """
        if self._previewcache.get("images", None) is None:
        self._previewcache["images"] = cache
        logger.debug("Cache shape: %s", self._previewcache["images"].shape)

    def _place_previews(self, frame_dims):
        """ Format the preview thumbnails stored in the cache into a grid fitting the display
        panel.

        Parameters
        ----------
        frame_dims: tuple
            The (width (`int`), height (`int`)) of the display panel that will display the preview

        Returns
        :class:`PIL.Image`:
            The final preview display image
        """
        if self._previewcache.get("images", None) is None:
        self._previewcache["images"] = cache
        logger.debug("Cache shape: %s", self._previewcache["images"].shape)

    def _place_previews(self, frame_dims):
        """ Format the preview thumbnails stored in the cache into a grid fitting the display
        panel.

        Parameters
        ----------
        frame_dims: tuple
            The (width (`int`), height (`int`)) of the display panel that will display the preview

        Returns
        :class:`PIL.Image`:
            The final preview display image
        """
        if self._previewcache.get("images", None) is None:
        self._previewcache["images"] = cache
        logger.debug("Cache shape: %s", self._previewcache["images"].shape)

    def _place_previews(self, frame_dims):
        """ Format the preview thumbnails stored in the cache into a grid fitting the display
        panel.

        Parameters
        ----------
        frame_dims: tuple
            The (width (`int`), height (`int`)) of the display panel that will display the preview

        Returns
        :class:`PIL.Image`:
            The final preview display image
        """
        if self._previewcache.get("images", None) is None:
        self._previewcache["images"] = cache
        logger.debug("Cache shape: %s", self._previewcache["images"].shape)

    def _place_previews(self, frame_dims):
        """ Format the preview thumbnails stored in the cache into a grid fitting the display
        panel.

        Parameters
        ----------
        frame_dims: tuple
            The (width (`int`), height (`int`)) of the display panel that will display the preview

        Returns
        :class:`PIL.Image`:
            The final preview display image
        """
        if self._previewcache.get("images", None) is None:
              logger.debug("No images in cache. Returning None")
              return None
          samples = self.previewcache["images"].copy()
          num_images, thumbnail_size = samples.shape[:2]
          if self.previewcache["placeholder"] is None:
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 replace replace keep keep keep keep keep
 GUI Updates (#940)

* lib.gui: Update icons
* tools.cli: Add video filetype flag to mask input
* lib.gui.popup_configure: Refresh GUI on config save
* lib.gui._config: Add Icon size and load last session options
* lib.gui.control_helper - Add control modification tracking
* lib.gui - Add Projects and Last Session
- Main root title handled by projects
- Add Hotkeys
- Create projects module
- split fsw and fst filetypes
- Add last_session saving

* lib.project
- Documentation
- Ask confirm on closing unsaved project
-Fixups

* Track model folder changes
- Shuffle some globals
- Activate System Verbosity for GUI

* lib.gui.utils - Documentation and clean up
- lib.gui.custom_widgets - Create and document

* Add GUI config option to disable auto loading model stats 
lib/gui/utils.py