97 lines
3.0 KiB
Python
97 lines
3.0 KiB
Python
|
|
#!/usr/bin/env python3
|
||
|
|
"""
|
||
|
|
Comfy-Studio — галерея и менеджер изображений, сгенерированных в ComfyUI.
|
||
|
|
Точка входа: логирование, БД, вотчер папок, запуск GUI.
|
||
|
|
"""
|
||
|
|
|
||
|
|
import sys
|
||
|
|
import os
|
||
|
|
import logging
|
||
|
|
from pathlib import Path
|
||
|
|
|
||
|
|
# Корень проекта в путях поиска модулей
|
||
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||
|
|
|
||
|
|
from PyQt6.QtWidgets import QApplication
|
||
|
|
from PyQt6.QtCore import Qt
|
||
|
|
|
||
|
|
from comfy_studio.core.config import APP_NAME, DB_PATH, LOG_PATH, LOGGING_LEVEL
|
||
|
|
from comfy_studio.core.settings import load_settings
|
||
|
|
from comfy_studio.core.i18n import set_language
|
||
|
|
from comfy_studio.db.manager import DBManager
|
||
|
|
from comfy_studio.services.watcher import FolderWatcher
|
||
|
|
|
||
|
|
|
||
|
|
def configure_logging() -> None:
|
||
|
|
logging.basicConfig(
|
||
|
|
level=getattr(logging, LOGGING_LEVEL.upper(), logging.INFO),
|
||
|
|
format="%(asctime)s [%(levelname)s] %(name)s: %(message)s",
|
||
|
|
datefmt="%Y-%m-%d %H:%M:%S",
|
||
|
|
handlers=[
|
||
|
|
logging.FileHandler(str(LOG_PATH), encoding="utf-8"),
|
||
|
|
logging.StreamHandler(sys.stdout),
|
||
|
|
],
|
||
|
|
)
|
||
|
|
logging.getLogger("PIL").setLevel(logging.WARNING)
|
||
|
|
logging.getLogger("watchdog").setLevel(logging.INFO)
|
||
|
|
|
||
|
|
|
||
|
|
def main() -> int:
|
||
|
|
configure_logging()
|
||
|
|
logger = logging.getLogger(__name__)
|
||
|
|
logger.info(f"{APP_NAME} запускается...")
|
||
|
|
|
||
|
|
# Настройки и язык (до создания UI!)
|
||
|
|
settings = load_settings()
|
||
|
|
set_language(settings.get("language", "ru"))
|
||
|
|
|
||
|
|
# База данных
|
||
|
|
try:
|
||
|
|
db_manager = DBManager(str(DB_PATH))
|
||
|
|
logger.info(f"База данных готова: {DB_PATH}")
|
||
|
|
except Exception as e:
|
||
|
|
logger.critical(f"Не удалось инициализировать БД: {e}")
|
||
|
|
return 1
|
||
|
|
|
||
|
|
# Гарантируем существование отслеживаемых папок
|
||
|
|
tracked_paths = settings.get("tracked_paths", [])
|
||
|
|
for path_str in tracked_paths:
|
||
|
|
Path(path_str).mkdir(parents=True, exist_ok=True)
|
||
|
|
|
||
|
|
# Фоновый вотчер
|
||
|
|
watcher = FolderWatcher(db_manager)
|
||
|
|
watcher.start_monitoring(tracked_paths)
|
||
|
|
|
||
|
|
# High DPI (до создания QApplication)
|
||
|
|
QApplication.setHighDpiScaleFactorRoundingPolicy(
|
||
|
|
Qt.HighDpiScaleFactorRoundingPolicy.PassThrough
|
||
|
|
)
|
||
|
|
|
||
|
|
app = QApplication(sys.argv)
|
||
|
|
app.setApplicationName(APP_NAME)
|
||
|
|
app.setStyle("Fusion")
|
||
|
|
|
||
|
|
# Импорт окна после создания QApplication
|
||
|
|
from comfy_studio.ui.main_window import MainWindow
|
||
|
|
|
||
|
|
window = MainWindow(db_manager, watcher)
|
||
|
|
|
||
|
|
if tracked_paths:
|
||
|
|
window.left_panel.set_root_path(tracked_paths[0])
|
||
|
|
window.load_folder_images(tracked_paths[0])
|
||
|
|
|
||
|
|
window.show()
|
||
|
|
logger.info("UI запущен.")
|
||
|
|
|
||
|
|
try:
|
||
|
|
exit_code = app.exec()
|
||
|
|
finally:
|
||
|
|
watcher.stop_monitoring()
|
||
|
|
logger.info(f"{APP_NAME} завершён.")
|
||
|
|
|
||
|
|
return exit_code
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
sys.exit(main())
|