working logic+working watching files+added calibration feature+instructions

This commit is contained in:
Vic Sergeev 2026-05-07 21:13:00 +03:00
parent 09d181eba8
commit 97ed8217bf
25 changed files with 1743 additions and 192 deletions

View file

@ -25,7 +25,17 @@ class PhotoHandler(FileSystemEventHandler):
if not event.is_directory:
src_path = Path(event.src_path)
if FileService.is_photo(src_path):
time.sleep(0.1) # Даём время на запись файла
print(f"[Watchdog] Обнаружен файл: {src_path}")
time.sleep(0.1)
self._pending_files.put(src_path)
def on_modified(self, event):
"""Также обрабатываем modified, так как некоторые программы сначала создают временный файл"""
if not event.is_directory:
src_path = Path(event.src_path)
if FileService.is_photo(src_path):
print(f"[Watchdog] Изменён файл: {src_path}")
time.sleep(0.1)
self._pending_files.put(src_path)
def _process_queue(self):
@ -52,24 +62,33 @@ class WatchService:
self._is_running = False
def start(self, watch_folder: Path, on_new_file: Callable[[Path], None]) -> bool:
"""Запускает отслеживание папки"""
if self._is_running:
print("Watcher already running")
return False
if not watch_folder.exists():
print(f"Папка не существует: {watch_folder}")
return False
try:
print(f"Запуск отслеживания папки: {watch_folder}")
self._event_handler = PhotoHandler(on_new_file)
self._observer = Observer()
self._observer.schedule(self._event_handler, str(watch_folder), recursive=False)
self._observer.start()
self._is_running = True
print(f"Отслеживание успешно запущено для: {watch_folder}")
return True
except Exception as e:
print(f"Ошибка запуска отслеживания: {e}")
import traceback
traceback.print_exc()
return False
def stop(self):
"""Останавливает отслеживание"""
print("Остановка отслеживания...")
if self._observer:
self._observer.stop()
self._observer.join()
@ -80,12 +99,13 @@ class WatchService:
self._event_handler = None
self._is_running = False
print("Отслеживание остановлено")
def is_running(self) -> bool:
return self._is_running
def move_all_existing_files(self, watch_folder: Path, on_file_moved: Callable[[Path], None]) -> int:
"""Перемещает все существующие файлы"""
"""Перемещает все существующие файлы из папки наблюдения"""
count = 0
if watch_folder.exists():
for file_path in watch_folder.iterdir():