-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
102 lines (88 loc) · 3.64 KB
/
Copy pathconfig.py
File metadata and controls
102 lines (88 loc) · 3.64 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
import os
import json
from pathlib import Path
from datetime import datetime
class Config:
def __init__(self):
self.app_name = "智能笔记管理系统"
self.version = "1.0.0"
self.author = "开源项目"
self.data_dir = Path.home() / ".smart_notes"
self.notes_dir = self.data_dir / "notes"
self.attachments_dir = self.data_dir / "attachments"
self.exports_dir = self.data_dir / "exports"
self.database_file = self.data_dir / "notes.db"
self.config_file = self.data_dir / "config.json"
self.index_file = self.data_dir / "search_index.json"
self.window_width = 1200
self.window_height = 800
self.theme_color = "#2c3e50"
self.accent_color = "#3498db"
self.bg_color = "#ecf0f1"
self.text_color = "#2c3e50"
self.sidebar_width = 250
self.editor_font = ("Consolas", 11)
self.ui_font = ("Microsoft YaHei UI", 10)
self.title_font = ("Microsoft YaHei UI", 12, "bold")
self.auto_save = True
self.auto_save_interval = 30
self.max_recent_notes = 10
self.enable_markdown_preview = True
self.enable_syntax_highlight = True
self.default_category = "未分类"
self.categories = ["工作", "学习", "生活", "项目", "想法"]
self._ensure_directories()
self._load_config()
def _ensure_directories(self):
self.data_dir.mkdir(parents=True, exist_ok=True)
self.notes_dir.mkdir(parents=True, exist_ok=True)
self.attachments_dir.mkdir(parents=True, exist_ok=True)
self.exports_dir.mkdir(parents=True, exist_ok=True)
def _load_config(self):
if self.config_file.exists():
try:
with open(self.config_file, 'r', encoding='utf-8') as f:
data = json.load(f)
for key, value in data.items():
if hasattr(self, key) and key not in ['data_dir', 'notes_dir']:
setattr(self, key, value)
except Exception as e:
print(f"加载配置失败: {e}")
def save_config(self):
try:
config_data = {
'window_width': self.window_width,
'window_height': self.window_height,
'auto_save': self.auto_save,
'auto_save_interval': self.auto_save_interval,
'categories': self.categories,
'enable_markdown_preview': self.enable_markdown_preview,
'enable_syntax_highlight': self.enable_syntax_highlight
}
with open(self.config_file, 'w', encoding='utf-8') as f:
json.dump(config_data, f, indent=4, ensure_ascii=False)
return True
except Exception as e:
print(f"保存配置失败: {e}")
return False
def add_category(self, category):
if category and category not in self.categories:
self.categories.append(category)
self.save_config()
return True
return False
def remove_category(self, category):
if category in self.categories and category != self.default_category:
self.categories.remove(category)
self.save_config()
return True
return False
def get_app_info(self):
return {
'name': self.app_name,
'version': self.version,
'author': self.author,
'data_dir': str(self.data_dir),
'notes_count': len(list(self.notes_dir.glob('*.md')))
}
config = Config()