-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings.py
More file actions
66 lines (56 loc) · 2.22 KB
/
settings.py
File metadata and controls
66 lines (56 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import json
import os
from PySide6.QtWidgets import QWidget
from project_data import ProjectData
def get_settings_path():
home = os.path.expanduser("~")
settings_dir = os.path.join(home, "keysearch_app_settings")
os.makedirs(settings_dir, exist_ok=True)
return os.path.join(settings_dir, "settings.json")
class Settings:
@staticmethod
def save_settings(search_depth, snippet_size, default_search_path, language):
data = {
"search_depth": search_depth.text(),
"snippet_size": snippet_size.text(),
"default_search_path": default_search_path.text(),
"language": language.currentText(),
}
with open(get_settings_path(), "w") as f:
json.dump(data, f, indent=4)
ProjectData.set(
search_depth=int(search_depth.text()),
snippet_size=int(snippet_size.text()),
default_search_path=default_search_path.text(),
language=language.currentText(),
)
@staticmethod
def load_settings(window=None):
path = get_settings_path()
search_depth = 4000
snippet_size = 250
default_search_path = ""
language = "Deutsch"
if os.path.exists(path):
with open(path, "r") as f:
data = json.load(f)
search_depth = data.get("search_depth", 4000)
snippet_size = data.get("snippet_size", 250)
default_search_path = data.get("default_search_path", "~")
language = data.get("language", "English")
# ProjectData updaten
ProjectData.set(
search_depth=search_depth,
snippet_size=snippet_size,
default_search_path=default_search_path,
language=language,
)
# Optional: Widgets in SettingsWindow setzen
if window:
window.search_depth.setText(str(search_depth))
window.snippet_size.setText(str(snippet_size))
window.default_search_path.setText(default_search_path)
# Prüfe ob die Sprache im ComboBox vorhanden ist
index = window.language.findText(language)
if index != -1:
window.language.setCurrentIndex(index)