feat(gui): improve status scope dialogs

This commit is contained in:
chengma
2026-07-18 17:23:22 +08:00
parent 89f1b085dc
commit 7538009f94
8 changed files with 218 additions and 62 deletions
+104
View File
@@ -292,6 +292,110 @@ def _danger_outline_button_style(object_name):
)
def _primary_button_style(object_name):
return (
f"QPushButton#{object_name} {{ "
f"background-color: {COLOR_INFO}; border-color: {COLOR_INFO}; "
"color: white; font-weight: 600; "
"}"
f"QPushButton#{object_name}:hover {{ "
"background-color: #0550ae; border-color: #0550ae; "
"}"
f"QPushButton#{object_name}:pressed {{ "
"background-color: #033d8b; border-color: #033d8b; "
"}"
)
class ProductStatusScopeDialog(QDialog):
"""供采集和生成复用的稳定中文范围选择框。"""
MINIMUM_WIDTH = 520
def __init__(
self,
title,
text,
informative_text,
normal_text,
all_text,
normal_value,
all_value,
normal_object_name,
all_object_name,
cancel_object_name,
all_enabled=True,
parent=None,
):
super().__init__(parent)
self._choice = None
self._informative_text = str(informative_text or "")
self.setWindowTitle(str(title or "选择范围"))
self.setModal(True)
self.setMinimumWidth(self.MINIMUM_WIDTH)
self.setStyleSheet(BUTTON_BASE_STYLE)
layout = QVBoxLayout(self)
layout.setContentsMargins(20, 18, 20, 18)
layout.setSpacing(10)
title_label = QLabel(str(text or ""))
title_label.setObjectName("productStatusScopeTitleLabel")
title_label.setWordWrap(True)
title_label.setStyleSheet("font-weight: 600; color: #24292f;")
layout.addWidget(title_label)
detail_label = QLabel(self._informative_text)
detail_label.setObjectName("productStatusScopeDetailLabel")
detail_label.setWordWrap(True)
detail_label.setStyleSheet("color: #57606a;")
layout.addWidget(detail_label)
layout.addSpacing(2)
self.normal_button = QPushButton(str(normal_text or ""))
self.normal_button.setObjectName(str(normal_object_name))
self.normal_button.setMinimumWidth(self.MINIMUM_WIDTH - 40)
self.normal_button.setMinimumHeight(34)
self.normal_button.setDefault(True)
self.normal_button.setFocus()
self.normal_button.setStyleSheet(_primary_button_style(normal_object_name))
self.normal_button.clicked.connect(lambda: self._accept_choice(normal_value))
layout.addWidget(self.normal_button)
self.all_button = QPushButton(str(all_text or ""))
self.all_button.setObjectName(str(all_object_name))
self.all_button.setMinimumWidth(self.MINIMUM_WIDTH - 40)
self.all_button.setMinimumHeight(34)
self.all_button.setEnabled(bool(all_enabled))
self.all_button.setStyleSheet(_warning_outline_button_style(all_object_name))
self.all_button.clicked.connect(lambda: self._accept_choice(all_value))
layout.addWidget(self.all_button)
self.cancel_button = QPushButton("取消")
self.cancel_button.setObjectName(str(cancel_object_name))
self.cancel_button.setMinimumWidth(self.MINIMUM_WIDTH - 40)
self.cancel_button.setMinimumHeight(32)
self.cancel_button.clicked.connect(self.reject)
layout.addWidget(self.cancel_button)
def defaultButton(self):
"""供调用方和 GUI 测试读取明确的默认按钮。"""
return self.normal_button
def informativeText(self):
"""按 QMessageBox 兼容接口返回说明文字。"""
return self._informative_text
def choice(self):
return self._choice
def _accept_choice(self, value):
self._choice = value
self.accept()
def _login_status_display(status):
return f"● {status or '未知'}"