feat(ui): 选中红框高亮、手写完成自动填入、布局精简与重拍未识别弹窗
This commit is contained in:
@@ -45,6 +45,9 @@ APP_VERSION = '1.0.72'
|
||||
# Tk 的 highlight 环画在控件外侧,粗细一变控件尺寸就变,grid 会把整屏
|
||||
# 卡片重排 —— 现场“点一下界面就抖”就是这么来的。
|
||||
CARD_HL = 4
|
||||
# AI 选中 / 待确认待办卡的红色高亮(分拣台与入库台共用)
|
||||
CARD_FOCUS_BORDER = '#dc2626'
|
||||
CARD_FOCUS_BG = '#fbe9e9'
|
||||
|
||||
|
||||
FONT_BIG = ('Microsoft YaHei', 14)
|
||||
@@ -1366,7 +1369,7 @@ class App:
|
||||
root.configure(bg=C.bg)
|
||||
|
||||
# ---- 顶栏 ----
|
||||
header = tk.Frame(root, bg=C.surface, height=px(72))
|
||||
header = tk.Frame(root, bg=C.surface, height=px(60))
|
||||
header.pack(fill='x')
|
||||
header.pack_propagate(False)
|
||||
tk.Frame(header, bg=C.line, height=1).pack(side='bottom', fill='x')
|
||||
@@ -1425,10 +1428,9 @@ class App:
|
||||
bg=C.surface, fg=C.ink2)
|
||||
self.lbl_clock.pack(side='right', padx=px(6))
|
||||
self._bind_drag(self.lbl_clock)
|
||||
# 右侧待办标题已显示总行数,顶栏不再重复展示「待办 N 行」
|
||||
self.lbl_pending = tk.Label(header, text='待办 0 行', font=font(12),
|
||||
bg=C.surface, fg=C.ink3)
|
||||
self.lbl_pending.pack(side='right', padx=px(8))
|
||||
self._bind_drag(self.lbl_pending)
|
||||
|
||||
main = tk.Frame(root, bg=C.bg)
|
||||
main.pack(fill='both', expand=True, padx=px(20), pady=(px(6), px(14)))
|
||||
@@ -1459,7 +1461,7 @@ class App:
|
||||
font=font(18, 'bold'), bg=C.surface,
|
||||
fg=C.ink, anchor='w')
|
||||
self.lbl_state.pack(side='left')
|
||||
self.lbl_print = tk.Label(r1, text='打印:—', font=font(11),
|
||||
self.lbl_print = tk.Label(r1, text='', font=font(11),
|
||||
bg=C.surface, fg=C.ink3, anchor='e')
|
||||
self.lbl_print.pack(side='right')
|
||||
self.lbl_hint = tk.Label(sc.body, text='放货 → 自动识别 → 取走',
|
||||
@@ -1552,9 +1554,10 @@ class App:
|
||||
font=font(16, 'bold'), surface=C.surface)
|
||||
self.btn_zero.pack(side='left', fill='x', expand=True,
|
||||
padx=(px(12), 0))
|
||||
self.lbl_scale = tk.Label(wc.body, text='秤:连接中…', font=font(11),
|
||||
bg=C.surface, fg=C.ink3, anchor='w')
|
||||
self.lbl_scale.pack(fill='x', pady=(px(4), 0))
|
||||
# 秤状态小字:正常称重时不占高度,仅在未连接/超载/过期等异常时显露
|
||||
self.lbl_scale = tk.Label(wc.body, text='', font=font(11),
|
||||
bg=C.surface, fg=C.red, anchor='w')
|
||||
self._scale_err_vis = False
|
||||
self.lbl_w_live = self.lbl_weight
|
||||
|
||||
# ④ 步骤条(贴重量卡上方)
|
||||
@@ -1594,30 +1597,16 @@ class App:
|
||||
box.bind('<MouseWheel>', self._zoom_wheel)
|
||||
|
||||
# ================= 右列:待办名单 =================
|
||||
hrow = tk.Frame(right, bg=C.bg)
|
||||
hrow.pack(fill='x')
|
||||
self.lbl_todo_title = tk.Label(hrow, text='待办名单(0 行)',
|
||||
font=font(17, 'bold'), bg=C.bg,
|
||||
fg=C.ink)
|
||||
self.lbl_todo_title.pack(side='left')
|
||||
self.btn_cols = TouchButton(hrow, text=self._cols_text(),
|
||||
command=self._cycle_cols, fill='#eaeff6',
|
||||
fg=C.ink2, height=px(42), width=px(92),
|
||||
radius=px(21), font=font(12),
|
||||
surface=C.bg)
|
||||
self.btn_cols.pack(side='left', padx=(px(10), 0))
|
||||
# 硬刷新:不光拉名单,卡住的流程(抓拍/识别/人工页)也一并作废回待机
|
||||
TouchButton(hrow, text='刷新待办', command=self._refresh_pending_now,
|
||||
fill=C.green, fg='white', height=px(42), width=px(110),
|
||||
radius=px(21), font=font(12, 'bold'),
|
||||
surface=C.bg).pack(side='right')
|
||||
self.lbl_todo_sum = tk.Label(hrow, text='', font=font(13, 'bold'),
|
||||
# 取消「待办名单 + 合计」标题行(多单位时易截断且占高度),保留隐藏引用兼容旧回调
|
||||
self.lbl_todo_title = tk.Label(right, text='', font=font(17, 'bold'),
|
||||
bg=C.bg, fg=C.ink)
|
||||
self.lbl_todo_sum = tk.Label(right, text='', font=font(13, 'bold'),
|
||||
bg=C.bg, fg=C.green)
|
||||
self.lbl_todo_sum.pack(side='right', padx=(0, px(14)))
|
||||
self.lbl_todo_detail = tk.Label(right, text='点一张卡看完整信息',
|
||||
font=font(12), bg=C.bg, fg=C.ink2,
|
||||
# 卡片详情/提示行:平时无选中或筛选时自动隐藏,避免占白位
|
||||
self.lbl_todo_detail = tk.Label(right, text='',
|
||||
font=font(11), bg=C.bg, fg=C.ink2,
|
||||
anchor='w', justify='left')
|
||||
self.lbl_todo_detail.pack(fill='x', pady=(px(2), px(8)))
|
||||
self._todo_detail_vis = False
|
||||
|
||||
# ---- 展示维度:不分组 / 按客户(下拉选一家)/ 按分类(下拉选一类) ----
|
||||
# 待办一动就是几十行,分组后「这一趟给谁拣」一眼能看出来。
|
||||
@@ -1633,7 +1622,7 @@ class App:
|
||||
self._group_mode = 'none'
|
||||
self._group_pick = None
|
||||
gbar = tk.Frame(right, bg=C.bg)
|
||||
gbar.pack(fill='x', pady=(0, px(8)))
|
||||
gbar.pack(fill='x', pady=(0, px(6)))
|
||||
self._group_bar = gbar
|
||||
seg = tk.Frame(gbar, bg=C.bg)
|
||||
seg.pack(side='top', fill='x')
|
||||
@@ -1643,23 +1632,34 @@ class App:
|
||||
('category', '按分类')):
|
||||
b = TouchButton(seg, text=txt,
|
||||
command=lambda k=key: self._set_group_mode(k),
|
||||
fill='#eaeff6', fg=C.ink2, height=px(40),
|
||||
width=px(82), radius=px(20), font=font(12),
|
||||
fill='#eaeff6', fg=C.ink2, height=px(38),
|
||||
width=px(82), radius=px(19), font=font(12),
|
||||
surface=C.bg)
|
||||
b.pack(side='left', padx=(0, px(6)))
|
||||
self._group_btns[key] = b
|
||||
# 下拉按钮:只在按客户/按分类时出现,「全部 N 行」= 不筛
|
||||
self._group_dd = TouchButton(seg, text='全部 ▾',
|
||||
command=self._toggle_group_dd,
|
||||
fill=C.surface, fg=C.ink, height=px(40),
|
||||
width=px(220), radius=px(20),
|
||||
fill=C.surface, fg=C.ink, height=px(38),
|
||||
width=px(210), radius=px(19),
|
||||
font=font(12), surface=C.bg,
|
||||
outline=C.line)
|
||||
# 硬刷新按钮与列数切换放到分组条右侧,给卡片留出更多空间
|
||||
TouchButton(seg, text='刷新待办', command=self._refresh_pending_now,
|
||||
fill=C.green, fg='white', height=px(38), width=px(102),
|
||||
radius=px(19), font=font(12, 'bold'),
|
||||
surface=C.bg).pack(side='right')
|
||||
self.btn_cols = TouchButton(seg, text=self._cols_text(),
|
||||
command=self._cycle_cols, fill='#eaeff6',
|
||||
fg=C.ink2, height=px(38), width=px(92),
|
||||
radius=px(19), font=font(12),
|
||||
surface=C.bg)
|
||||
self.btn_cols.pack(side='right', padx=(0, px(8)))
|
||||
self._paint_group_bar()
|
||||
|
||||
# 搜索框
|
||||
sb_card = Card(right, radius=px(25), pad=px(6), height=px(58))
|
||||
sb_card.pack(fill='x', pady=(0, px(12)))
|
||||
sb_card = Card(right, radius=px(24), pad=px(5), height=px(52))
|
||||
sb_card.pack(fill='x', pady=(0, px(8)))
|
||||
sb_card.pack_propagate(False)
|
||||
sbox = sb_card.body
|
||||
self.var_search = tk.StringVar()
|
||||
@@ -1676,7 +1676,9 @@ class App:
|
||||
self.ent_search._field_label = '搜索'
|
||||
for txt, cmd, bgc, fg, bw in (
|
||||
('×', self._clear_search, C.surface, C.ink3, 44),
|
||||
('键盘', lambda: self._show_osk('abc'), '#eef2f7', C.ink2, 62),
|
||||
('键盘', lambda: (self._search_focus_in(),
|
||||
self._show_osk('abc', self.ent_search)),
|
||||
'#eef2f7', C.ink2, 62),
|
||||
('语音', self._voice_input, '#eef2f7', C.ink2, 62),
|
||||
('手写', self._handwriting, '#eef2f7', C.ink2, 62)):
|
||||
TouchButton(sbox, text=txt, command=cmd, fill=bgc, fg=fg,
|
||||
@@ -1740,13 +1742,13 @@ class App:
|
||||
self._shown_ids = []
|
||||
self._build_gen = 0
|
||||
|
||||
# 底部结果条:提交结果 / 今日统计 / 当前模式,一眼能看到
|
||||
ft = Card(right, radius=px(14), pad=px(10), height=px(64))
|
||||
ft.pack(fill='x', pady=(px(10), 0))
|
||||
# 底部结果条:紧凑单行(模式已在顶栏标明,不重复占一行)
|
||||
ft = Card(right, radius=px(14), pad=px(8), height=px(48))
|
||||
ft.pack(fill='x', pady=(px(6), 0))
|
||||
ft.pack_propagate(False)
|
||||
self.ft_bar = ft
|
||||
f1 = tk.Frame(ft.body, bg=C.surface)
|
||||
f1.pack(fill='x')
|
||||
f1.pack(fill='both', expand=True)
|
||||
tk.Label(f1, text='本次结果', font=font(11), bg=C.surface,
|
||||
fg=C.ink3).pack(side='left', padx=(0, px(8)))
|
||||
self.lbl_result = tk.Label(f1, text='—', font=font(13, 'bold'),
|
||||
@@ -1759,12 +1761,11 @@ class App:
|
||||
# 「最近提交」:提交完不能改,但得让人随时翻出「刚才是怎么记的账」,
|
||||
# 对着照片和操作号去后台更正,而不是凭记忆吵。
|
||||
TouchButton(f1, text='最近提交', command=self._show_recent_records,
|
||||
fill='#eef2f7', fg=C.ink2, height=px(34), width=px(92),
|
||||
radius=px(17), font=font(11),
|
||||
fill='#eef2f7', fg=C.ink2, height=px(32), width=px(90),
|
||||
radius=px(16), font=font(11),
|
||||
surface=C.surface).pack(side='right', padx=(0, px(10)))
|
||||
self.lbl_mode = tk.Label(ft.body, text='', font=font(10),
|
||||
bg=C.surface, fg=C.ink3, anchor='w')
|
||||
self.lbl_mode.pack(fill='x')
|
||||
|
||||
# 识别确认:认出商品后跳到那张卡,人点左列「确认」才提交。
|
||||
# 用 pack(before=ft) 插在结果条上面,不用另开窗口 —— 现场最烦弹窗。
|
||||
@@ -2220,22 +2221,24 @@ class App:
|
||||
_set(self.lbl_w_tare, 't', text=tare_txt)
|
||||
_set(self.lbl_weight, 'wc',
|
||||
fg=C.brand if (st['connected'] and st['fresh']) else C.ink3)
|
||||
tips = []
|
||||
errs = []
|
||||
if not st['connected']:
|
||||
tips.append('未连接')
|
||||
errs.append('未连接')
|
||||
if not st['fresh']:
|
||||
tips.append('数据过期')
|
||||
errs.append('数据过期')
|
||||
if st['overload']:
|
||||
tips.append('超载')
|
||||
if not st['present']:
|
||||
tips.append('空秤')
|
||||
errs.append('超载')
|
||||
port = self.cfg.get('scale', {}).get('port', 'COM?')
|
||||
if self.cfg.get('scale', {}).get('simulate'):
|
||||
port = '模拟'
|
||||
_set(self.lbl_scale, 's',
|
||||
text='%s · %s' % (port, '·'.join(tips) if tips else '正常'))
|
||||
_set(self.lbl_scale, 'sc',
|
||||
fg='#a32d2d' if (tips and '未连接' in tips) else '#5f5e5a')
|
||||
if errs:
|
||||
err_txt = '%s · %s' % (port, '·'.join(errs))
|
||||
_set(self.lbl_scale, 's', text=err_txt)
|
||||
_set(self.lbl_w_tare, 't', text=err_txt)
|
||||
_set(self.lbl_w_tare, 'tc', fg=C.red)
|
||||
else:
|
||||
_set(self.lbl_scale, 's', text='%s · 正常' % port)
|
||||
_set(self.lbl_w_tare, 'tc', fg=C.ink3)
|
||||
|
||||
def _on_state(self, s):
|
||||
idx = STEP_STATE.get(s, -1)
|
||||
@@ -2368,6 +2371,10 @@ class App:
|
||||
self.ent_search.configure(fg='#333333')
|
||||
|
||||
def _search_focus_out(self, _e=None):
|
||||
osk = getattr(self, '_osk_win', None)
|
||||
if (osk is not None and getattr(osk, 'target', None) is self.ent_search
|
||||
and osk.is_visible()):
|
||||
return
|
||||
if not self.ent_search.get().strip():
|
||||
self._search_placeholder()
|
||||
|
||||
@@ -2456,10 +2463,8 @@ class App:
|
||||
|
||||
def _flash_search_tip(self, text, ms=6000):
|
||||
try:
|
||||
self.lbl_todo_detail.configure(text=text, fg='#185fa5')
|
||||
self.root.after(ms, lambda: self.lbl_todo_detail.configure(
|
||||
text='点一张卡看完整信息(规格/编码/客户/单号)',
|
||||
fg='#5f5e5a'))
|
||||
self._set_todo_detail(text, fg='#185fa5')
|
||||
self.root.after(ms, lambda: self._set_todo_detail(''))
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
@@ -2486,6 +2491,7 @@ class App:
|
||||
不再去调 Windows 触摸键盘(这台机器上它根本唤不出来)。
|
||||
"""
|
||||
try:
|
||||
self._search_focus_in()
|
||||
self.ent_search.focus_set()
|
||||
self.ent_search.icursor('end')
|
||||
self._last_input_w = self.ent_search
|
||||
@@ -2942,20 +2948,23 @@ class App:
|
||||
det = str((f or {}).get('detected') or '').strip()
|
||||
conf = (f or {}).get('conf')
|
||||
mode = (f or {}).get('mode') or 'weigh'
|
||||
name = self._std_name(row) if row else '(还没选商品)'
|
||||
if not row:
|
||||
if det:
|
||||
msg = 'AI 识别为「%s」但不在名单,没认出对应行,请点右边或重拍' % det[:14]
|
||||
else:
|
||||
msg = '没认出是哪一件,请点右边对应商品或重拍'
|
||||
return msg, f.get('warn') or ''
|
||||
name = self._std_name(row)
|
||||
bits = []
|
||||
if det and det != name:
|
||||
bits.append('AI 认为「%s」%s'
|
||||
% (det[:14], '' if conf is None
|
||||
else '(%d%%)' % int(conf)))
|
||||
elif conf is not None and row:
|
||||
elif conf is not None:
|
||||
bits.append('把握 %d%%' % int(conf))
|
||||
elif not row:
|
||||
bits.append('没认出是哪一件,点右边那一行')
|
||||
if row:
|
||||
order_name = str(row.get('item_name') or '').strip()
|
||||
if order_name and order_name != name:
|
||||
bits.append('下单名「%s」' % order_name[:16])
|
||||
order_name = str(row.get('item_name') or '').strip()
|
||||
if order_name and order_name != name:
|
||||
bits.append('下单名「%s」' % order_name[:16])
|
||||
if mode == 'count':
|
||||
q = float(f.get('business') or 0)
|
||||
if f.get('from_scale'):
|
||||
@@ -3026,6 +3035,100 @@ class App:
|
||||
# 跳过去 + 高亮(翻到那张卡所在的一页)
|
||||
self._reveal_row(rid)
|
||||
self._sync_big_confirm()
|
||||
# 点「作废重拍」后若仍未识别出商品,弹出自定义美观提示窗
|
||||
was_retry = bool(getattr(self, '_retry_pending', False))
|
||||
self._retry_pending = False
|
||||
if row:
|
||||
self._close_unrecognized_popup()
|
||||
elif was_retry:
|
||||
self._show_unrecognized_popup(f)
|
||||
|
||||
def _close_unrecognized_popup(self):
|
||||
pop = getattr(self, '_unrec_pop', None)
|
||||
self._unrec_pop = None
|
||||
if pop is not None:
|
||||
try:
|
||||
pop.destroy()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def _show_unrecognized_popup(self, f=None):
|
||||
"""作废重拍后仍未识别出来:自定义圆角轻模态提示窗(不用系统默认弹窗)。"""
|
||||
self._close_unrecognized_popup()
|
||||
px, font = self._px, self._font
|
||||
f = f or {}
|
||||
det = str(f.get('detected') or '').strip()
|
||||
|
||||
top = tk.Toplevel(self.root)
|
||||
self._unrec_pop = top
|
||||
top.overrideredirect(True)
|
||||
top.configure(bg='#cbd5e1')
|
||||
try:
|
||||
top.transient(self.root)
|
||||
top.attributes('-topmost', True)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
ww, hh = px(440), px(290)
|
||||
try:
|
||||
rx = self.root.winfo_rootx() + (self.root.winfo_width() - ww) // 2
|
||||
ry = self.root.winfo_rooty() + (self.root.winfo_height() - hh) // 2
|
||||
except Exception:
|
||||
rx = (top.winfo_screenwidth() - ww) // 2
|
||||
ry = (top.winfo_screenheight() - hh) // 2
|
||||
top.geometry('%dx%d+%d+%d' % (ww, hh, max(0, rx), max(0, ry)))
|
||||
|
||||
# 外框细描边 + 内部白底卡片
|
||||
shell = tk.Frame(top, bg='#ffffff', padx=px(24), pady=px(22))
|
||||
shell.pack(fill='both', expand=True, padx=2, pady=2)
|
||||
|
||||
# 顶部柔和红底圆形感叹号图标
|
||||
ic = tk.Canvas(shell, width=px(56), height=px(56), bg='#ffffff',
|
||||
highlightthickness=0, bd=0)
|
||||
ic.pack(pady=(0, px(10)))
|
||||
ic.create_oval(px(2), px(2), px(54), px(54),
|
||||
fill='#fde8e8', outline='#fecaca', width=2)
|
||||
ic.create_text(px(28), px(28), text='!', fill='#dc2626',
|
||||
font=font(26, 'bold'))
|
||||
|
||||
tk.Label(shell, text='未能识别出商品', font=font(19, 'bold'),
|
||||
bg='#ffffff', fg=C.ink).pack()
|
||||
|
||||
if det:
|
||||
desc = ('AI 识别为「%s」,但不在当前待办名单中。\n'
|
||||
'请调整货品位置后重拍,或直接在右侧手动点选。' % det[:16])
|
||||
else:
|
||||
desc = ('重拍后仍未识别出当前货品。\n'
|
||||
'请调整货品摆放或光线后重试,也可直接在右侧点选。')
|
||||
tk.Label(shell, text=desc, font=font(12), bg='#ffffff', fg=C.ink2,
|
||||
justify='center', wraplength=px(380)).pack(
|
||||
pady=(px(8), px(18)))
|
||||
|
||||
btns = tk.Frame(shell, bg='#ffffff')
|
||||
btns.pack(fill='x', side='bottom')
|
||||
|
||||
def _retry_again():
|
||||
self._close_unrecognized_popup()
|
||||
self._focus_retry()
|
||||
|
||||
TouchButton(btns, text='再次重拍', command=_retry_again,
|
||||
fill=C.brand_soft, fg=C.brand, height=px(46),
|
||||
radius=px(14), font=font(14, 'bold'),
|
||||
surface='#ffffff').pack(
|
||||
side='left', fill='x', expand=True, padx=(0, px(10)))
|
||||
TouchButton(btns, text='去手动选择',
|
||||
command=self._close_unrecognized_popup,
|
||||
fill='#dc2626', fg='white', height=px(46),
|
||||
radius=px(14), font=font(14, 'bold'),
|
||||
surface='#ffffff').pack(
|
||||
side='left', fill='x', expand=True)
|
||||
|
||||
top.bind('<Escape>', lambda _e: self._close_unrecognized_popup())
|
||||
try:
|
||||
top.lift()
|
||||
top.focus_force()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def _on_focus_clear(self, _p=None):
|
||||
self._focus_p = None
|
||||
@@ -3065,7 +3168,7 @@ class App:
|
||||
def _card_style(self, rid):
|
||||
"""这张卡此刻应有的边框颜色
|
||||
|
||||
优先级:确认态那一行(绿)> 最后点过的那张(琥珀)> 普通
|
||||
优先级:确认态那一行(红)> 最后点过的那张(琥珀)> 普通
|
||||
|
||||
v1.0.69:只变颜色、**不变边框粗细**。以前确认行是 4px、其余 2px,
|
||||
一张卡变粗就把它那一行撑高 4px,整列跟着重排 —— 现场就是
|
||||
@@ -3078,7 +3181,7 @@ class App:
|
||||
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
|
||||
return CARD_FOCUS_BORDER
|
||||
if str(getattr(self, '_sel_rid', '') or '') == rid:
|
||||
return C.amber
|
||||
return C.line
|
||||
@@ -3090,7 +3193,7 @@ class App:
|
||||
configure 一遍:120 行时一次点击 35ms(现场 i5 要 100ms+),日志里
|
||||
那些「ev:focus 用时 438 ms」就是这么来的。改完一次点击最多碰 2 张。
|
||||
|
||||
v1.0.69:只改 highlightbackground(不碰粗细)—— 粗细一变几何就变,
|
||||
v1.0.69:只改颜色(不碰粗细)—— 粗细一变几何就变,
|
||||
grid 重排让整屏卡跟着跳。
|
||||
"""
|
||||
cache = getattr(self, '_paint_cache', None)
|
||||
@@ -3108,11 +3211,24 @@ class App:
|
||||
if cache.get(rid) == color:
|
||||
continue # 没变,一个 configure 都不发
|
||||
cache[rid] = color
|
||||
is_focus = (color == CARD_FOCUS_BORDER)
|
||||
bg = CARD_FOCUS_BG if is_focus else C.surface
|
||||
qty_fg = CARD_FOCUS_BORDER if is_focus else C.green
|
||||
try:
|
||||
# 粗细也一并写回固定值:万一别处动过它,下一次重画就纠正,
|
||||
# 几何始终不变(写在 configure 里,值相同 Tk 不会引起重排)。
|
||||
c.configure(highlightbackground=color,
|
||||
c.configure(bg=bg,
|
||||
highlightbackground=color,
|
||||
highlightcolor=color,
|
||||
highlightthickness=CARD_HL)
|
||||
for attr in ('_name_lbl', '_meta_lbl', '_qty_lbl',
|
||||
'_thumb_label'):
|
||||
w = getattr(c, attr, None)
|
||||
if w is not None:
|
||||
if attr == '_qty_lbl':
|
||||
w.configure(bg=bg, fg=qty_fg)
|
||||
else:
|
||||
w.configure(bg=bg)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
@@ -3158,7 +3274,7 @@ class App:
|
||||
"""确认状态下点别的卡 = 改判"""
|
||||
ok, msg = self.engine.pick_focus(rid)
|
||||
if not ok and msg:
|
||||
self.lbl_todo_detail.configure(text=msg, fg=C.red)
|
||||
self._set_todo_detail(msg, fg=C.red)
|
||||
|
||||
def _capture_or_retry(self):
|
||||
"""手动抓拍 / 重拍合一(v1.0.62)
|
||||
@@ -3251,12 +3367,16 @@ class App:
|
||||
self._focus_busy = False
|
||||
|
||||
def _focus_cancel(self):
|
||||
self._retry_pending = False
|
||||
self._close_unrecognized_popup()
|
||||
self.engine.cancel_focus('放弃这一件(未记账)')
|
||||
|
||||
def _focus_retry(self):
|
||||
"""重拍:放弃这一件,再起一轮识别"""
|
||||
st = self.engine.state
|
||||
count = (self._focus_p or {}).get('mode') == 'count'
|
||||
self._retry_pending = True
|
||||
self._close_unrecognized_popup()
|
||||
self.engine.cancel_focus('重拍:本件作废')
|
||||
if count:
|
||||
self._start_count()
|
||||
@@ -3288,16 +3408,14 @@ class App:
|
||||
# 分组模式(客户/分类)下在组内排序,不跨组打散客户/分类。
|
||||
if self._group_mode == 'none':
|
||||
show = self._sort_rows_by_product(show)
|
||||
# 现场已统一成商品入库(不再有独立入库/无单直入),标题里不再分叉
|
||||
# 现场已统一成商品入库(不再有独立入库/无单直入),标题保持简洁不与右侧合计重叠
|
||||
if words:
|
||||
self.lbl_todo_title.configure(
|
||||
text='待办名单 · 匹配 %d/%d 行 · %s'
|
||||
% (len(show), len(self._all_rows),
|
||||
'应拣' if picking else '应验'))
|
||||
text='待办 · 匹配 %d/%d 行'
|
||||
% (len(show), len(self._all_rows)))
|
||||
else:
|
||||
self.lbl_todo_title.configure(
|
||||
text='待办名单(%d 行)· %s'
|
||||
% (len(self._all_rows), '应拣' if picking else '应验'))
|
||||
text='待办名单(%d 行)' % len(self._all_rows))
|
||||
totals = {}
|
||||
for r in show:
|
||||
q, unit = self._qty_of(r)
|
||||
@@ -3421,6 +3539,17 @@ class App:
|
||||
self._todo_tail(picking, show, words, kw, totals)
|
||||
self._layout_cards()
|
||||
|
||||
def _set_todo_detail(self, text, fg=None):
|
||||
"""更新待办提示/选中详情文案:不动态 pack/pack_forget,避免整列高度变化引发界面抖动。"""
|
||||
txt = (text or '').strip()
|
||||
try:
|
||||
if fg is not None:
|
||||
self.lbl_todo_detail.configure(text=txt, fg=fg)
|
||||
else:
|
||||
self.lbl_todo_detail.configure(text=txt, fg=C.ink2)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def _todo_tail(self, picking, show, words, kw, totals):
|
||||
"""待办区底部/空态文字与分组条(重建与增量更新两条路共用)"""
|
||||
if not show:
|
||||
@@ -3432,36 +3561,30 @@ class App:
|
||||
bg=C.bg, fg=C.ink3, anchor='w', justify='left')
|
||||
self._empty_lbl.grid(row=0, column=0, sticky='w',
|
||||
padx=self._px(12), pady=self._px(18))
|
||||
self.lbl_todo_detail.configure(text=tip)
|
||||
self._set_todo_detail(tip)
|
||||
elif self._group_pick:
|
||||
tip = '「%s」这一组已经没有待办了 · 点 chips 里的「全部」看别的' \
|
||||
tip = '「%s」这一组已经没有待办了 · 点「全部」看别的' \
|
||||
% self._group_pick
|
||||
self._empty_lbl = tk.Label(
|
||||
self.todo_grid, text=tip, font=self._font(13),
|
||||
bg=C.bg, fg=C.ink3, anchor='w', justify='left')
|
||||
self._empty_lbl.grid(row=0, column=0, sticky='w',
|
||||
padx=self._px(12), pady=self._px(18))
|
||||
self.lbl_todo_detail.configure(text=tip)
|
||||
self._set_todo_detail(tip)
|
||||
else:
|
||||
self.lbl_todo_detail.configure(text='当前账号没有待办行')
|
||||
self._set_todo_detail('当前账号没有待办行')
|
||||
self.todo_canvas.configure(scrollregion=(0, 0, 1, 1))
|
||||
return
|
||||
# 合计:一眼对得上「这轮一共要多少」,不用自己加
|
||||
# 合计:精简展示,不与标题栏冲突
|
||||
tot = ' + '.join('%g %s' % (v, u) for u, v in totals.items() if v)
|
||||
self.lbl_todo_sum.configure(
|
||||
text='合计%s %s' % ('应拣' if picking else '应验', tot or '0'))
|
||||
self.lbl_todo_sum.configure(text=tot or '0')
|
||||
if words:
|
||||
self.lbl_todo_detail.configure(
|
||||
text='搜索「%s」命中 %d 行 · 点一张卡看完整信息'
|
||||
% (kw, len(show)))
|
||||
self._set_todo_detail('搜索「%s」命中 %d 行' % (kw, len(show)))
|
||||
elif self._group_pick:
|
||||
self.lbl_todo_detail.configure(
|
||||
text='只看「%s」· %d 行 · 点一张卡看完整信息'
|
||||
% (self._group_pick, len(show)))
|
||||
self._set_todo_detail('只看「%s」· %d 行'
|
||||
% (self._group_pick, len(show)))
|
||||
else:
|
||||
self.lbl_todo_detail.configure(
|
||||
text='共 %d 行 · 点一张卡看完整信息(规格/编码/客户/单号)'
|
||||
% len(show))
|
||||
self._set_todo_detail('')
|
||||
self._paint_group_bar()
|
||||
|
||||
@staticmethod
|
||||
@@ -3572,7 +3695,7 @@ class App:
|
||||
bg=C.surface, fg=C.ink, anchor='w',
|
||||
justify='left',
|
||||
wraplength=int(150 * self.S))
|
||||
lbl_name.pack(side='top', fill='x', padx=px(12), pady=(px(10), 0))
|
||||
lbl_name.pack(side='top', fill='x', padx=px(10), pady=(px(8), 0))
|
||||
c._name_lbl = lbl_name # _layout_cards 按列宽改 wraplength
|
||||
badge = tk.Label(c, text='独立入库 · 加工原材料',
|
||||
font=self._font(10, 'bold'), bg='#fff4d6',
|
||||
@@ -3586,13 +3709,13 @@ class App:
|
||||
lbl_meta = tk.Label(c, text=meta, font=self._font(10), bg=C.surface,
|
||||
fg=C.ink3, anchor='w', justify='left',
|
||||
wraplength=int(150 * self.S))
|
||||
lbl_meta.pack(side='top', fill='x', padx=px(12), pady=(px(2), 0))
|
||||
lbl_meta.pack(side='top', fill='x', padx=px(10), pady=(px(2), 0))
|
||||
c._meta_lbl = lbl_meta
|
||||
c._meta_who = meta
|
||||
lbl_qty = tk.Label(c, text='%g %s' % (q, unit),
|
||||
font=self._font(16, 'bold'), bg=C.surface,
|
||||
fg=C.green, anchor='w')
|
||||
lbl_qty.pack(side='top', fill='x', padx=px(12), pady=(px(4), px(10)))
|
||||
lbl_qty.pack(side='top', fill='x', padx=px(10), pady=(px(2), px(8)))
|
||||
c._qty_lbl = lbl_qty
|
||||
img = self._thumb_for(r, rid) if self._thumb_on() else None
|
||||
if img is not None:
|
||||
@@ -3738,7 +3861,7 @@ class App:
|
||||
return
|
||||
top = getattr(c, '_top', None)
|
||||
host = top if top is not None else c
|
||||
tl = tk.Label(host, image=ph, bg='#ffffff', bd=0)
|
||||
tl = tk.Label(host, image=ph, bg=host.cget('bg'), bd=0)
|
||||
tl.image = ph
|
||||
if host is top:
|
||||
tl.pack(side='right', padx=(int(6 * self.S), 0))
|
||||
@@ -3851,7 +3974,7 @@ class App:
|
||||
self._page_count = 1
|
||||
self._paint_pager()
|
||||
return
|
||||
gap = int(12 * self.S)
|
||||
gap = int(8 * self.S)
|
||||
# 平板尺寸:一张卡至少 196px(品名 16 号、应拣 16 号,手指点得准),
|
||||
# 1440 屏右栏约 1400px → 6 列;列数按钮可锁 4/5/6。
|
||||
min_card = int(196 * self.S)
|
||||
@@ -3885,44 +4008,45 @@ class App:
|
||||
if (card_w, thumb) != getattr(self, '_mw_prev', None):
|
||||
self._mw_prev = (card_w, thumb)
|
||||
self._geom_dirty = True
|
||||
# 所有卡的换行宽度先按列宽设好(不在本页的卡翻过去时直接用)
|
||||
for kind, obj in items:
|
||||
if kind != 'card':
|
||||
continue
|
||||
# 卡片里的字宽必须跟着列宽走:写死 150/240 会把列撑开,
|
||||
# 列数越多越明显(最后表现为「怎么调都只有 4 列」)
|
||||
name_lbl = getattr(obj, '_name_lbl', None)
|
||||
if name_lbl is not None:
|
||||
wrap = max(int(64 * self.S),
|
||||
card_w - thumb - int(26 * self.S))
|
||||
# v1.0.60:长名字自动降一号字。「上海青(小棠菜)」这种
|
||||
# 16 号放不下会折成两行,右括号孤零零挂在第二行,很难看。
|
||||
# 能压成一行就压(14 号),压不下才照旧折行。
|
||||
size = 16
|
||||
try:
|
||||
txt = str(name_lbl.cget('text') or '')
|
||||
if txt and self._name_font(16).measure(txt) > wrap \
|
||||
and self._name_font(14).measure(txt) <= wrap:
|
||||
size = 14
|
||||
except Exception:
|
||||
pass
|
||||
name_lbl.configure(font=self._name_font(size),
|
||||
wraplength=wrap)
|
||||
self._fit_thumb(obj, card_w)
|
||||
meta_lbl = getattr(obj, '_meta_lbl', None)
|
||||
if meta_lbl is not None:
|
||||
# 卡上只有客户/供应商名了(v1.0.41 起不再放单号),
|
||||
# 宽窄卡内容一致,只需要跟着列宽调换行宽度。
|
||||
meta_lbl.configure(
|
||||
text=getattr(obj, '_meta_who', ''),
|
||||
wraplength=max(int(80 * self.S),
|
||||
card_w - int(16 * self.S)))
|
||||
badge = getattr(obj, '_independent_badge', None)
|
||||
if badge is not None:
|
||||
# 「独立入库原料 12 斤 · 普通入库 20 斤」比原来长,跟着列宽折行
|
||||
badge.configure(
|
||||
wraplength=max(int(80 * self.S),
|
||||
card_w - int(16 * self.S)))
|
||||
# 仅当列宽/缩略图/卡片列表变动时才重算所有卡的换行宽度,普通翻页直接跳过(省数百次 Tk configure)
|
||||
if getattr(self, '_geom_dirty', False):
|
||||
for kind, obj in items:
|
||||
if kind != 'card':
|
||||
continue
|
||||
# 卡片里的字宽必须跟着列宽走:写死 150/240 会把列撑开,
|
||||
# 列数越多越明显(最后表现为「怎么调都只有 4 列」)
|
||||
name_lbl = getattr(obj, '_name_lbl', None)
|
||||
if name_lbl is not None:
|
||||
wrap = max(int(64 * self.S),
|
||||
card_w - thumb - int(22 * self.S))
|
||||
# v1.0.60:长名字自动降一号字。「上海青(小棠菜)」这种
|
||||
# 16 号放不下会折成两行,右括号孤零零挂在第二行,很难看。
|
||||
# 能压成一行就压(14 号),压不下才照旧折行。
|
||||
size = 16
|
||||
try:
|
||||
txt = str(name_lbl.cget('text') or '')
|
||||
if txt and self._name_font(16).measure(txt) > wrap \
|
||||
and self._name_font(14).measure(txt) <= wrap:
|
||||
size = 14
|
||||
except Exception:
|
||||
pass
|
||||
name_lbl.configure(font=self._name_font(size),
|
||||
wraplength=wrap)
|
||||
self._fit_thumb(obj, card_w)
|
||||
meta_lbl = getattr(obj, '_meta_lbl', None)
|
||||
if meta_lbl is not None:
|
||||
# 卡上只有客户/供应商名了(v1.0.41 起不再放单号),
|
||||
# 宽窄卡内容一致,只需要跟着列宽调换行宽度。
|
||||
meta_lbl.configure(
|
||||
text=getattr(obj, '_meta_who', ''),
|
||||
wraplength=max(int(80 * self.S),
|
||||
card_w - int(16 * self.S)))
|
||||
badge = getattr(obj, '_independent_badge', None)
|
||||
if badge is not None:
|
||||
# 「独立入库原料 12 斤 · 普通入库 20 斤」比原来长,跟着列宽折行
|
||||
badge.configure(
|
||||
wraplength=max(int(80 * self.S),
|
||||
card_w - int(16 * self.S)))
|
||||
def _item_height(kind, obj):
|
||||
"""这一项单独占的高度(卡片行取本行最高,见 _paginate_by_height)"""
|
||||
try:
|
||||
@@ -3940,9 +4064,9 @@ class App:
|
||||
self._page_count = len(pages)
|
||||
self._page = max(0, min(self._page, len(pages) - 1))
|
||||
page = pages[self._page]
|
||||
# 只摆当前页,其余全部摘掉:120 行时每页 20 来张,翻页重排 ~2ms
|
||||
# 只摘掉当前在屏但不在新页的控件(不用遍历全部百来张离屏卡)
|
||||
on_page = set(id(o) for _, o in page)
|
||||
for kind, obj in items:
|
||||
for obj in list(self.todo_grid.grid_slaves()):
|
||||
if id(obj) not in on_page:
|
||||
try:
|
||||
obj.grid_forget()
|
||||
@@ -4231,7 +4355,7 @@ class App:
|
||||
else '验', qty, r.get('unit') or ''))
|
||||
if r.get('order_code'):
|
||||
bits.append('单号 %s' % r['order_code'])
|
||||
self.lbl_todo_detail.configure(text=' · '.join(bits))
|
||||
self._set_todo_detail(' · '.join(bits))
|
||||
|
||||
def _on_log(self, s):
|
||||
self.log(s)
|
||||
|
||||
@@ -50,6 +50,8 @@ class SoftKeyboard:
|
||||
self._cur = None
|
||||
self._recognizing = False
|
||||
self._hand_job = None
|
||||
self._candidates = []
|
||||
self._finish_after_recog = False
|
||||
self._hand_q = queue.Queue()
|
||||
self.win = tk.Toplevel(parent)
|
||||
self.win.withdraw()
|
||||
@@ -153,7 +155,8 @@ class SoftKeyboard:
|
||||
self._key(bar, '清空重写', self._hand_clear, bg=FN_BG, size=13)
|
||||
self._key(bar, '重新识别', lambda: self._hand_recognize(force=True),
|
||||
bg=FN_BG, size=13)
|
||||
self._key(bar, '完成 ✓', self.hide, bg=OK_BG, fg='white', size=14)
|
||||
self._key(bar, '完成 ✓', self._hand_finish, bg=OK_BG, fg='white',
|
||||
size=14)
|
||||
|
||||
wrap = tk.Frame(parent, bg=BG)
|
||||
wrap.pack(fill='both', expand=True, padx=px(6), pady=(px(2), 0))
|
||||
@@ -263,8 +266,15 @@ class SoftKeyboard:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def is_visible(self):
|
||||
try:
|
||||
return bool(self.win.winfo_exists() and self.win.winfo_viewable())
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
def hide(self):
|
||||
self._cancel_hand_job()
|
||||
self._finish_after_recog = False
|
||||
try:
|
||||
self.win.withdraw()
|
||||
except Exception:
|
||||
@@ -342,10 +352,20 @@ class SoftKeyboard:
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
def _prepare_target(self, t):
|
||||
"""写入/删字前若目标框正挂着灰色占位提示,先清掉占位,避免字插到占位前面。"""
|
||||
try:
|
||||
if (t is getattr(self.app, 'ent_search', None)
|
||||
and getattr(self.app, '_search_ph_on', False)):
|
||||
self.app._search_focus_in()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def _tap(self, ch):
|
||||
t = self._t()
|
||||
if t is None:
|
||||
return
|
||||
self._prepare_target(t)
|
||||
c = ch.upper() if self.shift and ch.isalpha() else ch
|
||||
try:
|
||||
if not self._is_text(t):
|
||||
@@ -366,6 +386,7 @@ class SoftKeyboard:
|
||||
t = self._t()
|
||||
if t is None:
|
||||
return
|
||||
self._prepare_target(t)
|
||||
try:
|
||||
if not self._is_text(t):
|
||||
if t.selection_present():
|
||||
@@ -383,6 +404,7 @@ class SoftKeyboard:
|
||||
t = self._t()
|
||||
if t is None:
|
||||
return
|
||||
self._prepare_target(t)
|
||||
try:
|
||||
if self._is_text(t):
|
||||
t.delete('1.0', 'end')
|
||||
@@ -469,6 +491,8 @@ class SoftKeyboard:
|
||||
|
||||
def _pen_down(self, e):
|
||||
self._cancel_hand_job()
|
||||
self._finish_after_recog = False
|
||||
self._candidates = []
|
||||
self._cur = [(e.x, e.y)]
|
||||
self._strokes.append(self._cur)
|
||||
try:
|
||||
@@ -546,6 +570,8 @@ class SoftKeyboard:
|
||||
pass
|
||||
return
|
||||
self._recognizing = False
|
||||
finish = self._finish_after_recog
|
||||
self._finish_after_recog = False
|
||||
if kind == 'err':
|
||||
self._set_cand_tip('识别失败:%s\n可点「重新识别」,或切 ABC 键盘'
|
||||
% str(data)[:60], '#a32d2d')
|
||||
@@ -555,12 +581,16 @@ class SoftKeyboard:
|
||||
self._set_cand_tip('没认出来,擦掉重写一次', '#a32d2d')
|
||||
return
|
||||
self._show_candidates(items)
|
||||
if finish:
|
||||
self._pick(items[0])
|
||||
self.hide()
|
||||
|
||||
def _show_candidates(self, items):
|
||||
self._candidates = list(items or [])
|
||||
try:
|
||||
for w in self.cand_box.winfo_children():
|
||||
w.destroy()
|
||||
for it in items:
|
||||
for it in self._candidates:
|
||||
b = tk.Button(self.cand_box, text=it, font=self._fs(15),
|
||||
bd=0, bg='#ffffff', fg='#17334f',
|
||||
activebackground='#cfe0f5', cursor='hand2',
|
||||
@@ -569,13 +599,28 @@ class SoftKeyboard:
|
||||
b.pack(fill='x', pady=self._px(3), ipady=self._px(5))
|
||||
except Exception:
|
||||
return
|
||||
self._set_cand_tip('点一下就填进输入框')
|
||||
self._set_cand_tip('点一下或点「完成」填进输入框')
|
||||
|
||||
def _hand_finish(self):
|
||||
"""手写视图点「完成 ✓」:若有未提交的识别结果则自动填入首候选,再收起。"""
|
||||
if self._candidates:
|
||||
self._pick(self._candidates[0])
|
||||
self.hide()
|
||||
return
|
||||
if self._strokes:
|
||||
self._finish_after_recog = True
|
||||
self._cancel_hand_job()
|
||||
if not self._recognizing:
|
||||
self._hand_recognize(force=True)
|
||||
return
|
||||
self.hide()
|
||||
|
||||
def _pick(self, text):
|
||||
t = self._t()
|
||||
if t is None:
|
||||
self._set_cand_tip('没有输入框可写,先点一下输入框', '#a32d2d')
|
||||
return
|
||||
self._prepare_target(t)
|
||||
try:
|
||||
if not self._is_text(t):
|
||||
try:
|
||||
@@ -591,8 +636,10 @@ class SoftKeyboard:
|
||||
|
||||
def _hand_clear(self):
|
||||
self._cancel_hand_job()
|
||||
self._finish_after_recog = False
|
||||
self._strokes = []
|
||||
self._cur = None
|
||||
self._candidates = []
|
||||
try:
|
||||
self.cv.delete('ink')
|
||||
except Exception:
|
||||
|
||||
Reference in New Issue
Block a user