-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
70 lines (60 loc) · 2.21 KB
/
config.py
File metadata and controls
70 lines (60 loc) · 2.21 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
import os
import json
from pathlib import Path
class Config:
"""Configuration management for PyEdit"""
def __init__(self):
self.config_dir = Path.home() / ".pyedit"
self.config_file = self.config_dir / "config.json"
self.default_config = {
"ai_model": "groq",
"theme": "default",
"auto_save": False,
"tab_size": 4,
"show_line_numbers": True,
"show_status_bar": True
}
self.config = self.load_config()
def load_config(self):
"""Load configuration from file or create default"""
try:
if self.config_file.exists():
with open(self.config_file, 'r') as f:
config = json.load(f)
# Merge with default config to ensure all keys exist
merged_config = self.default_config.copy()
merged_config.update(config)
return merged_config
else:
# Create config directory and file
self.config_dir.mkdir(exist_ok=True)
self.save_config(self.default_config)
return self.default_config
except Exception as e:
print(f"Error loading config: {e}")
return self.default_config
def save_config(self, config=None):
"""Save configuration to file"""
if config is None:
config = self.config
try:
self.config_dir.mkdir(exist_ok=True)
with open(self.config_file, 'w') as f:
json.dump(config, f, indent=2)
except Exception as e:
print(f"Error saving config: {e}")
def get(self, key, default=None):
"""Get configuration value"""
return self.config.get(key, default)
def set(self, key, value):
"""Set configuration value"""
self.config[key] = value
self.save_config()
def get_ai_model(self):
"""Get current AI model preference"""
return self.get("ai_model", "groq")
def set_ai_model(self, model_name):
"""Set AI model preference"""
self.set("ai_model", model_name)
# Global config instance
config = Config()