MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / ConfigChanges

Class ConfigChanges

tools/python-3.11.9-amd64/Lib/idlelib/config.py:781–876  ·  view source on GitHub ↗

Manage a user's proposed configuration option changes. Names used across multiple methods: page -- one of the 4 top-level dicts representing a .idlerc/config-x.cfg file. config_type -- name of a page. section -- a section within a page/file.

Source from the content-addressed store, hash-verified

779
780
781class ConfigChanges(dict):
782 """Manage a user's proposed configuration option changes.
783
784 Names used across multiple methods:
785 page -- one of the 4 top-level dicts representing a
786 .idlerc/config-x.cfg file.
787 config_type -- name of a page.
788 section -- a section within a page/file.
789 option -- name of an option within a section.
790 value -- value for the option.
791
792 Methods
793 add_option: Add option and value to changes.
794 save_option: Save option and value to config parser.
795 save_all: Save all the changes to the config parser and file.
796 delete_section: If section exists,
797 delete from changes, userCfg, and file.
798 clear: Clear all changes by clearing each page.
799 """
800 def __init__(self):
801 "Create a page for each configuration file"
802 self.pages = [] # List of unhashable dicts.
803 for config_type in idleConf.config_types:
804 self[config_type] = {}
805 self.pages.append(self[config_type])
806
807 def add_option(self, config_type, section, item, value):
808 "Add item/value pair for config_type and section."
809 page = self[config_type]
810 value = str(value) # Make sure we use a string.
811 if section not in page:
812 page[section] = {}
813 page[section][item] = value
814
815 @staticmethod
816 def save_option(config_type, section, item, value):
817 """Return True if the configuration value was added or changed.
818
819 Helper for save_all.
820 """
821 if idleConf.defaultCfg[config_type].has_option(section, item):
822 if idleConf.defaultCfg[config_type].Get(section, item) == value:
823 # The setting equals a default setting, remove it from user cfg.
824 return idleConf.userCfg[config_type].RemoveOption(section, item)
825 # If we got here, set the option.
826 return idleConf.userCfg[config_type].SetOption(section, item, value)
827
828 def save_all(self):
829 """Save configuration changes to the user config file.
830
831 Clear self in preparation for additional changes.
832 Return changed for testing.
833 """
834 idleConf.userCfg['main'].Save()
835
836 changed = False
837 for config_type in self:
838 cfg_type_changed = False

Callers 1

configdialog.pyFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected