fix(ui): align AI lamp with text across display scaling
Core regression / Python 3.12 core, intervention UI and release configuration (push) Failing after 21s
Core regression / JavaScript syntax (push) Successful in 5s
Core regression / Python 3.12 core, intervention UI and release configuration (pull_request) Failing after 21s
Core regression / JavaScript syntax (pull_request) Successful in 2s

This commit is contained in:
阿白叔 committed 2026-11-05 16:40:00 +08:00
1 parent cf6e3f9d2a
commit 3ecb6fa276
2 files changed
+32 -16

No files matched your search

@@ -1,6 +1,6 @@
"""Non-blocking model readiness and visible automatic-intervention state."""
from PySide6.QtCore import QObject, QSize, Qt, QTimer
from PySide6.QtGui import QColor, QIcon, QPainter, QPixmap
from PySide6.QtCore import QObject, QPointF, QRectF, QSize, Qt, QTimer
from PySide6.QtGui import QColor, QFontMetricsF, QPainter
from PySide6.QtWidgets import QToolButton
from ...dsh.availability import check_availability
@@ -12,8 +12,6 @@ class DshStatusIndicator(QToolButton):
def __init__(self, parent=None):
super().__init__(parent, objectName='dshAiStatus')
self.setAutoRaise(True)
self.setToolButtonStyle(Qt.ToolButtonStyle.ToolButtonTextBesideIcon)
self.setIconSize(QSize(18, 18))
self.setCursor(Qt.CursorShape.PointingHandCursor)
self.setStyleSheet('QToolButton#dshAiStatus, QToolButton#dshAiStatus:hover, '
'QToolButton#dshAiStatus:pressed {border: none; background: transparent; padding: 0 2px;}')
@@ -22,22 +20,36 @@ class DshStatusIndicator(QToolButton):
def set_state(self, state, label, details):
colors = {'idle': '#2bb673', 'working': '#e7ad21', 'checking': '#e7ad21',
'unavailable': '#e04b5a', 'attention': '#e04b5a', 'silent': '#929aa6'}
if self.property('state') != state:
pixmap = QPixmap(36, 36)
pixmap.fill(Qt.GlobalColor.transparent)
painter = QPainter(pixmap)
painter.setRenderHint(QPainter.RenderHint.Antialiasing)
painter.setPen(Qt.PenStyle.NoPen)
color = QColor(colors[state])
painter.setBrush(color)
painter.drawEllipse(8, 8, 20, 20)
painter.end()
self.setIcon(QIcon(pixmap))
self.setProperty('state', state)
self._light_color = QColor(colors[state])
self.setProperty('state', state)
self.setText('AI · ' + label)
self.setToolTip(details)
self.setAccessibleName('AI 自动介入:' + label)
self.setAccessibleDescription(details)
self.update()
def sizeHint(self):
self.ensurePolished()
return QSize(self.fontMetrics().horizontalAdvance(self.text()) + 28, 34)
def minimumSizeHint(self):
return self.sizeHint()
def paintEvent(self, event):
painter = QPainter(self)
painter.setRenderHint(QPainter.RenderHint.Antialiasing)
metrics = QFontMetricsF(painter.font())
baseline = (self.height() - metrics.height()) / 2 + metrics.ascent()
# The lamp follows the rendered glyphs, including Chinese fallback fonts.
center_y = baseline + metrics.tightBoundingRect(self.text()).center().y()
painter.setPen(Qt.PenStyle.NoPen)
painter.setBrush(self._light_color)
painter.drawEllipse(QRectF(4, center_y - 5, 10, 10))
painter.setPen(self.palette().buttonText().color())
painter.drawText(QPointF(22, baseline), self.text())
if self.hasFocus():
painter.setPen(self.palette().highlight().color())
painter.drawLine(QPointF(22, baseline + 2), QPointF(self.width() - 4, baseline + 2))
class DshStatusController(QObject):