feat: add semantic status bar colors

This commit is contained in:
chengma
2026-07-07 15:42:19 +08:00
parent 8bd6a1df91
commit 9ce4d2442e
14 changed files with 171 additions and 43 deletions
+55
View File
@@ -91,6 +91,14 @@ COLOR_PENDING = "#9a6700"
COLOR_MUTED = "#6e7781"
COLOR_WARNING = "#bc4c00"
COLOR_DANGER_BG = "#ffebe9"
STATUS_LEVEL_COLORS = {
"muted": COLOR_MUTED,
"info": COLOR_INFO,
"success": COLOR_SUCCESS,
"warning": COLOR_WARNING,
"danger": COLOR_DANGER,
"pending": COLOR_PENDING,
}
BUTTON_RADIUS_PX = 4
BUTTON_BASE_STYLE = f"""
QPushButton {{
@@ -193,6 +201,53 @@ def _status_base_color(status):
return None
def _status_level_color(level):
return STATUS_LEVEL_COLORS.get(str(level or "muted"), COLOR_MUTED)
def _status_level_for_message(message, default="muted"):
text = str(message or "")
if any(keyword in text for keyword in ("失败", "错误", "异常", "未登录", "不可写", "点数不足", "阻止")):
return "danger"
if any(keyword in text for keyword in ("没有", "请先", "未配置", "不完整", "已取消", "不能", "无法")):
return "warning"
if any(
keyword in text
for keyword in (
"完成",
"成功",
"已保存",
"已回写",
"已新增",
"已删除",
"已软删除",
"已重置",
"已刷新",
"已修改",
"已启动",
"已复用",
"已生成",
"已新建",
"已另存为",
"已重命名",
)
):
return "success"
if any(keyword in text for keyword in ("正在", "开始", "进度", "检测中")):
return "info"
return default
def _emit_status(callback, message, level=None):
if callback is None:
return
actual_level = level or _status_level_for_message(message)
try:
callback(str(message), level=actual_level)
except TypeError:
callback(str(message))
def _danger_metric_text(text, active):
if not active:
return text