98 lines
2.9 KiB
Python
98 lines
2.9 KiB
Python
# -*- coding: utf-8 -*-
|
||
"""1440×900:分拣工位「不称重分拣」主界面 + 核对页。"""
|
||
import glob
|
||
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 = [
|
||
('P9001', '圆萝卜', '散装', '一号食堂', 20.00, '斤'),
|
||
('P9002', '藕', '散装', '二号食堂', 14.60, '斤'),
|
||
('P9003', '大白菜', '散装', '三号食堂', 61.00, '斤'),
|
||
('P9004', '马铃薯', '散装', '一号食堂', 50.00, '斤'),
|
||
('P9005', '红富士苹果', '80#', '四号食堂', 30.00, '斤'),
|
||
('P9006', '桶装水', '18.9L', '三号食堂', 4.00, '桶'),
|
||
('P9007', '嫩豆腐', '盒装', '二号食堂', 12.00, '盒'),
|
||
('P9008', '水果黄瓜', '散装', '四号食堂', 8.00, '斤'),
|
||
]
|
||
rows = []
|
||
for i, (code, name, spec, cust, qty, unit) in enumerate(ROWS):
|
||
rows.append({'id': 'pk-%03d' % i, 'pick_code': code, 'order_code': code,
|
||
'sort_order': i + 1, 'sku_code': 'SKU%04d' % (2028 + i),
|
||
'item_name': name, 'spec': spec, 'customer_name': cust,
|
||
'unit': unit, 'required_qty': qty, 'prepare_qty': qty,
|
||
'requires_photo': 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)
|
||
|
||
|
||
def shot_path():
|
||
for p in glob.glob('data/photos/*.png') + glob.glob('data/photos/*.jpg'):
|
||
return p
|
||
return ''
|
||
|
||
|
||
root = tk.Tk()
|
||
app = A.App(root)
|
||
|
||
|
||
def step_main():
|
||
for w in root.winfo_children():
|
||
w.destroy()
|
||
app.engine.station = 'picking'
|
||
app.engine.rows = rows
|
||
app._build()
|
||
app.ready = True
|
||
app._fill_todo(rows)
|
||
app._on_state('IDLE')
|
||
root.after(700, step_shoot)
|
||
|
||
|
||
def step_shoot():
|
||
grab(root, 'picking-preview-1440x900.png')
|
||
root.after(300, step_dialog)
|
||
|
||
|
||
def step_dialog():
|
||
payload = {'detected': '圆萝卜', 'row': rows[0], 'rows': rows,
|
||
'candidates': [], 'qty': 20, 'snapshot': shot_path(),
|
||
'warn': '', 'station': 'picking'}
|
||
try:
|
||
app._on_count_confirm(payload)
|
||
top = app._count_top
|
||
top.attributes('-topmost', True)
|
||
top.lift()
|
||
root.after(900, lambda: (grab(top, 'noweigh-picking-1440x900.png'),
|
||
root.destroy()))
|
||
except Exception as e:
|
||
print('dialog failed:', e)
|
||
root.destroy()
|
||
|
||
|
||
root.after(1000, step_main)
|
||
root.mainloop()
|