GUI: added busy message to gonio and beamline camera thread

This commit is contained in:
appleb_m
2025-12-10 14:19:25 +01:00
parent e494fac5dd
commit b6ebcf0dbd
2 changed files with 49 additions and 2 deletions
+2
View File
@@ -447,6 +447,8 @@ class MainWindow(QMainWindow):
@Slot(DAQStatusModel)
def update_daq_status(self, s: DAQStatusModel):
self.beamline_camera_thread.set_busy(s.busy)
self.gonio_camera_thread.set_busy(s.busy)
if not self.__mounting and s.state == BeamlineStateEnum.RobotSampleExchange:
self.__mounting = True
self.video_tab.setCurrentIndex(3)
+47 -2
View File
@@ -1,8 +1,8 @@
import cv2
import requests
import numpy as np
from PySide6.QtCore import QThread, Signal
from PySide6.QtGui import QImage
from PySide6.QtCore import QThread, Signal, QRect, QPoint
from PySide6.QtGui import QImage, QPainter, QPen, QColor, Qt, QFontMetrics, QFont
from io import BytesIO
@@ -17,10 +17,14 @@ class VideoThread(QThread):
self.session = None
self.last_good_frame = None
self.camera: int = camera
self.is_busy = False
def set_camera_ip(self, ip: str):
self.camera_ip = ip
def set_busy(self, busy: bool):
self.is_busy = busy
def run(self):
# MJPEG URL
mjpeg_url = f"http://{self.camera_ip}/axis-cgi/mjpg/video.cgi?resolution=1280x720&fps=20&compression=30&camera={self.camera}"
@@ -113,6 +117,9 @@ class VideoThread(QThread):
height, width, channel = rgb_frame.shape
bytes_per_line = 3 * width
qt_image = QImage(rgb_frame.data, width, height, bytes_per_line, QImage.Format.Format_RGB888)
qt_image = qt_image.copy()
if self.is_busy:
self._draw_busy_overlay(qt_image)
# Store as last good frame
self.last_good_frame = qt_image
@@ -123,6 +130,44 @@ class VideoThread(QThread):
if self.last_good_frame is not None:
self.frame_ready.emit(self.last_good_frame)
def _draw_busy_overlay(self, image: QImage):
painter = QPainter(image)
painter.save()
painter.resetTransform()
font = QFont()
font.setPointSize(24)
font.setBold(True)
painter.setFont(font)
painter.setPen(QPen(QColor(255, 255, 255, 200), 2, Qt.PenStyle.SolidLine))
painter.setBrush(QColor(255, 0, 0, 150))
text = "ROBOT BUSY"
fm = QFontMetrics(font)
text_rect = fm.boundingRect(text)
padding = 16
vw = self.viewport().width()
vh = self.viewport().height()
bg_w = text_rect.width() + 2 * padding
bg_h = text_rect.height() + 2 * padding
position_x = int((vw - bg_w) / 2)
position_y = int((vh - bg_h) / 2)
bg_rect = QRect(position_x, position_y, bg_w, bg_h)
painter.setPen(QPen(QColor(255, 255, 255, 220)))
painter.setBrush(QColor(255, 215, 0, 180))
painter.drawRoundedRect(bg_rect, 10, 10)
painter.setPen(QPen(QColor(255, 255, 255)))
painter.drawText(QPoint(position_x + padding, position_y + padding + fm.ascent()), text)
painter.restore()
def stop(self):
self.running = False
if self.session: