3from PySide6.QtCore
import QObject
4from PySide6.QtWidgets
import QFileDialog, QMessageBox
9 Manage the loading, saving, and validation of configuration settings for directories.
10 Language setting for the user interface (e.g., 'english' or 'german').
11 Handle user interaction for selecting directories, and ensures that the configuration is
12 correctly loaded from and saved to a JSON file.
14 DEFAULT_COLUMNS = [
"Project",
"Operator",
"Specimen",
"DFOS_Type",
"Installation",
"Note"]
18 Initialize the ConfigManager with the path to the configuration file.
20 \param config_path (str): The file path where the configuration is stored.
22 super(ConfigManager, self).
__init__()
33 Create a default configuration file. Default language is English.
35 \return (dict): The default configuration.
41 'language':
'english',
45 json.dump(default_config, f)
50 Load the configuration file. If it doesn't exist or has errors, return an empty configuration.
52 \return (dict): The loaded configuration as a dictionary, or the default dictionary if the file contains errors.
58 except json.JSONDecodeError:
65 Save the current directory paths to the configuration file.
75 json.dump(config_data, f)
79 Load and check if previously saved directories are valid.
81 \return (tuple): directory1, directory2, language
83 dir1 = self.
config.get(
'directory1',
None)
84 dir2 = self.
config.get(
'directory2',
None)
85 dir3 = self.
config.get(
'directory3',
None)
86 language = self.
config.get(
'language',
'english')
89 if dir1
and os.path.exists(dir1):
92 if dir2
and os.path.exists(dir2):
95 if dir3
and os.path.exists(dir3):
98 if language
in (
'english',
'german'):
103 if isinstance(columns, list)
and all(isinstance(col, str)
for col
in columns):
112 Open a file dialog for the user to select the first (activated keyfile) directory.
114 \param dialog (QDialog): The dialog window that allows the user to select directories.
115 \param open_ui (QWidget): The UI that contains the directory input fields.
117 dir1 = QFileDialog.getExistingDirectory(dialog, self.tr(
"Please select the activation key file directory"))
120 open_ui.acLineEdit.setText(dir1)
124 Open a file dialog for the user to select the second (deactivated keyfile) directory.
126 \param dialog (QDialog): The dialog window that allows the user to select directories.
127 \param open_ui (QWidget): The UI that contains the directory input fields.
129 dir2 = QFileDialog.getExistingDirectory(dialog, self.tr(
"Please select the deactivation key file directory"))
132 open_ui.deacLineEdit.setText(dir2)
136 Open a file dialog for the user to select the trash directory.
138 \param dialog (QDialog): The dialog window that allows the user to select directories.
139 \param open_ui (QWidget): The UI that contains the directory input fields.
141 dir3 = QFileDialog.getExistingDirectory(dialog, self.tr(
"Please select the trash key file directory"))
144 open_ui.trashLineEdit.setText(dir3)
148 Confirm the directory selection made by the user.
149 Validate that both directories exist, and close the dialog if valid.
151 \param dialog (QDialog): The dialog window that allows the user to select directories.
152 \param open_ui (QWidget): The UI that contains the directory input fields.
154 dir1 = open_ui.acLineEdit.text().strip()
155 dir2 = open_ui.deacLineEdit.text().strip()
156 dir3 = open_ui.trashLineEdit.text().strip()
158 if not dir1
or not os.path.exists(dir1):
159 QMessageBox.warning(dialog, self.tr(
"Error"),
160 self.tr(
"Please select a valid directory for activated keyfiles."))
162 if not dir2
or not os.path.exists(dir2):
163 QMessageBox.warning(dialog, self.tr(
"Error"),
164 self.tr(
"Please select a valid directory for deactivated keyfiles."))
166 if not dir3
or not os.path.exists(dir3):
167 QMessageBox.warning(dialog, self.tr(
"Error"),
168 self.tr(
"Please select a valid directory for deactivated keyfiles."))
Manage the loading, saving, and validation of configuration settings for directories.
load_config(self)
Load the configuration file.
select_directory2(self, dialog, open_ui)
Open a file dialog for the user to select the second (deactivated keyfile) directory.
select_directory1(self, dialog, open_ui)
Open a file dialog for the user to select the first (activated keyfile) directory.
save_config(self)
Save the current directory paths to the configuration file.
select_directory3(self, dialog, open_ui)
Open a file dialog for the user to select the trash directory.
check_and_load_previous_config(self)
Load and check if previously saved directories are valid.
__init__(self, config_path)
Initialize the ConfigManager with the path to the configuration file.
confirm_directory_selection(self, dialog, open_ui)
Confirm the directory selection made by the user.
create_default_config(self)
Create a default configuration file.