41 lines
1.3 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# utils.py
import json
from pathlib import Path
def save_config(config_dict, filename="config.json"):
"""Сохранить конфигурацию в JSON файл"""
config_path = Path.home() / "Documents" / "C4" / filename
config_path.parent.mkdir(parents=True, exist_ok=True)
with open(config_path, 'w', encoding='utf-8') as f:
json.dump(config_dict, f, indent=2, ensure_ascii=False)
return config_path
def load_config(filename="config.json"):
"""Загрузить конфигурацию из JSON файла"""
config_path = Path.home() / "Documents" / "C4" / filename
if config_path.exists():
with open(config_path, 'r', encoding='utf-8') as f:
return json.load(f)
return {}
class ModuleManager:
"""Менеджер для работы с модулями"""
def __init__(self):
self.modules = {}
def register_module(self, name, module_class):
"""Зарегистрировать модуль"""
self.modules[name] = module_class
def create_module(self, name, parent_frame):
"""Создать экземпляр модуля"""
if name in self.modules:
return self.modules[name](parent_frame)
return None