98 lines
2.4 KiB
Python
98 lines
2.4 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""v1.0.33 界面图:设置页新增「AI 识别提示词」卡片 + 当前用词查看窗。
|
|
|
|
① 设置页:提示词来源一行(服务端 vN / 服务端缓存 / 内置默认)+ 立即同步
|
|
② 「看当前用词…」:三条提示词原文 + 各自来源与版本
|
|
"""
|
|
import json
|
|
import os
|
|
import sys
|
|
import time
|
|
|
|
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')
|
|
os.makedirs(OUT, exist_ok=True)
|
|
|
|
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
|
|
|
|
|
|
def grab(win, name, box=None):
|
|
try:
|
|
win.attributes('-topmost', True)
|
|
win.lift()
|
|
win.focus_force()
|
|
except Exception:
|
|
pass
|
|
win.update_idletasks()
|
|
win.update()
|
|
time.sleep(0.35)
|
|
win.update()
|
|
x, y = win.winfo_rootx(), win.winfo_rooty()
|
|
w, h = win.winfo_width(), win.winfo_height()
|
|
x0, y0, x1, y1 = box or (x, y, x + w, y + h)
|
|
ImageGrab.grab((x0, y0, x1, y1)).save(os.path.join(OUT, name))
|
|
print(name, w, 'x', h)
|
|
|
|
|
|
root = tk.Tk()
|
|
app = A.App(root)
|
|
|
|
|
|
def tops(w, out=None):
|
|
"""递归找所有 Toplevel(设置页里的查看窗挂在设置窗下面,不是 root)。"""
|
|
out = out if out is not None else []
|
|
for c in w.winfo_children():
|
|
if isinstance(c, tk.Toplevel):
|
|
out.append(c)
|
|
tops(c, out)
|
|
return out
|
|
|
|
|
|
def step1():
|
|
for w in root.winfo_children():
|
|
w.destroy()
|
|
app.engine.station = 'picking'
|
|
app._build()
|
|
app.ready = True
|
|
app._settings()
|
|
root.after(700, step2)
|
|
|
|
|
|
def step2():
|
|
wins = [w for w in tops(root) if w.winfo_viewable()]
|
|
if not wins:
|
|
print('设置窗口没出来')
|
|
root.destroy()
|
|
return
|
|
setwin = wins[0]
|
|
grab(setwin, 'settings-prompt-1440x900.png')
|
|
app._prompt_detail(setwin)
|
|
root.after(700, lambda: step3(setwin))
|
|
|
|
|
|
def step3(setwin):
|
|
wins = [w for w in tops(root) if w.winfo_viewable() and w is not setwin]
|
|
if not wins:
|
|
print('提示词查看窗没出来')
|
|
root.destroy()
|
|
return
|
|
grab(wins[0], 'prompt-detail-1440x900.png')
|
|
root.destroy()
|
|
|
|
|
|
root.after(900, step1)
|
|
root.mainloop()
|