88 lines
3.0 KiB
Python
88 lines
3.0 KiB
Python
# -*- coding: utf-8 -*-
|
||
"""按现场 19 寸 1440×900 渲染主界面并截图(不改 config.json,用内存配置)。
|
||
|
||
用法:python tools/_shot_1440.py [宽] [高] [输出名]
|
||
"""
|
||
import json
|
||
import os
|
||
import sys
|
||
|
||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||
os.chdir(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||
|
||
import tkinter as tk
|
||
from PIL import ImageGrab
|
||
|
||
import ui.app as A
|
||
|
||
W = int(sys.argv[1]) if len(sys.argv) > 1 else 1440
|
||
H = int(sys.argv[2]) if len(sys.argv) > 2 else 900
|
||
OUT = sys.argv[3] if len(sys.argv) > 3 else 'ui-shot-%dx%d.png' % (W, H)
|
||
|
||
cfg = json.load(open('config.json', encoding='utf-8'))
|
||
cfg.setdefault('server', {})['mock'] = True
|
||
cfg['ui'] = {'mode': 'window', 'width': W, 'height': H,
|
||
'borderless': True, 'todo_cols': 4}
|
||
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, unit) 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': unit, 'prepare_qty': qty, 'required_qty': qty,
|
||
'remaining_qty': qty,
|
||
'requires_photo_inspection': False})
|
||
|
||
root = tk.Tk()
|
||
app = A.App(root)
|
||
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='识别中:藕')
|
||
|
||
|
||
def shot():
|
||
try:
|
||
root.deiconify()
|
||
root.attributes('-topmost', True)
|
||
root.lift()
|
||
root.focus_force()
|
||
root.update_idletasks()
|
||
root.update()
|
||
except Exception as e:
|
||
print('raise failed:', e)
|
||
x, y = root.winfo_rootx(), root.winfo_rooty()
|
||
w, h = root.winfo_width(), root.winfo_height()
|
||
img = ImageGrab.grab((x, y, x + w, y + h))
|
||
d = os.path.join('docs', 'design')
|
||
os.makedirs(d, exist_ok=True)
|
||
p = os.path.join(d, OUT)
|
||
img.save(p)
|
||
print('size', w, 'x', h, '→', p)
|
||
root.destroy()
|
||
|
||
|
||
root.after(1200, shot)
|
||
root.mainloop()
|