                  helptext = def_opt["helptext"]
                  helptext = self._config.format_help(helptext, is_section=False)
                  new_config.set(section, helptext)
                  new_config.set(section, item, str(new_opt))
          self._config.config = new_config
          self._config.save_config()
          logger.info("Saved config: '%s'", self._config.configfile)
          self.destroy()
  
          running_task = get_config().tk_vars["runningtask"].get()
          if self._name.lower() == "gui" and not running_task:
              self._root.rebuild()
          elif self._name.lower() == "gui" and running_task:
              logger.info("Can't redraw GUI whilst a task is running. GUI Settings will be applied "
                          "at the next restart.")
          logger.debug("Saved config")
 
</s> remove                 new_opt = options[section][item].get()
                logger.debug("Adding option: (item: '%s', default: %s new: '%s'",
                             item, def_opt, new_opt)
                helptext = def_opt["helptext"]
                helptext = self._config.format_help(helptext, is_section=False)
 </s> add                 if page_only and section != lookup:
                    # Keep existing values for pages we are not updating
                    new_opt = config.get(section, item)
                    logger.debug("Retain existing value '%s' for %s",
                                 new_opt, ".".join([section, item]))
                else:
                    # Get currently selected value
                    key = category
                    if section != "global":
                        key += "|{}".format(section.replace(".", "|"))
                    new_opt = self._config_cpanel_dict[key]["options"][item].get()
                    logger.debug("Updating value to '%s' for %s",
                                 new_opt, ".".join([section, item]))
                helptext = config.format_help(options["helptext"], is_section=False) </s> remove def popup_config(name, configuration):
    """ Open the settings for the requested configuration file and close any already active
    pop-ups.
 </s> add class _State():
    """ Holds the existing config files and the current state of the popup window. """
    def __init__(self):
        self._popup = None
        # The GUI Config cannot be scanned until GUI is launched, so this is populated
        # on the first call to load the settings
        self._configs = dict() </s> remove     Parameters
    ----------
    name: str
        The name of the configuration file. Used for the pop-up title bar.
    configuration: :class:`~lib.config.FaceswapConfig`
        The configuration options for the requested pop-up window
    """
    logger.debug("name: %s, configuration: %s", name, configuration)
    if POPUP:
        p_key = list(POPUP.keys())[0]
        logger.debug("Closing open popup: '%s'", p_key)
        POPUP[p_key].destroy()
        del POPUP[p_key]
    window = _ConfigurePlugins(name, configuration)
    POPUP[name] = window
    logger.debug("Current pop-up: %s", POPUP)
 </s> add     def open_popup(self, name=None):
        """ Launch the popup, ensuring only one instance is ever open

        Parameters
        ----------
        name: str, Optional
            The name of the configuration file. Used for selecting the correct section if required.
            Set to ``None`` if no initial section should be selected. Default: ``None``
        """
        if not self._configs:
            self._scan_for_configs()
        logger.debug("name: %s", name)
        if self._popup is not None:
            logger.info("Popup already open. Returning: %s", _POPUP)
            return
        self._popup = _ConfigurePlugins(name, self._configs)

    def close_popup(self):
        """ Destroy the open popup and remove it from tracking. """
        if self._popup is None:
            logger.info("No popup to close. Returning")
            return
        self._popup.destroy()
        del self._popup
        self._popup = None

    def _scan_for_configs(self):
        """ Scan the plugin folders for configuration settings. Add in the GUI configuration also.

        Populates the attribute :attr:`_configs`.
        """
        root_path = os.path.abspath(os.path.dirname(sys.argv[0]))
        plugins_path = os.path.join(root_path, "plugins")
        logger.debug("Scanning path: '%s'", plugins_path)
        for dirpath, _, filenames in os.walk(plugins_path):
            if "_config.py" in filenames:
                plugin_type = os.path.split(dirpath)[-1]
                config = self._load_config(plugin_type)
                self._configs[plugin_type] = config
        self._configs["gui"] = get_config().user_config
        logger.debug("Configs loaded: %s", sorted(list(self._configs.keys())))

    @classmethod
    def _load_config(cls, plugin_type):
        """ Load the config from disk. If the file doesn't exist, then it will be generated.

        Parameters
        ----------
        plugin_type: str
            The plugin type (i.e. extract, train convert) that the config should be loaded for

        Returns
        -------
        :class:`lib.config.FaceswapConfig`
            The Configuration for the selected plugin
        """
        # Load config to generate default if doesn't exist
        mod = ".".join(("plugins", plugin_type, "_config"))
        module = import_module(mod)
        config = module.Config(None)
        logger.debug("Found '%s' config at '%s'", plugin_type, config.configfile)
        return config


