mirror of
https://gitlab.com/dslackw/slpkg.git
synced 2024-11-16 07:47:35 +01:00
Improved code quality
This commit is contained in:
parent
43c118ddbe
commit
b0fffd76dc
2 changed files with 31 additions and 16 deletions
|
@ -2,9 +2,9 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import locale
|
||||
from dialog import Dialog
|
||||
from pathlib import Path
|
||||
from typing import Union, Tuple
|
||||
from dialog import Dialog
|
||||
|
||||
from slpkg.configs import Configs
|
||||
from slpkg.views.version import Version
|
||||
|
@ -22,20 +22,23 @@ class DialogBox(Configs):
|
|||
self.d = Dialog(dialog="dialog")
|
||||
self.d.set_background_title(f'{self.prog_name} {Version().version} - Software Package Manager')
|
||||
|
||||
def checklist(self, text: str, title: str, height: int, width: int,
|
||||
def checklist(self, text: str, title: str, height: int, width: int, # pylint: disable=[R0913]
|
||||
list_height: int, choices: list) -> Tuple[bool, list]:
|
||||
""" Display a checklist box. """
|
||||
""" Display a checklist box.
|
||||
"""
|
||||
self.more_kwargs.update(
|
||||
{"item_help": True}
|
||||
)
|
||||
|
||||
code, tags = self.d.checklist(text=text, choices=choices, title=title, height=height, width=width,
|
||||
code, tags = self.d.checklist(text=text, choices=choices, title=title, height=height, width=width, # pylint: disable=[R0913]
|
||||
list_height=list_height, help_status=True, **self.more_kwargs)
|
||||
|
||||
return code, tags
|
||||
|
||||
def mixedform(self, text: str, title: str, elements: list, height: int, width: int, form_height) -> Tuple[bool, list]:
|
||||
""" Display a mixedform box. """
|
||||
def mixedform(self, text: str, title: str, elements: list, height: int, width: int, # pylint: disable=[R0913]
|
||||
form_height: int) -> Tuple[bool, list]:
|
||||
""" Display a mixedform box.
|
||||
"""
|
||||
self.more_kwargs.update(
|
||||
{"item_help": True,
|
||||
"help_tags": True}
|
||||
|
@ -47,9 +50,11 @@ class DialogBox(Configs):
|
|||
return code, tags
|
||||
|
||||
def msgbox(self, text: str, height: int, width: int) -> None:
|
||||
""" Display a message box. """
|
||||
""" Display a message box.
|
||||
"""
|
||||
self.d.msgbox(text, height, width)
|
||||
|
||||
def textbox(self, text: Union[str, Path], height: int, width: int) -> None:
|
||||
""" Display a text box. """
|
||||
""" Display a text box.
|
||||
"""
|
||||
self.d.textbox(text, height, width)
|
||||
|
|
|
@ -13,6 +13,10 @@ from slpkg.error_messages import Errors
|
|||
|
||||
class FormConfigs(Configs):
|
||||
|
||||
"""
|
||||
Edit slpkg.toml config file with dialog utility.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
super(Configs).__init__()
|
||||
self.dialogbox = DialogBox()
|
||||
|
@ -23,13 +27,15 @@ class FormConfigs(Configs):
|
|||
self.config_file: Path = Path(self.etc_path, f'{self.prog_name}.toml')
|
||||
|
||||
def is_dialog_enabled(self) -> None:
|
||||
""" Checking if the dialog box is enabled by the user. """
|
||||
""" Checking if the dialog box is enabled by the user.
|
||||
"""
|
||||
if not self.dialog:
|
||||
self.errors.raise_error_message(f"You should enable the dialog in the "
|
||||
f"'{self.etc_path}/{self.prog_name}.toml' file", exit_status=1)
|
||||
|
||||
def edit(self) -> None:
|
||||
""" Read and write the configuration file. """
|
||||
""" Read and write the configuration file.
|
||||
"""
|
||||
self.is_dialog_enabled()
|
||||
elements: list = []
|
||||
height: int = 9
|
||||
|
@ -65,12 +71,14 @@ class FormConfigs(Configs):
|
|||
self.edit()
|
||||
|
||||
def help(self) -> None:
|
||||
""" Load the configuration file on a text box. """
|
||||
""" Load the configuration file on a text box.
|
||||
"""
|
||||
self.dialogbox.textbox(str(self.config_file), 40, 60)
|
||||
self.edit()
|
||||
|
||||
def check_configs(self, tags: list) -> bool:
|
||||
""" Check for true of false values. """
|
||||
""" Check for true of false values.
|
||||
"""
|
||||
keys: list = [
|
||||
'COLORS',
|
||||
'DIALOG',
|
||||
|
@ -107,15 +115,17 @@ class FormConfigs(Configs):
|
|||
return True
|
||||
|
||||
def read_configs(self) -> None:
|
||||
""" Read the original config file. """
|
||||
with open(self.config_file, 'r') as toml_file:
|
||||
""" Read the original config file.
|
||||
"""
|
||||
with open(self.config_file, 'r', encoding='utf-8') as toml_file:
|
||||
self.orig_configs: list = toml_file.readlines()
|
||||
|
||||
def write_file(self, tags: list) -> None:
|
||||
""" Write the new values to the config file. """
|
||||
""" Write the new values to the config file.
|
||||
"""
|
||||
self.read_configs()
|
||||
|
||||
with open(self.config_file, 'w') as patch_toml:
|
||||
with open(self.config_file, 'w', encoding='utf-8') as patch_toml:
|
||||
for line in self.orig_configs:
|
||||
for key, value in zip(self.configs['configs'].keys(), tags):
|
||||
|
||||
|
|
Loading…
Reference in a new issue