Wrap text to fit within a specified width when rendered. On Pager, this is monkey-patched by PagerRagnar.setup_pager_shared_data() to use character-based wrapping instead of PIL fonts.
(self, text, font, max_width)
| 1769 | def load_config(self): |
| 1770 | """Load the configuration from the shared configuration JSON file.""" |
| 1771 | try: |
| 1772 | logger.info("Loading configuration...") |
| 1773 | if os.path.exists(self.shared_config_json): |
| 1774 | # Check if file is empty before attempting to parse |
| 1775 | if os.path.getsize(self.shared_config_json) == 0: |
| 1776 | logger.warning("Configuration file is empty, creating new one with default values...") |
| 1777 | self.save_config() |
| 1778 | return |
| 1779 | with open(self.shared_config_json, 'r') as f: |
| 1780 | config = json.load(f) |
| 1781 | config = self._normalize_config_keys(config) |
| 1782 | self.config.update(config) |
| 1783 | self.config = self._normalize_config_keys(self.config) |
| 1784 | for key, value in self.config.items(): |
| 1785 | setattr(self, key, value) |
| 1786 | self._remove_legacy_attributes() |
| 1787 | else: |
| 1788 | logger.warning("Configuration file not found, creating new one with default values...") |
| 1789 | self.save_config() |
| 1790 | self.load_config() |
| 1791 | time.sleep(2) |
| 1792 | except json.JSONDecodeError as e: |
| 1793 | logger.error(f"Configuration file is corrupted or invalid JSON: {e}") |
| 1794 | logger.warning("Recreating configuration file with default values...") |
| 1795 | self.save_config() |
| 1796 | except FileNotFoundError: |
| 1797 | logger.error("Error loading configuration: File not found.") |
| 1798 | self.save_config() |
no test coverage detected