AI_MMI_Analyser/app/ui/components/status_lamp.py

38 lines
1.4 KiB
Python

from PySide6.QtWidgets import QLabel
from PySide6.QtCore import Qt
class StatusLamp(QLabel):
def __init__(self, text, on_color="#00FF00", off_color="#333333", text_color="white", font_size=10, shape="rect"):
super().__init__(text)
self.setAlignment(Qt.AlignCenter)
self.on_color = on_color
self.off_color = off_color
self.text_color = text_color
self.shape = shape
# 기본 스타일 정의
radius = "12px" if shape == "circle" else "2px"
padding = "2px"
self.base_style = f"""
QLabel {{
color: {self.text_color};
border: 1px solid #555555;
border-radius: {radius};
font-family: 'Malgun Gothic';
font-weight: bold;
font-size: {font_size}pt;
padding: {padding};
}}
"""
self.set_status(False)
def set_status(self, is_on: bool):
bg = self.on_color if is_on else self.off_color
# 켜졌을 때 글자색을 검정으로 할지 흰색으로 할지 (가독성)
fg = "black" if (is_on and self.on_color in ["#00FF00", "#FFFF00", "#00BFFF", "#FFA500"]) else self.text_color
self.setStyleSheet(f"""
{self.base_style}
QLabel {{ background-color: {bg}; color: {fg}; }}
""")