# -*- coding: utf-8 -*- """ 生成 src/mainwindow.ui (Qt Designer XML) DDR5 RDIMM SLT 上位机监控平台 —— 多工位测试监控界面 用法: python tools/gen_ui.py 说明: * 界面结构 100% 落在 .ui 文件里,可直接用 Qt Designer 打开继续拖拽编辑; * 所有颜色/字号/圆角集中在 src/style/app.qss,.ui 里只保留结构 + role 属性, 便于改主题;动态属性(role / tone / pill)用作 QSS 选择器钩子。 """ import os import textwrap ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) OUT = os.path.join(ROOT, "src", "mainwindow.ui") MAXW = 16777215 # -------------------------------------------------------------------------- # XML 片段工具 # -------------------------------------------------------------------------- def esc(v): return (v.replace("&", "&").replace("<", "<").replace(">", ">") .replace('"', """)) def prop(name, inner, stdset=False): a = ' stdset="0"' if stdset else "" return '%s\n' % (name, a, inner) def pstr(name, v, stdset=False): return prop(name, "%s" % esc(v), stdset) def pnum(name, v): return prop(name, "%s" % v) def ppixmap(name, path): return prop(name, '%s' % esc(path)) def pbool(name, v): return prop(name, "%s" % ("true" if v else "false")) def psize(name, w, h, stdset=False): return prop(name, "%d%d" % (w, h), stdset) def penum(name, v): return prop(name, "%s" % v) def palign(expr): return prop("alignment", "%s" % expr) def prect(name, x, y, w, h): return prop(name, "%d%d%d%d" % (x, y, w, h)) def pspol(h="Preferred", v="Preferred", hs=0, vs=0): return prop("sizePolicy", '' "%d%d" % (h, v, hs, vs)) def pfixh(h): """固定高度:min=max=h,配合 Fixed 垂直策略使用""" return (psize("minimumSize", 0, h) + psize("maximumSize", MAXW, h) + pspol("Preferred", "Fixed")) def role(name): return pstr("role", name, stdset=True) def widget(cls, name, props="", body=""): s = '\n' % (cls, name) if props: s += textwrap.indent(props, " ") if body: s += textwrap.indent(body, " ") s += "\n" return s def layout(cls, name, items, spacing=0, margins=(0, 0, 0, 0), props=""): s = '\n' % (cls, name) l, t, r, b = margins inner = (pnum("leftMargin", l) + pnum("topMargin", t) + pnum("rightMargin", r) + pnum("bottomMargin", b) + pnum("spacing", spacing) + props) s += textwrap.indent(inner, " ") for it in items: s += textwrap.indent(it, " ") s += "\n" return s def it(w, row=None, col=None, rowspan=None): # 注意:uic 只允许 上的 row/column/rowspan/colspan,写 stretch 会报 Unexpected attribute, # 布局伸缩比例统一在 mainwindow.cpp 里用 setStretch() / setRowStretch() 设置 attr = ' row="%d" column="%d"' % (row, col) if row is not None else "" if rowspan and rowspan > 1: attr += ' rowspan="%d"' % rowspan return "\n" % attr + textwrap.indent(w, " ") + "\n" def stack(name, pages, current=0): """QStackedWidget:子页面直接内联,不能用 包裹""" s = '\n' % name s += textwrap.indent(penum("frameShape", "QFrame::NoFrame") + pnum("currentIndex", current), " ") for pg in pages: s += textwrap.indent(pg, " ") s += "\n" return s def spacer(name, w=20, h=20, orient="Qt::Horizontal", size_type="QSizePolicy::Fixed"): s = '\n' % name s += textwrap.indent(penum("orientation", orient), " ") if size_type: s += textwrap.indent(penum("sizeType", size_type), " ") s += textwrap.indent(psize("sizeHint", w, h, stdset=True), " ") s += "\n" return s def label(name, text, role_name=None, align=None, rich=False, size=None, maxsize=None, policy=None, props=""): p = pstr("text", text) if role_name: p += role(role_name) if align: p += palign(align) if rich: p += penum("textFormat", "Qt::RichText") if size: p += psize("minimumSize", size[0], size[1]) if maxsize: p += psize("maximumSize", maxsize[0], maxsize[1]) if policy: p += pspol(*policy) p += props return widget("QLabel", name, p) def vsep(name): return widget("QFrame", name, penum("frameShape", "QFrame::NoFrame") + role("vsep") + psize("minimumSize", 1, 0) + psize("maximumSize", 1, MAXW)) def hline(name, role_name="hsep"): return widget("QFrame", name, penum("frameShape", "QFrame::NoFrame") + role(role_name) + psize("minimumSize", 0, 1) + psize("maximumSize", MAXW, 1)) # -------------------------------------------------------------------------- # 顶部标题栏(只保留品牌区 + 窗口按钮;一级页签已按需求移除) # -------------------------------------------------------------------------- def build_header(): logo = widget("QLabel", "logoMark", ppixmap("pixmap", ":/assets/logo-mark.png") + role("logo") + palign("Qt::AlignCenter") + psize("minimumSize", 33, 32) + psize("maximumSize", 33, 32)) title = label("appTitle", "HOVSE SLT Pro", "appTitle", "Qt::AlignLeft|Qt::AlignVCenter") win_items = [it(widget("QPushButton", n, pstr("text", t) + role("win") + psize("minimumSize", 44, 44) + psize("maximumSize", 44, 44))) for n, t in (("btnWinMin", "—"), ("btnWinMax", "❐"), ("btnWinClose", "✕"))] bar = layout("QHBoxLayout", "headerLayout", [it(logo), it(title), it(spacer("headerSpacer", 40, 20, size_type="QSizePolicy::Expanding")), it(widget("QFrame", "headerSep", penum("frameShape", "QFrame::NoFrame") + role("headerSep") + psize("minimumSize", 1, 26) + psize("maximumSize", 1, 26)))] + win_items, spacing=10, margins=(18, 0, 0, 0)) return widget("QFrame", "header", penum("frameShape", "QFrame::NoFrame") + role("header") + psize("minimumSize", 0, 70) + psize("maximumSize", MAXW, 70), bar) # -------------------------------------------------------------------------- # 工位卡片 # -------------------------------------------------------------------------- STATE_MAP = {"p": "pass", "r": "run", "f": "fail", "i": "idle"} STATIONS = [ dict(sid="SLT-HT-001", temp="68.4°C", runtime="02:36:18", ch=["ppprpippppfp", "prppppprpppr"]), dict(sid="SLT-HT-002", temp="67.8°C", runtime="01:48:32", ch=["pppripppprpp", "pppppppprppp"]), dict(sid="SLT-HT-003", temp="70.2°C", runtime="00:58:41", ch=["ppprpppppprf", "prpppfpprprr"]), dict(sid="SLT-HT-004", temp="65.6°C", runtime="01:15:27", ch=["ppprrpppprpp", "prppppprpprr"]), ] def info_cell(idx, key, label_text, value, min_w=0, hs=2, bold=False): """信息列:字段名 / 数值 两行(下面的说明小字已按需求去掉),行高固定,两张卡节奏一致""" # 水平 Expanding:整行四块(温度 / 运行时间 / 开始测试 / 串口)等比例均分宽度, # 不再靠行尾 spacer 把富余一口吃掉、把内容全挤到左边 p = (penum("frameShape", "QFrame::NoFrame") + role("infoCell") + pspol("Expanding", "Preferred", hs)) if min_w: p += psize("minimumSize", min_w, 0) # 上下各一个弹性 spacer:两行文字在 70px 的行高里垂直居中(和右边的圆钮对齐) cell = layout("QVBoxLayout", "infoLayout_%d_%s" % (idx, key), [ it(spacer("infoPadTop_%d_%s" % (idx, key), 4, 2, orient="Qt::Vertical", size_type="QSizePolicy::Expanding")), it(label("infoLabel_%d_%s" % (idx, key), label_text, "fieldLabel", "Qt::AlignLeft|Qt::AlignBottom")), it(label("infoValue_%d_%s" % (idx, key), value, "fieldValueBold" if bold else "fieldValue", "Qt::AlignLeft|Qt::AlignVCenter")), it(spacer("infoPad_%d_%s" % (idx, key), 4, 2, orient="Qt::Vertical", size_type="QSizePolicy::Expanding")), ], spacing=1, margins=(10, 2, 6, 2)) return widget("QFrame", "infoCell_%d_%s" % (idx, key), p, cell) CARD_MIN_H = 0 OV_CELL_H = 36 # 最小高度:两行文字(16+18)留 2px 余量,窗口只有 700 时四行仍完整 OV_CELL_MAX_H = 56 # 窗口拉高时格子跟着长,最多到这里(再高就留白) OV_GRID_SPACING = 3 OV_STATE_TEXT = {"pass": "PASS", "fail": "FAIL", "idle": "IDLE"} def channel_names(): """24 通道顺序:CPU0_CHA..CHL、CPU1_CHA..CHL,与详情页保持一致""" return ["CPU%d_CH%s" % (c, s) for c in (0, 1) for s in "ABCDEFGHIJKL"] def ov_cell(idx, name, state): """总览卡里的通道格:上排通道名、下排状态字(PASS / FAIL / IDLE),配色由 QSS 按 state 切。 上下各放一个弹性 spacer:格子被拉高时两行文字保持贴在一起并垂直居中,而不是被拉散。""" body = layout("QVBoxLayout", "ovChCellLayout_%d_%s" % (idx, name), [ it(spacer("ovChPadTop_%d_%s" % (idx, name), 4, 2, orient="Qt::Vertical", size_type="QSizePolicy::Expanding")), it(label("ovChCellName_%d_%s" % (idx, name), name, "chCellName", "Qt::AlignCenter")), it(label("ovChCellValue_%d_%s" % (idx, name), OV_STATE_TEXT[state], "chCellValue", "Qt::AlignCenter")), it(spacer("ovChPadBot_%d_%s" % (idx, name), 4, 2, orient="Qt::Vertical", size_type="QSizePolicy::Expanding")), ], spacing=0, margins=(2, 1, 2, 1)) p = (penum("frameShape", "QFrame::NoFrame") + role("chCell") + pstr("state", state, stdset=True) + psize("minimumSize", 0, OV_CELL_H) + # 不再封顶高度:格子吃掉 GroupBox 里的全部剩余空间, # 否则多余高度会跑到图例行上,把图例顶到半空 pspol("Expanding", "Expanding")) return widget("QFrame", "ovChCell_%d_%s" % (idx, name), p, body) def build_station(idx, st): icon = widget("QLabel", "cardIcon_%d" % idx, pstr("text", "▤") + role("cardIcon") + palign("Qt::AlignCenter") + psize("minimumSize", 24, 24) + psize("maximumSize", 24, 24)) # 卡头右侧:COM 串口名 + COM 连接状态(状态用动态属性 state 切换 QSS 配色) # 串口名和状态灯都是纯文字(QSS 里已去掉外框),两行统一水平居中 com_name = widget("QLabel", "cardComName_%d" % idx, pstr("text", "—") + role("cardPort") + palign("Qt::AlignCenter") + psize("minimumSize", 0, 20)) com_chip = widget("QLabel", "cardCom_%d" % idx, pstr("text", "● 未配置") + role("comState") + pstr("state", "offline", stdset=True) + pstr("plain", "true", stdset=True) + palign("Qt::AlignCenter")) head = widget("QFrame", "cardHead_%d" % idx, penum("frameShape", "QFrame::NoFrame") + role("cardHead") + pfixh(26), layout("QHBoxLayout", "cardHeadLayout_%d" % idx, [ it(icon), it(label("cardName_%d" % idx, st["sid"], "cardName", "Qt::AlignLeft|Qt::AlignVCenter")), it(spacer("cardSpacer_%d" % idx, 12, 10, size_type="QSizePolicy::Expanding")), it(widget("QPushButton", "cardDetail_%d" % idx, pstr("text", "查看详情 >") + role("cardDetail"))), ], spacing=13, margins=(0, 0, 0, 0))) # 四块等比例分布:温度 │ 运行时间 │ 串口 │ 开始测试(串口和按钮的位置按需求对调), # 竖分界线固定 1px 不参与均分;按钮块内部左右各垫一个 Expanding spacer, # 圆钮始终落在自己那四分之一的正中。 btn_block = widget("QWidget", "btnBlock_%d" % idx, pspol("Expanding", "Preferred") + psize("minimumSize", 96, 0), layout("QHBoxLayout", "btnBlockLayout_%d" % idx, [ it(spacer("btnPadL_%d" % idx, 0, 0, size_type="QSizePolicy::Expanding")), it(widget("PowerButton", "startTest_%d" % idx, psize("minimumSize", 76, 78) + psize("maximumSize", 76, 78))), it(spacer("btnPadR_%d" % idx, 0, 0, size_type="QSizePolicy::Expanding")), ], spacing=0, margins=(0, 0, 0, 0))) com_block = widget("QWidget", "comWrap_%d" % idx, pspol("Expanding", "Preferred") + psize("minimumSize", 84, 0), layout("QVBoxLayout", "comWrapLayout_%d" % idx, [ it(com_name), it(com_chip), ], spacing=1, margins=(8, 0, 8, 0))) info_items = [ it(info_cell(idx, "temp", "腔体温度", st["temp"], 92, 2, bold=True)), it(vsep("vsepB_%d" % idx)), it(info_cell(idx, "runtime", "运行时间", st["runtime"], 100, 2, bold=True)), it(vsep("vsepC_%d" % idx)), it(com_block), it(vsep("vsepD_%d" % idx)), it(btn_block), ] # 行高 80:46px 的圆钮 + 下面一行 8.5pt 的「开始测试」,按钮实际占 78px。 # 文字区 = 78 - 47(圆底) - 2 = 29px,居中后上下各留 4~5px 呼吸; # 给到 70 会被切掉、给到 74 只是不切但仍然贴底,所以留到 80。 info_row = widget("QFrame", "infoRow_%d" % idx, penum("frameShape", "QFrame::NoFrame") + role("infoRow") + pfixh(80), layout("QHBoxLayout", "infoRowLayout_%d" % idx, info_items, spacing=0, margins=(0, 0, 0, 0))) # 24 通道:4 行 × 6 列,与详情页同一套格子样式(PASS / FAIL / IDLE) names = channel_names() states = [STATE_MAP[ch] for ch in (st["ch"][0] + st["ch"][1])] cells = [] for i, (nm, state) in enumerate(zip(names, states)): if state == "run": # RUN 状态已移除,统一按 PASS 展示 state = "pass" cells.append(it(ov_cell(idx, nm, state), i // 6, i % 6)) ch_grid = layout("QGridLayout", "ovChGrid_%d" % idx, cells, spacing=OV_GRID_SPACING, margins=(0, 0, 0, 0)) # 通道区块:普通文字标题(与详情页「24 通道内存测试状态」同一套 panelTitle 样式),不再加边框和图例 # 标题单独用 ovChTitle:上下各留 5px 呼吸空间(间距写在 QSS 的 padding 里) ch_block = layout("QVBoxLayout", "ovChLayout_%d" % idx, [it(panel_title("ovChTitle_%d" % idx, "24 通道内存测试状态", "ovChTitle")), it(ch_grid)], spacing=4, margins=(0, 0, 0, 0)) body = layout("QVBoxLayout", "cardLayout_%d" % idx, [ it(head), it(spacer("cardGapA_%d" % idx, 10, 4, orient="Qt::Vertical")), it(hline("cardLine1_%d" % idx)), it(spacer("cardGapB_%d" % idx, 10, 4, orient="Qt::Vertical")), it(info_row), it(spacer("cardGapC_%d" % idx, 10, 4, orient="Qt::Vertical")), it(ch_block), ], spacing=0, margins=(13, 9, 13, 8)) return widget("QFrame", "stationCard_%d" % idx, penum("frameShape", "QFrame::NoFrame") + role("station") + pspol("Expanding", "Expanding") + psize("minimumSize", 0, CARD_MIN_H), body) # -------------------------------------------------------------------------- # 内容区 # -------------------------------------------------------------------------- def build_content(): page_title = widget("QLabel", "pageTitle", pstr("text", "多工位测试监控" "  Multi-Station Monitor") + role("pageTitle") + penum("textFormat", "Qt::RichText") + palign("Qt::AlignLeft|Qt::AlignVCenter")) title_row = widget("QFrame", "titleRow", penum("frameShape", "QFrame::NoFrame") + role("titleRow") + pfixh(34), layout("QHBoxLayout", "titleRowLayout", [ it(page_title), it(spacer("titleSpacer", 30, 10, size_type="QSizePolicy::Expanding")), ], spacing=10)) grid = layout("QGridLayout", "stationGrid", [ it(build_station(0, STATIONS[0]), 0, 0), it(build_station(1, STATIONS[1]), 0, 1), it(build_station(2, STATIONS[2]), 1, 0), it(build_station(3, STATIONS[3]), 1, 1), ], spacing=14) body = layout("QVBoxLayout", "contentBody", [ it(title_row), it(grid), ], spacing=12, margins=(20, 8, 20, 14)) return widget("QWidget", "contentArea", role("contentArea"), layout("QVBoxLayout", "contentLayout", [ it(body), ], spacing=0)) # -------------------------------------------------------------------------- # 设备详情页(工位卡「查看详情 >」进入,返回键回多机监控) # -------------------------------------------------------------------------- def panel_title(name, text, role_name="panelTitle"): return label(name, text, role_name, "Qt::AlignLeft|Qt::AlignVCenter") # 详情页 24 通道:4 行 × 6 列(CPU0 十二通道 / CPU1 十二通道) # 状态合计:pass 16 + run 4 + fail 2 + idle 2 = 24(已装载 22,异常 2) DETAIL_CH = [ [("CPU0_CHA", "64.0", "pass"), ("CPU0_CHB", "67.5", "pass"), ("CPU0_CHC", "66.5", "pass"), ("CPU0_CHD", "65.5", "pass"), ("CPU0_CHE", "64.5", "pass"), ("CPU0_CHF", "68.0", "pass")], [("CPU0_CHG", "67.0", "pass"), ("CPU0_CHH", "66.0", "pass"), ("CPU0_CHI", "65.0", "pass"), ("CPU0_CHJ", "65.0", "fail"), ("CPU0_CHK", "67.5", "pass"), ("CPU0_CHL", "66.5", "pass")], [("CPU1_CHA", "65.5", "pass"), ("CPU1_CHB", "64.5", "pass"), ("CPU1_CHC", "68.0", "fail"), ("CPU1_CHD", "67.0", "pass"), ("CPU1_CHE", "66.0", "pass"), ("CPU1_CHF", "65.0", "pass")], [("CPU1_CHG", "64.0", "pass"), ("CPU1_CHH", "67.5", "pass"), ("CPU1_CHI", "66.5", "pass"), ("CPU1_CHJ", "—", "idle"), ("CPU1_CHK", "—", "idle"), ("CPU1_CHL", "68.0", "pass")], ] def ch_cell(name, label_text, temp, state): # 详情页只区分「已装载 / 未装载」:已装载统一蓝色(不再分 PASS/FAIL 配色) ui_state = "idle" if state == "idle" else "loaded" value = "--℃" if state == "idle" else "%s ℃" % temp body = layout("QVBoxLayout", "chCellLayout_%s" % name, [ it(spacer("chCellPadTop_%s" % name, 4, 2, orient="Qt::Vertical", size_type="QSizePolicy::Expanding")), it(label("chCellName_%s" % name, label_text, "chCellName", "Qt::AlignCenter")), it(label("chCellValue_%s" % name, value, "chCellValue", "Qt::AlignCenter")), it(spacer("chCellPadBot_%s" % name, 4, 2, orient="Qt::Vertical", size_type="QSizePolicy::Expanding")), ], spacing=0, margins=(2, 2, 2, 2)) # 高度 42~64 弹性:卡片高时四行一起撑开,不会在表头下面留一条空白 p = (penum("frameShape", "QFrame::NoFrame") + role("chCell") + pstr("state", ui_state, stdset=True) + psize("minimumSize", 0, 42) + psize("maximumSize", MAXW, 64) + pspol("Expanding", "Expanding")) return widget("QFrame", "chCell_%s" % name, p, body) def tab_page(name, hint): return widget("QWidget", name, "", layout("QVBoxLayout", name + "Layout", [ it(spacer(name + "PadTop", 10, 2, orient="Qt::Vertical", size_type="QSizePolicy::Expanding")), it(label(name + "Hint", hint, "placeholder", "Qt::AlignCenter")), it(spacer(name + "PadBot", 10, 2, orient="Qt::Vertical", size_type="QSizePolicy::Expanding")), ], spacing=0)) def build_curve_page(): """温控曲线页:QCustomPlot(.ui 里 declare 为 promoted widget,见 build() 的 customwidgets 段) 坐标轴范围 / 曲线样式都在 detailview.cpp 的 setupCurvePlot() 里设,.ui 只放控件""" plot = widget("QCustomPlot", "curvePlot", role("curvePlot") + pspol("Expanding", "Expanding")) return widget("QWidget", "tabPageCurve", "", layout("QVBoxLayout", "tabPageCurveLayout", [it(plot)], spacing=0, margins=(6, 8, 8, 8))) def build_ch_card(): # 图例已按需求移除:详情页只区分已装载(蓝)与 IDLE(灰) head = layout("QHBoxLayout", "detailChHead", [ it(panel_title("detailChTitle", "24 通道内存测试状态")), it(spacer("detailChSpacer", 16, 10, size_type="QSizePolicy::Expanding")), ], spacing=12, margins=(0, 0, 0, 0)) cells = [] for r, row in enumerate(DETAIL_CH): for c, (nm, temp, st) in enumerate(row): cells.append(it(ch_cell(nm, nm, temp, st), r, c)) grid = layout("QGridLayout", "detailChGrid", cells, spacing=6, margins=(0, 0, 0, 0)) # 卡片高度封顶在 330:格子撑到 64 就停,避免出现"表头下面一大片空白" return widget("QFrame", "detailChCard", penum("frameShape", "QFrame::NoFrame") + role("card") + pspol("Expanding", "Expanding") + psize("maximumSize", MAXW, 330), layout("QVBoxLayout", "detailChCardLayout", [it(head), it(grid)], spacing=10, margins=(14, 12, 14, 14))) # -------------------------------------------------------------------------- # 详情页「内存参数设置」:三列参数表单(参数名 / 输入框 / 单位) # 数值由后端下发,界面只提供输入位;输入框默认 0 # -------------------------------------------------------------------------- PARAM_NAME_W = 86 # 参数名列宽(最长 "mem vddq") PARAM_EDIT_H = 24 # 输入框高 PARAM_EDIT_W = 160 # 输入框最大宽(再宽就只剩空白了,窗口变窄时自动缩) PARAM_GRID_ROWS = 6 # 三列统一 6 个行槽位(第三列最后一槽空着),行距才能对齐并一起弹性分配 PARAM_COLS = [ ["mem vdd", "mem vddq", "tCL", "tRCD", "tRP", "tRAS"], ["tRFC", "tRTP", "trrd_l", "tWTR_S", "tWTR_L", "tWR"], ["tCCD_L", "trefi", "tRFCsb"], ] PARAM_CHECKS = ["errhandle", "ap"] def param_name(name, text): return label(name, text, "paramName", "Qt::AlignLeft|Qt::AlignVCenter", size=(PARAM_NAME_W, PARAM_EDIT_H), maxsize=(PARAM_NAME_W, MAXW), policy=("Fixed", "Preferred")) def param_edit(col, row): return widget("QLineEdit", "paramEdit_%d_%d" % (col, row), pstr("text", "0") + role("paramEdit") + psize("minimumSize", 0, PARAM_EDIT_H) + psize("maximumSize", PARAM_EDIT_W, PARAM_EDIT_H) + pspol("Expanding", "Fixed")) def param_check(col, row): return widget("QCheckBox", "paramCheck_%d_%d" % (col, row), pstr("text", "") + role("paramCheck") + psize("minimumSize", 16, 16) + psize("maximumSize", 16, 16)) def param_row(col, row, text, is_check): """一行 = 参数名 + 输入框(或复选框);输入框横向伸展吃满该列(单位已按需求去掉)""" if is_check: return layout("QHBoxLayout", "paramRow_%d_%d" % (col, row), [ it(param_name("paramChkName_%d_%d" % (col, row), text)), it(param_check(col, row)), it(spacer("paramChkPad_%d_%d" % (col, row), 10, 1, size_type="QSizePolicy::Expanding")), ], spacing=8) # 行尾补一个弹性空隙:输入框封顶 160px 后,列里剩下的宽度必须有东西去吃掉, # 否则窗口拉宽时 Qt 会把富余量塞到「参数名」和「输入框」中间(第三列就是这么被撑歪的) return layout("QHBoxLayout", "paramRow_%d_%d" % (col, row), [ it(param_name("paramName_%d_%d" % (col, row), text)), it(param_edit(col, row)), it(spacer("paramPad_%d_%d" % (col, row), 8, 1, size_type="QSizePolicy::Expanding")), ], spacing=8) def build_param_page(): # 三列各自一个 QVBoxLayout,行槽位固定 6 个、行间是 Expanding spacer, # 这样行距会随页面高度均分(把下方空白吃掉),三列又因为槽位相同而严格对齐。 # 注意:不用 QGridLayout + rowStretch —— 网格的行最大高度被输入框的 maximumHeight(24) 卡死,行长不高。 blocks = [] for c, rows in enumerate(PARAM_COLS): entries = [(nm, False) for nm in rows] if c == len(PARAM_COLS) - 1: # 第三列尾部是两个开关,没有输入框 entries += [(nm, True) for nm in PARAM_CHECKS] items = [] for r in range(PARAM_GRID_ROWS): if r: items.append(it(spacer("paramVGap_%d_%d" % (c, r), 6, 2, orient="Qt::Vertical", size_type="QSizePolicy::Expanding"))) if r < len(entries): nm, is_chk = entries[r] items.append(it(param_row(c, r, nm, is_chk))) else: # 空槽位:给一个和输入框等高的占位,保持列高一致 items.append(it(spacer("paramVPad_%d_%d" % (c, r), 6, PARAM_EDIT_H, orient="Qt::Vertical"))) blocks.append(it(layout("QVBoxLayout", "paramCol_%d" % c, items, spacing=0, margins=(0, 0, 0, 0)))) if c != len(PARAM_COLS) - 1: # 列间分隔线 blocks.append(it(widget("QFrame", "paramSep_%d" % c, penum("frameShape", "QFrame::NoFrame") + role("paramSep") + psize("minimumSize", 1, 0) + psize("maximumSize", 1, MAXW)))) form = layout("QHBoxLayout", "paramForm", blocks, spacing=14, margins=(0, 0, 0, 0)) # 「确定」按钮:跟表单右边界对齐,功能暂未接(先占位,后续接下发) submit_row = layout("QHBoxLayout", "paramSubmitRow", [ it(spacer("paramSubmitSpacer", 10, 10, size_type="QSizePolicy::Expanding")), it(widget("QPushButton", "btnParamSubmit", pstr("text", "确定") + role("paramSubmit") + psize("minimumSize", 88, 30) + psize("maximumSize", 88, 30))), ], spacing=0, margins=(0, 0, 0, 0)) # 表单吃满整页高度(C++ 里给 form 设 stretch=1),底部贴「确定」按钮 return widget("QWidget", "tabPageParam", "", layout("QVBoxLayout", "tabPageParamLayout", [ it(form), it(spacer("paramGapSubmit", 10, 16, orient="Qt::Vertical")), it(submit_row), ], spacing=0, margins=(6, 10, 6, 10))) def build_tabs_card(): # 只保留「温控曲线 / 异常记录」两页;测试数据集、测试项目进度已按需求移除 tabs = [("温控曲线", True), ("异常记录", False), ("内存参数设置", False)] btns = [] for i, (txt, active) in enumerate(tabs): p = (pstr("text", txt) + role("detailTab") + pstr("active", "true" if active else "false", stdset=True) + psize("minimumSize", 100, 26) + psize("maximumSize", MAXW, 26)) btns.append(it(widget("QPushButton", "detailTab_%d" % i, p))) tab_bar = layout("QHBoxLayout", "detailTabBar", btns + [ it(spacer("detailTabSpacer", 10, 10, size_type="QSizePolicy::Expanding"))], spacing=6, margins=(14, 10, 14, 6)) pages = [build_curve_page(), tab_page("tabPageAlarm", "暂无异常记录"), build_param_page()] tab_stack = stack("detailTabStack", pages) return widget("QFrame", "detailTabsCard", penum("frameShape", "QFrame::NoFrame") + role("card") + pspol("Expanding", "Expanding"), layout("QVBoxLayout", "detailTabsCardLayout", [it(tab_bar), it(tab_stack)], spacing=0, margins=(0, 0, 0, 0))) DETAIL_LOG_LINES = [ "[10:12:00] 工位 SLT-HT-001 载入任务 TASK-20261021-001(DDR5 RDIMM)", "[10:12:04] 腔体升温至 68.4 °C,温控进入恒温模式", "[10:13:26] CPU0 · 12CH / CPU1 · 12CH 通道训练完成", "[10:28:12] 通道 CPU0_CHJ 读取延迟超阈值,已标记 FAIL", "[10:29:40] 测试进度 87.5%,预计剩余 5 分 20 秒", ] def build_log_card(): head = layout("QHBoxLayout", "logHead", [ it(panel_title("logTitle", "测试日志")), it(spacer("logHeadSpacer", 10, 10, size_type="QSizePolicy::Expanding")), ], spacing=8, margins=(0, 0, 0, 0)) # 日志内容由 detailview.cpp 运行时写入:.ui 里的多行字符串会被 uic 按缩进重排, # 每行前面会多出一串空格(换行后自动缩进),所以这里只留空控件 # 日志内容由后端实时推送;空的时候不显示任何提示文字 log = widget("QPlainTextEdit", "detailLog", pbool("readOnly", True) + role("log") + penum("lineWrapMode", "QPlainTextEdit::NoWrap")) return widget("QFrame", "detailLogCard", penum("frameShape", "QFrame::NoFrame") + role("card") + pspol("Expanding", "Expanding"), layout("QVBoxLayout", "detailLogCardLayout", [it(head), it(log)], spacing=8, margins=(14, 12, 14, 12))) def build_detail(): back = widget("QPushButton", "btnBackMonitor", pstr("text", "← 返回多机监控") + role("detailBack") + psize("minimumSize", 112, 28) + psize("maximumSize", 112, 28)) title_bar = widget("QFrame", "detailTitleBar", penum("frameShape", "QFrame::NoFrame") + role("card") + pfixh(46), layout("QHBoxLayout", "detailTitleBarLayout", [ it(label("detailTitle", "设备详情页", "detailTitle", "Qt::AlignLeft|Qt::AlignVCenter")), # 分隔符与工位号拆成两个静态控件:.cpp 只填 detailDevice 的内容 it(label("detailTitleDot", "·", "detailTitleDot", "Qt::AlignCenter")), it(label("detailDevice", "—", "detailDevice", "Qt::AlignLeft|Qt::AlignVCenter")), it(spacer("detailTitleSpacer", 10, 10, size_type="QSizePolicy::Expanding")), it(back), ], spacing=8, margins=(14, 0, 14, 0))) left = layout("QVBoxLayout", "detailLeftCol", [it(build_ch_card()), it(build_tabs_card())], spacing=10, margins=(0, 0, 0, 0)) right = layout("QVBoxLayout", "detailRightCol", [it(build_log_card())], spacing=10, margins=(0, 0, 0, 0)) cols = layout("QHBoxLayout", "detailCols", [it(left), it(right)], spacing=10, margins=(0, 0, 0, 0)) # KPI 条已按需求移除:标题栏下面直接是左右两栏 body = layout("QVBoxLayout", "detailBody", [it(title_bar), it(cols)], spacing=10, margins=(20, 8, 20, 14)) return widget("QWidget", "detailPage", role("contentArea"), body) # -------------------------------------------------------------------------- def build(): # pageStack: 0 = 多机监控总览,1 = 设备详情页(工位卡「查看详情 >」切换) pages = stack("pageStack", [build_content(), build_detail()]) root = layout("QVBoxLayout", "rootLayout", [ it(build_header()), it(pages), ], spacing=0) central = widget("QWidget", "centralwidget", "", root) ui = '\n\n' ui += " MainWindow\n" ui += ' \n' ui += textwrap.indent( prect("geometry", 0, 0, 1640, 720) + psize("minimumSize", 1320, 800) + pstr("windowTitle", "HOVSE SLT Pro"), " ") ui += textwrap.indent(central, " ") ui += " \n" # 提升控件:QCustomPlot 作为普通 QWidget 放进 .ui,由 uic 生成 #include "qcustomplot.h" ui += (" \n" " \n" " QCustomPlot\n" " QWidget\n" "
qcustomplot.h
\n" " 0\n" "
\n" " \n" " PowerButton\n" " QWidget\n" "
powerbutton.h
\n" " 0\n" "
\n" "
\n") ui += " \n \n
\n" return ui if __name__ == "__main__": os.makedirs(os.path.dirname(OUT), exist_ok=True) data = build() with open(OUT, "w", encoding="utf-8", newline="\n") as f: f.write(data) print("written: %s (%d bytes)" % (OUT, len(data)))