""" Confidence Bar Widget Horizontal progress bar for displaying confidence scores. """ from PyQt5.QtWidgets import QWidget, QHBoxLayout, QLabel, QProgressBar from PyQt5.QtCore import Qt from PyQt5.QtGui import QFont class ConfidenceBar(QWidget): """ Horizontal confidence bar with label and percentage. Args: label: Label text (e.g., "Ripe") color: Bar color hex code parent: Parent widget """ def __init__(self, label: str, color: str = "#27ae60", parent=None): super().__init__(parent) self.color = color self.init_ui(label) def init_ui(self, label: str): """Initialize the confidence bar UI.""" layout = QHBoxLayout(self) layout.setContentsMargins(0, 5, 0, 5) layout.setSpacing(10) # Label self.label = QLabel(label + ":") self.label.setFont(QFont("Arial", 9)) self.label.setMinimumWidth(70) layout.addWidget(self.label) # Progress bar self.progress_bar = QProgressBar() self.progress_bar.setFixedHeight(12) self.progress_bar.setMaximum(100) self.progress_bar.setValue(0) self.progress_bar.setTextVisible(False) self.progress_bar.setStyleSheet(f""" QProgressBar {{ background-color: #ecf0f1; border: 1px solid #bdc3c7; border-radius: 2px; }} QProgressBar::chunk {{ background-color: {self.color}; border-radius: 2px; }} """) layout.addWidget(self.progress_bar, 1) # Percentage label self.percent_label = QLabel("0.0%") self.percent_label.setFont(QFont("Arial", 9)) self.percent_label.setMinimumWidth(50) self.percent_label.setStyleSheet("color: #2c3e50;") layout.addWidget(self.percent_label) def set_value(self, value: float, is_primary: bool = False): """ Set the confidence value. Args: value: Confidence value (0-100) is_primary: Whether this is the primary/selected classification """ self.progress_bar.setValue(int(value)) self.percent_label.setText(f"{value:.1f}%") # Bold text for primary classification if is_primary: self.label.setStyleSheet("font-weight: bold; color: #2c3e50;") self.percent_label.setStyleSheet("font-weight: bold; color: #2c3e50;") else: self.label.setStyleSheet("color: #2c3e50;") self.percent_label.setStyleSheet("color: #2c3e50;")