-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
121 lines (90 loc) · 2.81 KB
/
config.py
File metadata and controls
121 lines (90 loc) · 2.81 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import json
import os
CODESLEUTH_FOLDER = r"C:\ProgramData\CodeSleuth"
CONFIG_FILE = os.path.join(CODESLEUTH_FOLDER, r"config.json")
def check_folder():
if not os.path.exists(CODESLEUTH_FOLDER):
os.makedirs(CODESLEUTH_FOLDER)
def get_config():
try:
with open(CONFIG_FILE, "r", encoding="UTF-8") as f:
config = json.load(f)
return config
except Exception:
return {}
def save_config(config : dict):
with open(CONFIG_FILE, "w", encoding="UTF-8") as f:
json.dump(config, f, indent=4)
def save_search_paths(paths : list):
check_folder()
config = get_config()
config["search_paths"] = paths
save_config(config)
def save_search_exeption_paths(paths : list):
check_folder()
config = get_config()
config["search_exeption_paths"] = paths
save_config(config)
def save_search_limits(limits : dict):
check_folder()
config = get_config()
config["search_limits"] = limits
save_config(config)
def save_theme(theme_file : str):
check_folder()
config = get_config()
config["theme"] = theme_file
save_config(config)
def get_search_paths() -> list:
try:
return get_config()["search_paths"]
except Exception:
return []
def get_search_exeption_paths() -> list:
try:
return get_config()["search_exeption_paths"]
except Exception:
return []
def get_search_limits() -> dict:
try:
return get_config()["search_limits"]
except Exception:
return {}
def get_theme_file() -> str:
try:
return get_config()["theme"]
except Exception:
return None
def get_theme_files() -> str:
theme_files = []
for root, dirs, files in os.walk(os.path.join(CODESLEUTH_FOLDER, "Themes")):
for file in files:
theme_files.append(file)
return theme_files
def get_theme() -> str:
file = get_theme_file()
if file:
try:
with open(os.path.join(CODESLEUTH_FOLDER, "Themes", file), "r", encoding="UTF-8") as f:
theme = json.load(f)
except Exception:
return "Default"
if "name" in theme:
return theme["name"]
else:
return "Unnamed"
return "Default"
def get_widget_style(widget : str, style : str) -> str:
file = get_theme_file()
if file:
try:
with open(os.path.join(CODESLEUTH_FOLDER, "Themes", file), "r", encoding="UTF-8") as f:
theme = json.load(f)
if widget in theme:
if style in theme[widget]:
return theme[widget][style]
return None
except Exception:
return None
else:
return None