Reads settings file and returns the dictionary. If you have anything changed in an existing settings dictionary, you will lose your changes. :return: settings dictionary :rtype: (dict)
(self)
| 22716 | self.save() |
| 22717 | |
| 22718 | def read(self): |
| 22719 | """ |
| 22720 | Reads settings file and returns the dictionary. |
| 22721 | If you have anything changed in an existing settings dictionary, you will lose your changes. |
| 22722 | :return: settings dictionary |
| 22723 | :rtype: (dict) |
| 22724 | """ |
| 22725 | if self.full_filename is None: |
| 22726 | return {} |
| 22727 | try: |
| 22728 | if os.path.exists(self.full_filename): |
| 22729 | with open(self.full_filename, 'r') as f: |
| 22730 | if not self.use_config_file: # if using json |
| 22731 | self.dict = json.load(f) |
| 22732 | else: # if using a config file |
| 22733 | self.config.read_file(f) |
| 22734 | # Make a dictionary of SectionDict classses. Keys are the config.sections(). |
| 22735 | self.section_class_dict = {} |
| 22736 | for section in self.config.sections(): |
| 22737 | section_dict = dict(self.config[section]) |
| 22738 | self.section_class_dict[section] = self._SectionDict(section, section_dict, self.config, self) |
| 22739 | |
| 22740 | self.dict = self.section_class_dict |
| 22741 | self.config_sections = self.config.sections() |
| 22742 | # self.config_dict = {section_name : dict(self.config[section_name]) for section_name in self.config.sections()} |
| 22743 | # if self.retain_config_comments: |
| 22744 | # self.config_file_contents = f.readlines() |
| 22745 | except Exception as e: |
| 22746 | self.dict = {} |
| 22747 | if not self.silent_on_error and ('pysimplegui_user_settings' in globals() and pysimplegui_user_settings != self): |
| 22748 | _error_popup_with_traceback('User Settings read warning', 'Error reading settings from file', self.full_filename, e) |
| 22749 | elif not self.silent_on_error: |
| 22750 | print(f'*** UserSettings.read - Error {e} reading settings from file: {self.full_filename}') |
| 22751 | |
| 22752 | return self.dict |
| 22753 | |
| 22754 | def exists(self, filename=None, path=None): |
| 22755 | """ |
no test coverage detected