-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
62 lines (48 loc) · 1.97 KB
/
main.py
File metadata and controls
62 lines (48 loc) · 1.97 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
import sys
import json
import os
from pathlib import Path
from PyQt5.QtWidgets import QApplication
from core.calculator import ChemistryCalculator, RecipeRepository
from core.config import ChemistryConfig
from ui.main_window import ChemistryHelperWindow
def load_recipes() -> dict:
"""Загрузить рецепты из JSON файла"""
recipes_path = Path(__file__).parent / "data" / "recipes.json"
try:
with open(recipes_path, 'r', encoding='utf-8') as f:
return json.load(f)
except Exception as e:
print(f"Ошибка загрузки рецептов: {e}")
return {}
def get_available_substances(recipes: dict) -> list:
"""Получить список всех доступных веществ"""
substances = set()
for recipe_data in recipes.values():
# Добавляем продукты
substances.update(recipe_data.get("products", {}).keys())
# Добавляем реагенты
substances.update(recipe_data.get("reactants", {}).keys())
return list(substances)
def main():
# Создаём приложение
app = QApplication(sys.argv)
app.setApplicationName("Chemistry Helper")
app.setApplicationVersion("1.0.0")
# Загружаем рецепты
recipes_data = load_recipes()
if not recipes_data:
print("Не удалось загрузить рецепты!")
return 1
# Инициализируем систему
recipe_repo = RecipeRepository(recipes_data)
calculator = ChemistryCalculator(recipe_repo)
# Получаем список веществ
available_substances = get_available_substances(recipes_data)
# Создаём и показываем окно
window = ChemistryHelperWindow(calculator, available_substances)
window.show()
# Запускаем приложение
return app.exec_()
if __name__ == "__main__":
sys.exit(main())