Commit 04882a00 authored by AJ Fite's avatar AJ Fite 🛫

Completed making image handling thread safe

parent 7cccc2bd
0.1.0-ALPHA2
\ No newline at end of file
0.1.0-ALPHA3
\ No newline at end of file
import os
from PyQt5.QtCore import QThread, pyqtSignal
from watchdog.events import PatternMatchingEventHandler
from datetime import date
from datetime import datetime
from .config import Config
from watchdog.observers import Observer
......@@ -11,15 +10,12 @@ from watchdog.observers import Observer
class FileHandlerUtils:
@staticmethod
def compute_current_data_dir():
today = date.today()
today = datetime.utcnow()
return Config.lepton_grabber_working_dir + "/" \
+ today.strftime("%y-%m-%d")
# TODO: This needs to be thread safe
# Good example:
# https://github.com/yesworkflow-org/yw-gui/blob/master/main_ui.py
class ImageThread(QThread):
new_image = pyqtSignal(str)
......@@ -31,7 +27,6 @@ class ImageThread(QThread):
self.event_thread = event_thread
def on_created(self, event):
print("Update image")
self.event_thread.new_image.emit(event.src_path)
def run(self):
......@@ -44,6 +39,7 @@ class ImageThread(QThread):
os.mkdir(datadir)
observer = Observer()
# FIXME: When this ticks over to the next day it fails to update
observer.schedule(self.ImageHandler(self), path=datadir)
observer.start()
......@@ -51,8 +47,6 @@ class ImageThread(QThread):
# TODO: This needs to be thread safe
# Good example:
# https://github.com/yesworkflow-org/yw-gui/blob/master/main_ui.py
class CSVHandler(PatternMatchingEventHandler):
patterns = ["*.csv"]
main = None
......@@ -62,6 +56,4 @@ class CSVHandler(PatternMatchingEventHandler):
self.main = mainwindow
def on_created(self, event):
# TODO: use this to determine percentage complete
# TODO: Update irradiance count
print("New CSV")
......@@ -4,7 +4,8 @@ import webbrowser
from PyQt5 import uic
import pkg_resources
from PyQt5.QtCore import QProcess, QProcessEnvironment, Qt
from PyQt5.QtWidgets import QMainWindow, QApplication
from PyQt5.QtGui import QPixmap
from PyQt5.QtWidgets import QMainWindow, QApplication, QGraphicsScene
from .filehandlers import ImageThread
from .sudo import PasswordWindow
from .about import AboutDialog
......@@ -54,8 +55,52 @@ class MainWindow(QMainWindow):
self.cameraCount.display("OFF")
self.solarIrradiance.display("OFF")
# Init the scenes for the graphics displays
self.sceneN = QGraphicsScene()
self.imgN.setScene(self.sceneN)
self.sceneNE = QGraphicsScene()
self.imgNE.setScene(self.sceneNE)
self.sceneE = QGraphicsScene()
self.imgE.setScene(self.sceneE)
self.sceneSE = QGraphicsScene()
self.imgSE.setScene(self.sceneSE)
self.sceneS = QGraphicsScene()
self.imgS.setScene(self.sceneS)
self.sceneSW = QGraphicsScene()
self.imgSW.setScene(self.sceneSW)
self.sceneW = QGraphicsScene()
self.imgW.setScene(self.sceneW)
self.sceneNW = QGraphicsScene()
self.imgNW.setScene(self.sceneNW)
self.sceneCenter = QGraphicsScene()
self.imgCenter.setScene(self.sceneCenter)
self.current = 0
# Updates the image and determines the capture progress
def update_image(self, path):
print("New Image! " + path)
pix = QPixmap(path)
if self.current == 0:
self.sceneNW.addPixmap(pix)
elif self.current == 1:
self.sceneN.addPixmap(pix)
elif self.current == 2:
self.sceneNE.addPixmap(pix)
elif self.current == 3:
self.sceneW.addPixmap(pix)
elif self.current == 4:
self.sceneCenter.addPixmap(pix)
elif self.current == 5:
self.sceneE.addPixmap(pix)
elif self.current == 6:
self.sceneSW.addPixmap(pix)
elif self.current == 7:
self.sceneS.addPixmap(pix)
elif self.current == 8:
self.sceneSE.addPixmap(pix)
# TODO: Capture progress
self.current = (self.current + 1) % Config.dbg_lepton_set
# Opens a link
@staticmethod
......@@ -109,6 +154,7 @@ class MainWindow(QMainWindow):
# Triggered when the QProcess that runs the lepton-grabber runs
def process_started(self):
self.button_toggle(True)
self.current = 0
self.png_watcher.start()
# Triggered when the QProcess that runs the lepton-grabber dies for any
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment