2024-11-08 10:50:18 +03:00
|
|
|
|
import pyqtgraph as pg
|
|
|
|
|
|
|
2024-11-11 13:05:18 +03:00
|
|
|
|
from src.gui import app
|
2024-11-08 10:50:18 +03:00
|
|
|
|
|
2024-11-12 19:26:38 +03:00
|
|
|
|
import os
|
|
|
|
|
|
import time
|
|
|
|
|
|
from PyQt5.QtCore import QThread, pyqtSignal, QObject
|
|
|
|
|
|
from watchdog.observers import Observer
|
|
|
|
|
|
from watchdog.events import FileSystemEventHandler
|
|
|
|
|
|
|
2024-11-08 10:50:18 +03:00
|
|
|
|
def main():
|
2024-11-12 19:26:38 +03:00
|
|
|
|
pg.mkQApp()
|
|
|
|
|
|
apps = appHandler
|
|
|
|
|
|
directory_path = "D:/downloads/a22"
|
|
|
|
|
|
|
|
|
|
|
|
file_watcher_thread = FileWatcherThread(directory_path)
|
|
|
|
|
|
file_watcher_thread.worker.file_detected.connect(get)
|
|
|
|
|
|
file_watcher_thread.start()
|
|
|
|
|
|
|
2024-11-08 10:50:18 +03:00
|
|
|
|
pg.exec()
|
2024-11-12 19:26:38 +03:00
|
|
|
|
#temp = app()
|
|
|
|
|
|
|
|
|
|
|
|
def get(path):
|
|
|
|
|
|
time.sleep(1)
|
|
|
|
|
|
temp = app(path)
|
|
|
|
|
|
|
|
|
|
|
|
class appHandler:
|
|
|
|
|
|
def __init__(self):
|
|
|
|
|
|
self.appTemp = []
|
|
|
|
|
|
|
|
|
|
|
|
def makeApp(self, result):
|
|
|
|
|
|
self.appTemp.append(app(result))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class FileWatcherWorker(QObject):
|
|
|
|
|
|
file_detected = pyqtSignal(str) # Сигнал для передачи пути к новому файлу
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, directory_path):
|
|
|
|
|
|
super().__init__()
|
|
|
|
|
|
self.directory_path = directory_path
|
|
|
|
|
|
self.observer = Observer()
|
|
|
|
|
|
self._running = True
|
|
|
|
|
|
|
|
|
|
|
|
def start_watching(self):
|
|
|
|
|
|
# Настраиваем наблюдателя и запускаем его
|
|
|
|
|
|
event_handler = CSVFileHandler(self.file_detected)
|
|
|
|
|
|
self.observer.schedule(event_handler, self.directory_path, recursive=False)
|
|
|
|
|
|
self.observer.start()
|
|
|
|
|
|
|
|
|
|
|
|
def stop_watching(self):
|
|
|
|
|
|
self._running = False
|
|
|
|
|
|
self.observer.stop()
|
|
|
|
|
|
self.observer.join()
|
|
|
|
|
|
|
|
|
|
|
|
class CSVFileHandler(FileSystemEventHandler):
|
|
|
|
|
|
def __init__(self, file_detected_signal):
|
|
|
|
|
|
super().__init__()
|
|
|
|
|
|
self.file_detected_signal = file_detected_signal
|
|
|
|
|
|
|
|
|
|
|
|
def on_created(self, event):
|
|
|
|
|
|
# Проверяем, что это файл и что он имеет расширение .csv
|
|
|
|
|
|
if not event.is_directory and event.src_path.endswith(".csv"):
|
|
|
|
|
|
abs_path = os.path.abspath(event.src_path)
|
|
|
|
|
|
print(f"Найден новый CSV файл: {abs_path}")
|
|
|
|
|
|
self.file_detected_signal.emit(abs_path) # Испускаем сигнал с путем к файлу
|
|
|
|
|
|
|
|
|
|
|
|
class FileWatcherThread(QThread):
|
|
|
|
|
|
def __init__(self, directory_path):
|
|
|
|
|
|
super().__init__()
|
|
|
|
|
|
self.worker = FileWatcherWorker(directory_path)
|
|
|
|
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
|
|
self.worker.start_watching() # Запуск наблюдателя
|
|
|
|
|
|
self.exec_() # Запускаем событийный цикл в потоке
|
2024-11-08 10:50:18 +03:00
|
|
|
|
|
2024-11-12 19:26:38 +03:00
|
|
|
|
def stop(self):
|
|
|
|
|
|
self.worker.stop_watching() # Остановка наблюдателя
|
2024-11-08 10:50:18 +03:00
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
|
main()
|