Skip to content

Commit

Permalink
Allow % in config files by turning off ConfigParser interpolation (is…
Browse files Browse the repository at this point in the history
…sue #60).
  • Loading branch information
digitaltrails committed Sep 20, 2023
1 parent 4e74761 commit e050b71
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ Version History
* Update the Settings Dialog when a new VDU becomes available.
* Light-metering: show both a lux-auto indicator (an orange "LED") AND the current preset (if any) in the app icon.
* Fix first time use crash (issue #60).
* Allow % in config files by turning off ConfigParser interpolation (issue #60).
* 1.11.0
* Made vdu_controls ddcutil-2.0-ready.
* Added support for ddcutil versions earlier than 1.3 (issue #43, #53).
Expand Down
1 change: 1 addition & 0 deletions vdu_controls.changes
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Tue 12 Sep 2023 20:59:00 UTC - Michael Hamilton <[email protected]>
* Update the Settings Dialog when a new VDU becomes available.
* Light-metering: show both a lux-auto indicator (an orange "LED") AND the current preset (if any) in the app icon.
* Fix first time use crash (issue #60).
* Allow % in config files by turning off ConfigParser interpolation (issue #60).

-------------------------------------------------------------------
Sun 24 Jun 2023 21:50:00 UTC - Michael Hamilton <[email protected]>
Expand Down
10 changes: 5 additions & 5 deletions vdu_controls.py
Original file line number Diff line number Diff line change
Expand Up @@ -1361,7 +1361,7 @@ def query_capabilities(self, vdu_number: str) -> str:
"""Return a vpc capabilities string."""
result = self.__run__(*['capabilities'] + self.id_key_args(vdu_number), log_id=vdu_number)
capability_text = result.stdout.decode('utf-8', errors='surrogateescape')
return capability_text.replace('%', '')
return capability_text

def get_type(self, vcp_code) -> str | None:
return self.vcp_type_map[vcp_code] if vcp_code in self.vcp_type_map else None
Expand Down Expand Up @@ -1651,7 +1651,7 @@ class ConfigIni(configparser.ConfigParser):
METADATA_TIMESTAMP_OPTION = "timestamp"

def __init__(self) -> None:
super().__init__()
super().__init__(interpolation=None)
if not self.has_section(ConfigIni.METADATA_SECTION):
self.add_section(ConfigIni.METADATA_SECTION)

Expand Down Expand Up @@ -1789,7 +1789,7 @@ def get_capabilities_alt_text(self) -> str:
return self.ini_content['ddcutil-capabilities']['capabilities-override']

def set_capabilities_alt_text(self, alt_text: str) -> None:
self.ini_content['ddcutil-capabilities']['capabilities-override'] = alt_text.replace("%", "%%")
self.ini_content['ddcutil-capabilities']['capabilities-override'] = alt_text

def enable_supported_vcp_code(self, vcp_code: str) -> None:
self.ini_content['vdu-controls-widgets'][SUPPORTED_VCP_BY_CODE[vcp_code].property_name()] = 'yes'
Expand Down Expand Up @@ -1845,7 +1845,7 @@ def parse_file(self, config_path: Path) -> None:
alt_text = preserve_indents_match.group(1) if preserve_indents_match is not None else ''
# Remove excess indentation while preserving the minimum existing indentation.
alt_text = inspect.cleandoc(alt_text)
self.ini_content['ddcutil-capabilities']['capabilities-override'] = alt_text.replace('%', '')
self.ini_content['ddcutil-capabilities']['capabilities-override'] = alt_text

def reload(self) -> None:
log_info(f"Reloading config: {self.file_path}")
Expand Down Expand Up @@ -2512,7 +2512,7 @@ def __init__(self, section_editor: SettingsEditorTab, option: str, section: str,
text_editor = QPlainTextEdit(section_editor.ini_editable[section][option])

def text_changed() -> None:
section_editor.ini_editable[section][option] = text_editor.toPlainText().replace("%", "%%")
section_editor.ini_editable[section][option] = text_editor.toPlainText()

text_editor.textChanged.connect(text_changed)
layout.addWidget(text_editor)
Expand Down

0 comments on commit e050b71

Please sign in to comment.