_STATE = _State()
open_popup = _STATE.open_popup </s> remove         logger.debug("Setting tk variable: (name: '%s', dtype: %s, tk_var: %s)",
                     self.name, self.dtype, var)
 </s> add         if initial_value is not None:
            var.set(initial_value)
        logger.debug("Setting tk variable: (name: '%s', dtype: %s, tk_var: %s, initial_value: %s)",
                     self.name, self.dtype, var, initial_value) </s> remove             self._config.insert_config_section(section, items["helptext"], config=new_config)
            for item, def_opt in items.items():
 </s> add             config.insert_config_section(section, items["helptext"], config=new_config)
            for item, options in items.items():
        config.config = new_config
        config.save_config()
        logger.info("Saved config: '%s'", config.configfile)

        if category == "gui":
            if not get_config().tk_vars["runningtask"].get():
                get_config().root.rebuild()
            else:
                logger.info("Can't redraw GUI whilst a task is running. GUI Settings will be "
                            "applied at the next restart.")
                  helptext = def_opt["helptext"]
                  helptext = self._config.format_help(helptext, is_section=False)
                  new_config.set(section, helptext)
                  new_config.set(section, item, str(new_opt))
        config.config = new_config
        config.save_config()
        logger.info("Saved config: '%s'", config.configfile)

        if category == "gui":
            if not get_config().tk_vars["runningtask"].get():
                get_config().root.rebuild()
            else:
                logger.info("Can't redraw GUI whilst a task is running. GUI Settings will be "
                            "applied at the next restart.")
        config.config = new_config
        config.save_config()
        logger.info("Saved config: '%s'", config.configfile)

        if category == "gui":
            if not get_config().tk_vars["runningtask"].get():
                get_config().root.rebuild()
            else:
                logger.info("Can't redraw GUI whilst a task is running. GUI Settings will be "
                            "applied at the next restart.")
        config.config = new_config
        config.save_config()
        logger.info("Saved config: '%s'", config.configfile)

        if category == "gui":
            if not get_config().tk_vars["runningtask"].get():
                get_config().root.rebuild()
            else:
                logger.info("Can't redraw GUI whilst a task is running. GUI Settings will be "
                            "applied at the next restart.")
        config.config = new_config
        config.save_config()
        logger.info("Saved config: '%s'", config.configfile)

        if category == "gui":
            if not get_config().tk_vars["runningtask"].get():
                get_config().root.rebuild()
            else:
                logger.info("Can't redraw GUI whilst a task is running. GUI Settings will be "
                            "applied at the next restart.")
        config.config = new_config
        config.save_config()
        logger.info("Saved config: '%s'", config.configfile)

        if category == "gui":
            if not get_config().tk_vars["runningtask"].get():
                get_config().root.rebuild()
            else:
                logger.info("Can't redraw GUI whilst a task is running. GUI Settings will be "
                            "applied at the next restart.")
        config.config = new_config
        config.save_config()
        logger.info("Saved config: '%s'", config.configfile)

        if category == "gui":
            if not get_config().tk_vars["runningtask"].get():
                get_config().root.rebuild()
            else:
                logger.info("Can't redraw GUI whilst a task is running. GUI Settings will be "
                            "applied at the next restart.")
        config.config = new_config
        config.save_config()
        logger.info("Saved config: '%s'", config.configfile)

        if category == "gui":
            if not get_config().tk_vars["runningtask"].get():
                get_config().root.rebuild()
            else:
                logger.info("Can't redraw GUI whilst a task is running. GUI Settings will be "
                            "applied at the next restart.")
        config.config = new_config
        config.save_config()
        logger.info("Saved config: '%s'", config.configfile)

        if category == "gui":
            if not get_config().tk_vars["runningtask"].get():
                get_config().root.rebuild()
            else:
                logger.info("Can't redraw GUI whilst a task is running. GUI Settings will be "
                            "applied at the next restart.")
        config.config = new_config
        config.save_config()
        logger.info("Saved config: '%s'", config.configfile)

        if category == "gui":
            if not get_config().tk_vars["runningtask"].get():
                get_config().root.rebuild()
            else:
                logger.info("Can't redraw GUI whilst a task is running. GUI Settings will be "
                            "applied at the next restart.")
        config.config = new_config
        config.save_config()
        logger.info("Saved config: '%s'", config.configfile)

        if category == "gui":
            if not get_config().tk_vars["runningtask"].get():
                get_config().root.rebuild()
            else:
                logger.info("Can't redraw GUI whilst a task is running. GUI Settings will be "
                            "applied at the next restart.")
        config.config = new_config
        config.save_config()
        logger.info("Saved config: '%s'", config.configfile)

        if category == "gui":
            if not get_config().tk_vars["runningtask"].get():
                get_config().root.rebuild()
            else:
                logger.info("Can't redraw GUI whilst a task is running. GUI Settings will be "
                            "applied at the next restart.")
          logger.debug("Saved config")
keep keep keep keep replace replace replace replace replace replace replace replace replace replace replace keep
 GUI: Consolidate settings to single menu 
lib/gui/popup_configure.py