feat(label): 标签改左右布局,修卡片高亮抖动

待办卡外框统一固定 4px,选中/确认只换颜色,不再把整行撑高;
引擎接管确认行时清掉手动选中,避免两张同时亮。版本升到 1.0.69。
This commit is contained in:
雨天
2026-11-23 10:45:15 +08:00
parent a74edd316e
commit 22c1750c9b
8 changed files with 287 additions and 25 deletions
+3 -3
View File
@@ -1,16 +1,16 @@
VSVersionInfo(
ffi=FixedFileInfo(filevers=(1, 0, 67, 0), prodvers=(1, 0, 67, 0),
ffi=FixedFileInfo(filevers=(1, 0, 69, 0), prodvers=(1, 0, 69, 0),
mask=0x3f, flags=0x0, OS=0x40004, fileType=0x1,
subtype=0x0, date=(0, 0)),
kids=[
StringFileInfo([StringTable('080404B0', [
StringStruct('CompanyName', '配送中心'),
StringStruct('FileDescription', '入库分拣工作站'),
StringStruct('FileVersion', '1.0.68.0'),
StringStruct('FileVersion', '1.0.69.0'),
StringStruct('InternalName', 'WeighStation'),
StringStruct('OriginalFilename', '入库分拣工作站.exe'),
StringStruct('ProductName', '入库分拣工作站'),
StringStruct('ProductVersion', '1.0.68.0'),
StringStruct('ProductVersion', '1.0.69.0'),
StringStruct('LegalCopyright', '内部使用')])]),
VarFileInfo([VarStruct('Translation', [2052, 1200])])
]
+1 -1
View File
@@ -20,7 +20,7 @@ import sys
ROOT = os.path.dirname(os.path.abspath(__file__))
APP_NAME = '入库分拣工作站'
APP_VERSION = '1.0.68'
APP_VERSION = '1.0.69'
ASSETS = os.path.join(ROOT, 'assets')
DIST = os.path.join(ROOT, 'dist')
OUT = os.path.join(DIST, APP_NAME)
+6 -1
View File
@@ -305,7 +305,12 @@ def plan_label(cfg, title, fields, qr_data=''):
# 最后一行只占一个字号的高度,不占整行行距,垂直居中才不会显得偏上
block_h = (len(rows) - 1) * font * _LINE_RATIO + font
y = my + max(0, int((avail_h - block_h) // 2))
if qr:
# 有二维码时文字贴顶:和右上角的码同一条水平线,读起来是“左右布局”。
# 以前一律垂直居中,码在上、字块在中,看着像上下两段(现场反馈)。
y = my
else:
y = my + max(0, int((avail_h - block_h) // 2))
lines = []
for t in rows:
lines.append({'text': t, 'font': font, 'x': mx, 'y': int(y),
+3 -3
View File
@@ -1,12 +1,12 @@
; ============================================================
; 入库分拣工作站 · 安装包脚本(Inno Setup 6)
; 编译:iscc installer.iss → dist\入库分拣工作站_安装程序_v1.0.68.exe
; 编译:iscc installer.iss → dist\入库分拣工作站_安装程序_v1.0.69.exe
; 说明:源目录为 build_exe.py 产出的 dist\入库分拣工作站(onedir)
; ============================================================
#define AppName "入库分拣工作站"
#ifndef AppVersion
#define AppVersion "1.0.68"
#define AppVersion "1.0.69"
#endif
#define AppExe "入库分拣工作站.exe"
#define SrcDir "dist\入库分拣工作站"
@@ -41,7 +41,7 @@ CloseApplications=yes
RestartApplications=no
AllowNoIcons=yes
ShowLanguageDialog=no
VersionInfoVersion=1.0.68.0
VersionInfoVersion=1.0.69.0
VersionInfoDescription={#AppName} 安装程序
VersionInfoProductName={#AppName}
+139
View File
@@ -0,0 +1,139 @@
# -*- coding: utf-8 -*-
"""标签版面不变量回归(v1.0.69)
背景:v1.0.68 起「有二维码时文字块贴顶」(左右布局)。改的只是起始 y,
但必须证明:**任何纸型 / 任何字段长度下,文字都不会越出纸边、不会丢内容、
不会压到二维码**——现场以前从没出现过「打一半」「少一行」。
检查项(对每组纸型 × 字段组合):
① 每一行都在纸内:x≥左留白、x+w≤右边界
② 有二维码时文字不压码(x+w ≤ 码左沿-4)
③ 垂直不越界:首行 y≥上留白、末行 y+字号≤纸高-下留白
④ 内容完整:所有行文字拼起来 == 原始输入(除非明确提示“已截断”)
⑤ 二维码整块在纸内
⑥ 贴顶规则:有码时首行 y==上留白;无码时垂直居中
不需要打印机/网络。
"""
import sys
import io
import os
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from core.printing import label as L
ok = fail = 0
def check(name, cond, extra=''):
global ok, fail
if cond:
ok += 1
else:
fail += 1
print(' ✘ %s %s' % (name, extra))
SIZES = [(50, 50), (60, 40), (40, 60), (35, 25), (70, 50), (80, 30)]
FIELDS = {
'分拣-短': ('分拣标签', ['客户: 王记饭店', '品名: 红富士苹果',
'重量: 5.62 斤', '日期: 11-22 18:30']),
'分拣-长': ('分拣标签', ['客户: 张三水果批发市场配送中心',
'品名: 农夫山泉饮用天然水 550ml×24 整箱',
'重量: 1234.56 斤', '日期: 2026-11-22 18:30']),
'入库-6行': ('验收标签', ['订单: ORD_WEB_20261122_BR003_0017',
'品名: 精瘦肉', '数量: 15.00 斤',
'供应商: 演示供应商名称比较长', '时间: 2026-11-22 18:30']),
'空值': ('分拣标签', ['客户: ', '品名: ', '重量: 0.00 斤', '日期: ']),
}
QRS = {'短码': 'CT2026112200001',
'长码': 'CT-WEB-20261122-BR003-000123456789',
'无码': ''}
def fail_reasons(p, cfg, qr):
g = p['geom']
w, h, dpm = g['w'], g['h'], g['dots_per_mm']
mx = max(int(round(2 * dpm)), 8)
my = max(int(round(1.5 * dpm)), 6)
q = p['qr']
out = []
for ln in p['lines']:
if ln['x'] < mx - 1:
out.append('行越左边界 x=%d' % ln['x'])
if ln['x'] + ln['w'] > w:
out.append('行越右纸边 x+w=%d > %d' % (ln['x'] + ln['w'], w))
if q and ln['x'] + ln['w'] > q['x'] - 4:
out.append('行压到二维码 x+w=%d, 码左沿=%d'
% (ln['x'] + ln['w'], q['x']))
if p['lines']:
y0 = p['lines'][0]['y']
yl = p['lines'][-1]['y'] + p['font']
if y0 < my - 1:
out.append('首行越上边界 y=%d' % y0)
if yl > h - my + 2:
out.append('末行越下边界 y+字=%d > %d' % (yl, h - my))
if q and y0 != my:
out.append('有码却未贴顶 y0=%d my=%d' % (y0, my))
if q:
if q['x'] + q['size'] > w - mx + 1:
out.append('二维码越右边界')
if q['y'] + q['size'] > h - my + 1:
out.append('二维码越下边界')
return out
def content_ok(p, title, fields):
src = L._safe_text(title or '') + ''.join(
L._safe_text(f or '') for f in fields)
got = ''.join(ln['text'] for ln in p['lines'])
truncated = any('截断' in str(x) for x in (p.get('warnings') or []))
return (got == src) or truncated, src, got
for (wmm, hmm) in SIZES:
for fname, (title, fields) in FIELDS.items():
for qname, qr in QRS.items():
cfg = {'width_mm': wmm, 'height_mm': hmm, 'dpi': 203,
'gap_mm': 2}
p = L.plan_label(cfg, title, fields, qr_data=qr)
tag = '%gx%g/%s/%s' % (wmm, hmm, fname, qname)
bad = fail_reasons(p, cfg, qr)
check('%s 版面' % tag, not bad, '; '.join(bad))
good, src, got = content_ok(p, title, fields)
check('%s 内容完整' % tag, good,
'源=%r 得=%r' % (src, got))
print('版面不变量:%d 通过,%d 失败' % (ok, fail))
# ---- 再验一遍真正的 TSPL 字节:坐标在纸内、文字一个字不少 ----
print('=== 实际 TSPL 指令校验 ===')
for (wmm, hmm) in ((50, 50), (60, 40)):
cfg = {'width_mm': wmm, 'height_mm': hmm, 'dpi': 203, 'gap_mm': 2}
data = L.build_picking_label_tspl(
cfg, '张三水果批发市场', '农夫山泉 550ml×24', 15.0, '斤',
'2026-11-22 18:30', 'CT-WEB-20261122-BR003-000123456789')
s = data.decode('gbk', errors='replace')
tag = 'TSPL %gx%g' % (wmm, hmm)
for need in ('张三水果批发市场', '农夫山泉 550ml×24', '15.00',
'2026-11-22 18:30', 'CT-WEB-20261122-BR003-000123456789'):
check('%s 含 %s' % (tag, need[:10]), need in s,
'内容丢了')
# TEXT x,y,"font",0,1,1,"..." → 坐标都在纸内
import re
for m in re.finditer(r'TEXT (\d+),(\d+),"TSS(\d+)', s):
x, y, f = int(m.group(1)), int(m.group(2)), int(m.group(3))
check('%s TEXT 坐标' % tag,
x >= 0 and y >= 0 and x < wmm * 8 and y + f <= hmm * 8,
'x=%d y=%d f=%d' % (x, y, f))
for m in re.finditer(r'QRCODE (\d+),(\d+),H,(\d+)', s):
x, y, cell = int(m.group(1)), int(m.group(2)), int(m.group(3))
mods = L._qr_modules(len('CT-WEB-20261122-BR003-000123456789'.encode('gbk')))
check('%s QR 坐标' % tag,
x + mods * cell <= wmm * 8 and y + mods * cell <= hmm * 8,
'x=%d y=%d size=%d' % (x, y, mods * cell))
print('总计:%d 通过,%d 失败' % (ok, fail))
sys.exit(1 if fail else 0)
+77
View File
@@ -428,6 +428,83 @@ app.engine.station = 'picking'
app._paint_station()
check('窗口标题跟着变', app.root.title() == '分拣工作站', app.root.title())
print('=== 19. 卡片高亮:不抖 + 不同时亮两张 ===')
# 把登录页换掉,真正建一次作业界面。
# 必须 deiconify:窗口 withdraw 时 canvas 宽只有 1px,_layout_cards 直接
# return,卡片根本没摆上,下面那些「几何没变」的断言会空过(踩过)。
for _w in list(root.winfo_children()):
_w.destroy()
# 第 17 组把 _layout_cards 换成了空函数(测翻页时不想重排),这里恢复真方法
try:
del app._layout_cards
except AttributeError:
pass
app.engine.station = 'picking'
app.engine.logged_in = True
app.ready = True
root.deiconify()
try:
root.geometry('1400x820+20+20')
except Exception:
pass
root.update()
app._build()
root.update()
frows = [{'id': 'c%d' % i, 'item_name': n, 'unit': '个', 'remaining_qty': 2,
'customer_name': '富顺分公司', 'order_code': 'O%d' % i}
for i, n in enumerate(['虾皮', '绿豆', '盐', '花椒'])]
app.engine.rows = [dict(r) for r in frows]
app._fill_todo(frows)
root.update()
gridded = [c for c in app.todo_cards.values() if c.winfo_manager() == 'grid']
check('卡片真的摆上了(不是空跑)', len(gridded) >= 2, str(len(gridded)))
check('画布有真实宽度', app.todo_canvas.winfo_width() > 400,
str(app.todo_canvas.winfo_width()))
check('所有卡边框厚度统一',
{c.cget('highlightthickness') for c in app.todo_cards.values()}
== {A.CARD_HL},
str({c.cget('highlightthickness') for c in app.todo_cards.values()}))
check('高亮样式是纯颜色', isinstance(app._card_style('c1'), str),
str(type(app._card_style('c1'))))
def _positions():
return {r: (c.winfo_x(), c.winfo_y(), c.winfo_width(),
c.winfo_height(), c.grid_info().get('row'),
c.grid_info().get('column'))
for r, c in app.todo_cards.items()}
# 点一张 → 只有它亮,位置/尺寸不动
p_before = _positions()
app._sel_rid = 'c1'
app._repaint_cards(['c1'])
root.update()
p_after = _positions()
check('选中不改变卡片几何', p_before == p_after,
str({k: (p_before[k], p_after[k]) for k in p_after
if p_before[k] != p_after[k]}))
check('选中不改边框粗细',
{c.cget('highlightthickness') for c in app.todo_cards.values()}
== {A.CARD_HL},
str({c.cget('highlightthickness') for c in app.todo_cards.values()}))
# 引擎接管确认行 → 旧的琥珀选中被清掉,只剩一张绿的
p2 = _positions()
app._on_focus({'row_id': 'c3', 'mode': 'weigh'})
root.update()
lit = {r: c for r, c in app._paint_cache.items() if c != A.C.line}
check('确认时只剩一张高亮', len(lit) == 1 and 'c3' in lit, str(lit))
check('旧的手动选中已清', app._sel_rid is None, str(app._sel_rid))
p3 = _positions()
check('确认行高亮不引起抖动', p2 == p3,
str({k: (p2[k], p3[k]) for k in p3 if p2[k] != p3[k]}))
check('确认行高亮不改边框粗细',
{c.cget('highlightthickness') for c in app.todo_cards.values()}
== {A.CARD_HL},
str({c.cget('highlightthickness') for c in app.todo_cards.values()}))
root.destroy()
print('\n结果:%d 项通过,%d 项失败' % (ok, fail))
sys.exit(1 if fail else 0)
+41 -16
View File
@@ -39,7 +39,12 @@ class _BoolVar:
self._sw.set(v)
APP_VERSION = '1.0.68'
APP_VERSION = '1.0.69'
# 待办卡外框粗细:所有卡统一这一个值,选中/确认只换颜色。
# Tk 的 highlight 环画在控件外侧,粗细一变控件尺寸就变,grid 会把整屏
# 卡片重排 —— 现场“点一下界面就抖”就是这么来的。
CARD_HL = 4
FONT_BIG = ('Microsoft YaHei', 14)
FONT_HUGE = ('Microsoft YaHei', 38, 'bold')
@@ -2866,6 +2871,13 @@ class App:
rid = f.get('row_id')
row = f.get('row') or {}
mode = f.get('mode') or 'weigh'
# 引擎接管高亮:清掉「手动点过的那行 / 空秤预选」的琥珀框。
# 不然确认行(绿)会和之前点过的那张(琥珀)同时亮,看着像选了两张。
old_hl = [getattr(self, '_sel_rid', None),
getattr(self, '_pre_rid', None)]
self._sel_rid = None
self._pre_rid = None
self._repaint_cards(old_hl)
self._show_focus_bar(True)
# v1.0.61:不再弹确认条 —— 结论压成状态卡下面那一行提示,
# 有警示语就整行变琥珀色且顶到最前面。
@@ -2929,19 +2941,23 @@ class App:
self._scroll_to(c)
def _card_style(self, rid):
"""这张卡此刻应有的高亮:(颜色, 边框宽)
"""这张卡此刻应有的边框颜色
优先级:确认态那一行(绿·粗)> 空秤预选 / 手动选中(琥珀)> 普通
优先级:确认态那一行(绿)> 空秤预选 / 手动选中(琥珀)> 普通
v1.0.69:只变颜色、**不变边框粗细**。以前确认行是 4px、其余 2px,
一张卡变粗就把它那一行撑高 4px,整列跟着重排 —— 现场就是
「一点卡片界面就抖」。现在所有卡片统一 CARD_HL 浅灰,选中/确认只换色。
"""
rid = str(rid)
fp = getattr(self, '_focus_p', None) or {}
if fp.get('row_id') is not None and str(fp.get('row_id')) == rid:
return (C.green, 4)
return C.green
if str(getattr(self, '_pre_rid', '') or '') == rid:
return (C.amber, 2)
return C.amber
if str(getattr(self, '_sel_rid', '') or '') == rid:
return (C.amber, 2)
return (C.line, 2)
return C.amber
return C.line
def _repaint_cards(self, rids):
"""只重画「高亮真的变了」的那几张卡(v1.0.56)
@@ -2949,6 +2965,9 @@ class App:
原来 _select_card / _paint_focus / _on_preselect 三处都遍历全部卡片
configure 一遍:120 行时一次点击 35ms(现场 i5 要 100ms+),日志里
那些「ev:focus 用时 438 ms」就是这么来的。改完一次点击最多碰 2 张。
v1.0.69:只改 highlightbackground(不碰粗细)—— 粗细一变几何就变,
grid 重排让整屏卡跟着跳。
"""
cache = getattr(self, '_paint_cache', None)
if cache is None:
@@ -2961,13 +2980,15 @@ class App:
c = cards.get(rid)
if c is None:
continue
style = self._card_style(rid)
if cache.get(rid) == style:
color = self._card_style(rid)
if cache.get(rid) == color:
continue # 没变,一个 configure 都不发
cache[rid] = style
cache[rid] = color
try:
c.configure(highlightbackground=style[0],
highlightthickness=style[1])
# 粗细也一并写回固定值:万一别处动过它,下一次重画就纠正,
# 几何始终不变(写在 configure 里,值相同 Tk 不会引起重排)。
c.configure(highlightbackground=color,
highlightthickness=CARD_HL)
except Exception:
pass
@@ -3391,7 +3412,7 @@ class App:
"""
px = self._px
c = tk.Frame(self.todo_grid, bg=C.surface, bd=0,
highlightthickness=2, highlightbackground=C.line,
highlightthickness=CARD_HL, highlightbackground=C.line,
highlightcolor=C.line)
c._thumb_label = None
name = r.get('item_name') or '—'
@@ -3928,15 +3949,19 @@ class App:
return
# v1.0.40:空秤(待机)点卡片 = 预选这一行 —— 放货识别后以 AI
# 命中为准,识别不出仍走人工确认页。高亮下面统一画。
old_pre = getattr(self, '_pre_rid', None)
if self.engine.state == 'IDLE':
try:
self.engine.preselect(rid)
# 预选高亮当场挪过去,别等引擎事件回来 —— 否则连点两张时
# 会有一帧「两张同时亮」(pending 事件要过一轮 _poll 才到)。
if self.engine.preselect(rid):
self._pre_rid = rid
except Exception:
pass
old = getattr(self, '_sel_rid', None)
self._sel_rid = rid
# 只重画变了的这两张(原来遍历整张名单 configure,120 行 35ms)
self._repaint_cards([old, rid])
# 只重画变了的这几张(原来遍历整张名单 configure,120 行 35ms)
self._repaint_cards([old, old_pre, rid])
r = self.todo_rows.get(rid) or {}
bits = [r.get('item_name') or '—']
if r.get('spec'):
+17 -1
View File
@@ -25,7 +25,23 @@
build_assets/ 打包素材(VC++ 运行库 vc_redist.x64.exe)
打包.bat 双击打包
dist/ 产物:dist\入库分拣工作站\(绿色版)
dist\入库分拣工作站_安装程序_v1.0.68.exe(安装包)
dist\入库分拣工作站_安装程序_v1.0.69.exe(安装包)
【v1.0.69 标签改左右布局 + 点卡不再抖(2026-11-23)】
◆ 标签改成左右布局(文字在左、二维码在右)
· 文字块改成贴顶排版,和右上角二维码在同一条水平线上;以前文字块
垂直居中,看着像“上面一块码、中间一块字”两段。
· 没有二维码的标签(调试预览)仍按原来的垂直居中,版面不变。
· 安装包出厂纸型改为 60×40mm(203dpi 下 480×320 点)。
· 老机器升级不会覆盖 config.json,纸型仍是原来的设置;需要时走
「设置 → 标签打印机 → 标签纸… → 自动读取尺寸」重新读一次。
◆ 点待办卡不再抖、也不会两张同时亮
· 所有卡片外框固定 4px,选中(琥珀)/ 确认(绿)只换颜色、不改粗细。
以前确认行比别的卡粗 2px,一点卡整排卡片就被撑大、界面跟着跳。
· 引擎接管确认行时会清掉手动点过 / 预选的琥珀框,只亮一张。
· 连点两张也不会出现一帧“两张同时亮”。
【v1.0.68 整组短收按部分成功处理(2026-11-22)】