Repository navigation
Expand file tree
/
Copy pathsettings.py
More file actions
executable file
·78 lines (68 loc) · 2.15 KB
/
Copy pathsettings.py
File metadata and controls
executable file
·78 lines (68 loc) · 2.15 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
#!/usr/bin/env python3
"""
Settings Management Module
"""
import json
import os
import threading
class Settings:
DEFAULT_SETTINGS = {
'camera_id': 0,
'width': 640,
'height': 480,
'fps': 15,
'quality': 80,
'mirror_h': False,
'mirror_v': False,
'rotation': 0,
'zoom': 1.0,
'flash': False,
'show_timestamp': False,
'show_grid': False,
'motion_detection': False,
'motion_threshold': 30,
'theme': 'dark'
}
def __init__(self, settings_file='camera_settings.json'):
self.settings_file = settings_file
self.settings = self.DEFAULT_SETTINGS.copy()
self.lock = threading.Lock()
self.load()
def load(self):
try:
if os.path.exists(self.settings_file):
with open(self.settings_file, 'r') as f:
loaded = json.load(f)
with self.lock:
for key in self.DEFAULT_SETTINGS:
if key in loaded:
self.settings[key] = loaded[key]
except Exception as e:
print(f"Error loading settings: {e}")
def save(self):
try:
with self.lock:
with open(self.settings_file, 'w') as f:
json.dump(self.settings, f, indent=2)
except Exception as e:
print(f"Error saving settings: {e}")
def get(self, key, default=None):
with self.lock:
return self.settings.get(key, default)
def set(self, key, value):
with self.lock:
if key in self.DEFAULT_SETTINGS:
self.settings[key] = value
def update(self, new_settings):
with self.lock:
for key, value in new_settings.items():
if key in self.DEFAULT_SETTINGS:
self.settings[key] = value
self.save()
def get_all(self):
with self.lock:
return self.settings.copy()
def reset(self):
with self.lock:
self.settings = self.DEFAULT_SETTINGS.copy()
self.save()