Files

97 lines
3.1 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- coding: utf-8 -*-
"""1440×900(现场 19 寸)三张图:登录页 / 主界面 / 人工确认页。"""
import json
import os
import sys
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, ROOT)
os.chdir(ROOT)
import tkinter as tk
from PIL import ImageGrab
import ui.app as A
W, H = 1440, 900
OUT = os.path.join('docs', 'design')
cfg = json.load(open('config.json', encoding='utf-8'))
cfg.setdefault('server', {})['mock'] = True
cfg['ui'] = {'mode': 'window', 'width': W, 'height': H,
'borderless': True}
A.load_config = lambda *a, **k: cfg
ROWS = [
('R7401', '藕', '散装', '兴达蔬菜', 14.60),
('R7402', '大白菜', '散装', '绿源种植', 61.04),
('R7403', '四季豆', '散装', '兴达蔬菜', 26.00),
('R7404', '莴笋', '散装', '绿源种植', 20.00),
('R7405', '圆萝卜', '散装', '兴达蔬菜', 2.00),
('R7406', '马铃薯', '散装', '金土地', 50.00),
('R7407', '红富士苹果', '80#', '红果贸易', 100.00),
('R7408', '水果黄瓜', '散装', '绿源种植', 4.00),
('R7409', '旱黄瓜', '散装', '绿源种植', 2.00),
('R7410', '冰糖橙', '散装', '红果贸易', 30.00),
('R7411', '小白菜', '散装', '兴达蔬菜', 18.50),
('R7412', '胡萝卜', '散装', '金土地', 12.00),
]
rows = []
for i, (code, name, spec, sup, qty) in enumerate(ROWS):
rows.append({'id': 'ins-%03d' % i, 'order_code': code, 'sort_order': i + 1,
'sku_code': 'SKU%04d' % (1027 + i), 'item_name': name,
'spec': spec, 'supplier': sup, 'customer_name': sup,
'unit': '斤', 'prepare_qty': qty, 'required_qty': qty,
'remaining_qty': qty,
'requires_photo_inspection': False})
def grab(win, name):
win.update_idletasks()
win.update()
x, y = win.winfo_rootx(), win.winfo_rooty()
w, h = win.winfo_width(), win.winfo_height()
ImageGrab.grab((x, y, x + w, y + h)).save(os.path.join(OUT, name))
print(name, w, 'x', h)
root = tk.Tk()
app = A.App(root)
def step_login():
grab(root, 'login-preview-1440x900.png')
for w in root.winfo_children():
w.destroy()
app.engine.station = 'inspection'
app._build()
app.ready = True
app._fill_todo(rows)
app.lbl_weight.configure(text='7.3')
app.lbl_jin.configure(text='14.6 斤')
app.lbl_state.configure(text='识别中:藕')
root.after(700, step_main)
def step_main():
grab(root, 'ui-preview-1440x900.png')
app.engine.station = 'inspection'
payload = {'detected': '藕', 'weight': 7.3, 'reason': 'AI 无法确认品名',
'rows': rows, 'candidates': [{'id': r['id']} for r in rows[:8]]}
try:
app._show_confirm(payload)
top = app._confirm_top
top.attributes('-fullscreen', False)
top.geometry('%dx%d+0+0' % (W, H))
top.attributes('-topmost', True)
top.lift()
root.after(800, lambda: (grab(top, 'confirm-preview-1440x900.png'),
root.destroy()))
except Exception as e:
print('confirm failed:', e)
root.destroy()
root.after(1000, step_login)
root.mainloop()