124 lines
4.8 KiB
Python
124 lines
4.8 KiB
Python
# -*- coding: utf-8 -*-
|
||
"""v1.0.51 回归:左列「实时画面」预览加高
|
||
|
||
现场反馈:「把画面预览拉高一些,限制太挤了」。
|
||
原来 1440×900 下预览框只有 540×183,而相机是 1280×720(16:9)——
|
||
预览按 cover 缩放(max(lw/w, lh/h)),183 只装得下整幅画面的 61%,
|
||
等于上下各裁掉近 1/5,货放在秤上只能看见中间一条。
|
||
|
||
本文件锁死这几件事:
|
||
A. 1440×900 下预览框高度 ≥ 宽度的 9/16(整幅画面看得全,不再纵向裁切)
|
||
B. 相比 v1.0.50 的 183 至少长 100px
|
||
C. 状态卡压到 116 后,塞进一条超长「最近:…」也不会被裁(单行 + 省略号)
|
||
D. 左列各块加起来正好等于左列高度(没有重叠、没有挤成 1px 的块)
|
||
E. 1280×800 / 1024×700 小屏同样成立(等比缩放不塌)
|
||
"""
|
||
import os
|
||
import sys
|
||
import json
|
||
import tkinter as tk
|
||
|
||
HERE = os.path.dirname(os.path.abspath(__file__))
|
||
ROOT = os.path.dirname(HERE)
|
||
sys.path.insert(0, ROOT)
|
||
os.chdir(ROOT)
|
||
|
||
from ui import app as A # noqa: E402
|
||
|
||
A.App._poll = lambda self: None
|
||
A.App._poll_preview = lambda self: None
|
||
|
||
ok = fail = 0
|
||
|
||
|
||
def check(name, cond, extra=''):
|
||
global ok, fail
|
||
if cond:
|
||
ok += 1
|
||
print(' ✔ %s' % name)
|
||
else:
|
||
fail += 1
|
||
print(' ✘ %s %s' % (name, extra))
|
||
|
||
|
||
BASE = json.load(open('config.json', encoding='utf-8'))
|
||
BASE.setdefault('ui', {})
|
||
BASE['ui']['mode'] = 'window' # 不上全屏,按给定尺寸出图
|
||
BASE['ui']['fit_screen'] = False
|
||
BASE['ui']['borderless'] = False
|
||
BASE['ui']['todo_thumb'] = False
|
||
|
||
|
||
def build(w, h):
|
||
cfg = json.loads(json.dumps(BASE))
|
||
cfg['ui']['width'] = w
|
||
cfg['ui']['height'] = h
|
||
A.load_config = lambda path='config.json', _c=cfg: _c
|
||
root = tk.Tk()
|
||
app = A.App(root)
|
||
root.geometry('%dx%d+0+0' % (w, h))
|
||
for c in root.winfo_children():
|
||
c.destroy()
|
||
app._build()
|
||
root.update_idletasks()
|
||
root.update()
|
||
return root, app
|
||
|
||
|
||
def layout(w, h):
|
||
"""返回 (预览宽, 预览高, 左列高, 各块高度列表, 状态卡超高量)"""
|
||
root, app = build(w, h)
|
||
# 压测:状态卡最后一行给一条超长文案
|
||
long_txt = ('最近:识别 旱黄瓜 15.89kg → 已提交 #88231 客户「南充市高坪区'
|
||
'红运水果蔬菜批发部」规格 20 斤/箱 单价 3.2 元 剩余 12 箱')
|
||
app.lbl_last.configure(
|
||
text=app._fit_text(long_txt, app._px(536)))
|
||
root.update_idletasks()
|
||
root.update()
|
||
left = app.preview_lbl.master.master.master.master # lbl→box→body→cam→left
|
||
left_h = left.winfo_height()
|
||
blocks = [c.winfo_height() for c in left.winfo_children()]
|
||
sc = app.lbl_last.master.master # body → 状态卡
|
||
need = (app.lbl_last.winfo_y() + app.lbl_last.winfo_height()
|
||
+ app._px(6)) # 内容底 + 下内边距
|
||
res = (app.preview_lbl.winfo_width(), app.preview_lbl.winfo_height(),
|
||
left_h, blocks, need - sc.winfo_height(),
|
||
app.lbl_last.cget('text'), app.lbl_last.cget('wraplength'),
|
||
sc.winfo_height())
|
||
root.destroy()
|
||
return res
|
||
|
||
|
||
print('A. 1440×900:预览要装得下 16:9 整幅')
|
||
pw, ph, lh, blocks, over, txt, wrap, sc_h = layout(1440, 900)
|
||
print(' 预览 %dx%d / 左列 %d / 各块 %s' % (pw, ph, lh, blocks))
|
||
check('预览高度 ≥ 宽度×9/16(整幅可见)', ph >= pw * 9.0 / 16.0,
|
||
'需要 ≥ %.0f,实际 %d' % (pw * 9.0 / 16.0, ph))
|
||
check('比 v1.0.50 的 183px 至少长 100px', ph >= 283, '实际 %d' % ph)
|
||
check('预览宽度没被压窄(≥530)', pw >= 530, '实际 %d' % pw)
|
||
|
||
print('B. 状态卡压到 116 后仍装得下超长「最近:…」')
|
||
check('内容不超出卡片', over <= 0, '超出 %d px' % over)
|
||
check('最后一行是单行(wraplength=0)', int(wrap) == 0, 'wraplength=%s' % wrap)
|
||
check('超长文案被截断补省略号', txt.endswith('…'), txt[-12:])
|
||
check('状态卡高度就是 116(设计值)', sc_h == 116, '实际 %d' % sc_h)
|
||
|
||
print('C. 左列没有块被挤成 0 / 重叠')
|
||
check('所有块高度 > 0', all(b > 0 for b in blocks), str(blocks))
|
||
check('各块+间距刚好铺满左列',
|
||
abs(sum(blocks) + 6 * 3 - lh) <= 6,
|
||
'块合计 %d + 间距 18 vs 左列 %d' % (sum(blocks), lh))
|
||
check('重量卡 ≤ 230(56 号字已降到 46)', blocks[3] <= 230,
|
||
'实际 %d' % blocks[3])
|
||
|
||
print('D. 小屏等比缩放不塌')
|
||
for (w, h) in ((1280, 800), (1024, 700)):
|
||
pw, ph, lh, blocks, over, txt, wrap, sc_h = layout(w, h)
|
||
print(' %dx%d 预览 %dx%d 各块 %s' % (w, h, pw, ph, blocks))
|
||
check('%dx%d 预览仍近 16:9(允许 3%% 误差)' % (w, h),
|
||
ph >= pw * 9.0 / 16.0 * 0.97, '比例 %.2f' % (ph / float(pw)))
|
||
check('%dx%d 没有 0 高度块' % (w, h), all(b > 0 for b in blocks), str(blocks))
|
||
|
||
print('\n结果:%d 通过 / %d 失败' % (ok, fail))
|
||
sys.exit(1 if fail else 0)
|