''' app/ui/widgets/statusbar.py ''' import os.path import socket import threading import time from PyQt6.QtCore import Qt, QTimer from PyQt6.QtGui import QPixmap from PyQt6.QtWidgets import QStatusBar, QLabel from src.api.server_proxy import RenderServerProxy from src.utilities.misc_helper import resources_dir class StatusBar(QStatusBar): """ Initialize the status bar. Args: parent: The parent widget. """ def __init__(self, parent) -> None: super().__init__(parent) def background_update(): proxy = RenderServerProxy(socket.gethostname()) proxy.start_background_update() image_names = {'Ready': 'GreenCircle.png', 'Offline': "RedSquare.png"} last_update = None # Check for status change every 1s on background thread while True: new_status = proxy.status() if new_status is not last_update: new_image_name = image_names.get(new_status, 'Synchronize.png') image_path = os.path.join(resources_dir(), 'icons', new_image_name) self.label.setPixmap((QPixmap(image_path).scaled(16, 16, Qt.AspectRatioMode.KeepAspectRatio))) self.messageLabel.setText(new_status) last_update = new_status time.sleep(1) background_thread = threading.Thread(target=background_update,) background_thread.daemon = True background_thread.start() # Create a label that holds an image self.label = QLabel() image_path = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), 'resources', 'icons', 'RedSquare.png') pixmap = (QPixmap(image_path).scaled(16, 16, Qt.AspectRatioMode.KeepAspectRatio)) self.label.setPixmap(pixmap) self.addWidget(self.label) # Create a label for the message self.messageLabel = QLabel() self.addWidget(self.messageLabel) # Call this method to display a message self.messageLabel.setText("Loading...")