commit 816824a0c701982fd07e674bdde8798ca0c1a465 Author: Dunestorm Date: Sat Aug 6 00:49:01 2022 +0100 Initial commit of working config write code diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..306f58e --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,16 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Python: Current File", + "type": "python", + "request": "launch", + "program": "${file}", + "console": "integratedTerminal", + "justMyCode": true + } + ] +} \ No newline at end of file diff --git a/config_writer.py b/config_writer.py new file mode 100644 index 0000000..7484fc5 --- /dev/null +++ b/config_writer.py @@ -0,0 +1,55 @@ +from dis import dis + + +class ConfigWriter: + def __init__(self): + self._config_file = 'C:\\Program Files\\EqualizerAPO\\config\\config.txt' + self._config_output = None + + self.headphone_mode_enabled = False + self.active_headphone = None + self.inactive_headphones = list() + + # Read current config. + with open(self._config_file, 'r') as c: + self._config_output = c.readlines() + c.close() + + # Extract spec name from text output. + for spec in self._config_output: + if spec.startswith('# '): + _spec = spec.replace('# ', '').removesuffix('\n').removesuffix('.txt').removeprefix('Include:') + self.inactive_headphones.append(_spec.strip()) + else: + _spec = spec.removesuffix('\n').removesuffix('.txt').removeprefix('Include:') + self.active_headphone = _spec.strip() + + if self.active_headphone is not None: + self.headphone_mode_enabled = True + + + def write_specs(self, disabled_specs, enabled_spec): + formatted_disabled_specs = list() + formatted_enabled_spec = self._format_spec(enabled_spec, False) + + if disabled_specs is not None: + for s in disabled_specs: + formatted_disabled_specs.append(self._format_spec(s, True)) + + with open(self._config_file, 'w+') as c: + for i in formatted_disabled_specs: + c.write(i + '\n') + + if enabled_spec is not None: + c.write(formatted_enabled_spec) + + c.close() + + def _format_spec(self, entry: str, disable: bool): + _entry = None + if disable: + _entry = '# Include: {}.txt'.format(entry) + else: + _entry = 'Include: {}.txt'.format(entry) + + return _entry \ No newline at end of file diff --git a/headphones_dark.png b/headphones_dark.png new file mode 100644 index 0000000..a25ddd2 Binary files /dev/null and b/headphones_dark.png differ diff --git a/headphones_light.png b/headphones_light.png new file mode 100644 index 0000000..8f76aa0 Binary files /dev/null and b/headphones_light.png differ diff --git a/loudspeakers_dark.png b/loudspeakers_dark.png new file mode 100644 index 0000000..95de042 Binary files /dev/null and b/loudspeakers_dark.png differ diff --git a/loudspeakers_light.png b/loudspeakers_light.png new file mode 100644 index 0000000..03ea7b8 Binary files /dev/null and b/loudspeakers_light.png differ diff --git a/main.pyw b/main.pyw new file mode 100644 index 0000000..b8249ab --- /dev/null +++ b/main.pyw @@ -0,0 +1,10 @@ +from config_writer import ConfigWriter + +cw = ConfigWriter() + +lis = cw.inactive_headphones +if cw.active_headphone is not None: + lis.append(cw.active_headphone) + +#cw.write_specs(lis, None) +cw.write_specs(cw.active_headphone, cw.inactive_headphones[0]) \ No newline at end of file