Fixed for tags

This commit is contained in:
Dimitris Zlatanidis 2023-03-07 10:56:05 +02:00
parent 00beee1f08
commit 48ecd85c57

View file

@ -22,53 +22,50 @@ class FormConfigs(Configs):
def edit(self) -> None:
""" Read and write the configuration file. """
elements: list = []
config_file = Path(self.etc_path, f'{self.prog_name}.toml')
height: int = 35
width: int = 74
text: str = f'Edit the configuration file: {self.config_file}'
title: str = ' Configuration File '
if config_file.is_file():
# Load the toml config file.
configs: dict = self.load_configs.file(self.etc_path, self.prog_name)
# Creating the elements for the dialog form.
for i, (key, value) in enumerate(self.configs['CONFIGS'].items(), start=1):
if value is True:
value: str = 'true'
elif value is False:
value: str = 'false'
elements += [
(key, i, 1, value, i, 21, 47, 200, '0x0')
]
# Creating the elements for the dialog form.
for i, (key, value) in enumerate(configs['CONFIGS'].items(), start=1):
if value is True:
value: str = 'true'
elif value is False:
value: str = 'false'
elements += [
(key, i, 1, value, i, 21, 47, 200, '0x0')
]
code, tags = self.dialogbox.mixedform(text, title, elements, height, width)
height: int = 35
width: int = 74
text: str = f'Edit the configuration file: {config_file}'
title: str = ' Configuration File '
os.system('clear')
code, tags = self.dialogbox.mixedform(text, title, elements, height, width)
if code == 'help':
tags = self.configs.values()
self.help()
os.system('clear')
check: bool = self.check_configs(tags)
if code == 'help':
self.help()
if code == 'ok' and check:
self.write_file(tags)
check: bool = self.check_configs(configs, tags)
if code == 'ok' and check:
self.write_file(configs, tags)
elif not check:
self.edit()
elif not check:
self.edit()
def help(self) -> None:
""" Load the configuration file on a text box. """
self.read_configs()
self.dialogbox.textbox(str(self.config_file), 40, 60)
self.edit()
def check_configs(self, configs: dict, tags: list) -> bool:
def check_configs(self, tags: list) -> bool:
""" Check for true of false values. """
for key, value in zip(configs['CONFIGS'].keys(), tags):
keys: list = ['COLORS', 'DIALOG', 'SILENT_MODE', 'ASCII_CHARACTERS', 'PONCE_REPO', 'ASK_QUESTION']
values: list = ['true', 'false']
if (key in ['COLORS', 'DIALOG', 'SILENT_MODE', 'ASCII_CHARACTERS', 'PONCE_REPO', 'ASK_QUESTION'] and
value not in ['true', 'false']):
for key, value in zip(self.configs['CONFIGS'].keys(), tags):
if key in keys and value not in values:
self.dialogbox.msgbox(f"\nError value for {key}. It must be 'true' or 'false'\n", height=7, width=60)
return False
@ -83,14 +80,14 @@ class FormConfigs(Configs):
with open(self.config_file, 'r') as toml_file:
self.orig_configs = toml_file.readlines()
def write_file(self, configs: dict, tags: list) -> None:
def write_file(self, tags: list) -> None:
""" Write the new values to the config file. """
self.read_configs()
with open(self.config_file, 'w') as patch_toml:
for line in self.orig_configs:
for key, value in zip(configs['CONFIGS'].keys(), tags):
for key, value in zip(self.configs['CONFIGS'].keys(), tags):
if line.lstrip().startswith(f'{key} ='):
line = f' {key} = "{value}"\n'