Section = dict "Map item names to item values." # If we decide to add section methods, # class Section(dict): pass class Page(dict): pass """Map section names to sections. New methods: additem: apply: delete_section?: These are properly Page methods, not Section methods, because the section parameters are not Sections, just possible section names. """ # Configparser somewhat misleadingly calls this a 'ConfigParser' # but a page may or may not use its parser method to load sections. def additem(self, section, item, value): """Add item/value pair to a section of a page. Each ConfigDialog tab uses this to set values for its page. """ if section not in self: self[section] = Section() self[section][item] = str(value) def apply(self, section, new_items): # inline code for keys and highlight """Apply changes in section to dict new_items. One config entry for keysets and themes is the name of the keyset/theme and it contains all the settings for that entry. This applies the changes to a loaded keyset/theme to create a new list of item/value pairs. The output is used as input to save_new_config. """ try: new_items.update(self[section]) except KeyError: pass def delete_section(self, section): """Delete a section from this page. Used to delete custom themes and keysets. """ if section in self: del self[section] # So trivial we could leave inline, where 'self' will be page reference. class Changes: """Manage a user's proposed configuration option changes. One instance: pages manage changes to the corresponding user files. All changes are either cancelled or applied in a single transaction. Arguments used across multiple methods: These share the definition used in config.py. page (type, config_type) section item value Methods used by ConfigDialog: save_all: Save all the changes to the config file. save_new_config: Apply all the changes for key Methods used only for testing: Methods used internally: reset: Clear all changes by clearing each page. set_user_value: Set value *in idleConf* for page, section, item. TODO: - Evaluate extensions usage of this class. """ def __init__(self): "Create a page for each configuration file" self.main = Page() self.themes = Page() self.keys = Page() self.extensions = Page() self.pages = (self.main, self.themes, self.keys, self.extensions) def clear(self): # was reset_changed_items "Clear all 4 pages. Called in save_all(_changed_configs) after saving to idleConf. XXX Expose to user as [Clear changes] XXX Mark window *title* when there are changes; unmark here. """ for page in self.pages: page.clear() def save_all(self): # renamed from save_all_changed_configs """Save configuration changes to the user config file. XXX - what to do with save_all_changed_extensions """ pass def save_new_config(self, config_type, section, items_): # renamed from save_new_key_set and save_new_theme """Update IdleConf.userCfg values for all sections within a config_type. This is used for keysets and themes since those have many items that represent what the keyset or theme is. """ pass def set_user_value(self, config_type, section, item, value): # old """Update a single IdleConf.userCfg item/value pair. Called from save_all for each item within each section for each config_type. """ pass