AnalyseMorphologique/utils/settings/SettingManager.py
Djalim Simaila 6803443385 🔖 chore(SettingManager.py): update version to 1.2.0
🔨 refactor(SettingManager.py): reorder authors list and update description
The version number has been updated to 1.2.0 to reflect the changes made to the application. The authors list has been reordered and the description has been updated to provide a more detailed explanation of the tool's functionality.
2023-05-10 16:33:53 +02:00

111 lines
3.8 KiB
Python

"""
Created on Fri Apr 21 2023
@name: SettingManager.py
@desc: A module to manage the settings
@auth: Djalim Simaila
@e-mail: djalim.simaila@inrae.fr
"""
from yaml import load, dump
try:
from yaml import CLoader as Loader, CDumper as Dumper
except ImportError:
from yaml import Loader, Dumper
class SettingManager:
"""
A class to manage the settings
:ivar settings: The settings
:ivar instance: The instance of the class
"""
instance = None
version = "1.2.0"
def __init__(self):
try:
with open('config.yml', 'r') as f:
self.settings = load(f.read(), Loader=Loader)
if self.settings['version'] != self.version:
self.settings['version'] = self.version
self.save()
except FileNotFoundError:
self.settings = {}
self.createInitialSettings()
@staticmethod
def get_instance()->'SettingManager':
"""
Get the instance of the class
:return: The instance of the class
"""
if SettingManager.instance is None:
SettingManager.instance = SettingManager()
return SettingManager.instance
def save(self):
"""
Save the settings to the config file
"""
with open('config.yml', 'w') as f:
f.write(dump(self.settings, Dumper=Dumper))
def createInitialSettings(self):
self.settings['version'] = self.version
self.settings['name'] = 'Analyse Morphologique'
self.settings['authors'] = ['Djalim Simaila <djalim.simaila@inrae.fr>','Alexis Doghmane <alexis@doghmane.fr>']
self.settings['description'] = """Analyse Morphologique est un outil conçu pour extraire des informations \ndétaillées et précises à partir d'un scan 3D. Il permet aux utilisateurs\nd'analyser des objets 3D à partir d'un point de vue morphologique,\nc'est-à-dire en analysant la forme et la structure de l'objet."""
self.settings['repo'] = 'https://forgemia.inra.fr/scanner3d/analysemorphologique'
self.settings['lastGraph'] = ["Aucun" for i in range(11)]
self.settings['discretisation_method'] = 'Z0-Zi >= DeltaZ' # 'Z0-Zi < DeltaZ'
self.settings['discretisation_methods'] = ['Z0-Zi >= DeltaZ', 'Z0-Zi < DeltaZ']
self.settings['raw_data_suffix'] = '_delta_{delta_z}_analyse_brute'
self.settings['discrete_data_suffix'] = '_delta_{delta_z}_analyse_rayon'
self.settings['output_file_extension'] = '.txt'
self.settings['output_file_separator'] = '\t'
self.settings['pretiffy_output_file'] = True
self.save()
def get_last_graph(self, graph_number)->str:
"""
Get the last graph name for the specified slot
"""
return self.settings['lastGraph'][graph_number]
def set_last_graph(self, graph_number, graph_name):
"""
Set the last graph name for the specified slot
:param graph_number: The slot number
:param graph_name: The graph name
"""
self.settings['lastGraph'][graph_number] = graph_name
self.save()
def get_setting(self, setting_name)->any:
"""
Get the value of the specified setting
:param setting_name: The name of the setting
:return: The value of the setting
"""
return self.settings[setting_name]
def get_settings(self)->dict:
"""
Get the settings
:return: The settings
"""
return self.settings
def set_setting(self, setting_name, setting_value):
"""
Set the value of the specified setting
:param setting_name: The name of the setting
:param setting_value: The value of the setting
"""
self.settings[setting_name] = setting_value
self.save()