Files
kefu/wechat_rpa/tmp/verify_frameless_preview.py
T
2026-09-21 10:34:06 +08:00

45 lines
1.9 KiB
Python

import json
import os
import sys
from pathlib import Path
from unittest import mock
os.environ['QT_QPA_PLATFORM'] = 'windows'
os.environ['QTWEBENGINE_CHROMIUM_FLAGS'] = '--disable-gpu'
os.environ['QT_SCALE_FACTOR'] = '1'
sys.path.insert(0, 'C:/kefu/wechat_rpa')
from PySide6.QtCore import QTimer, Qt
from PySide6.QtWidgets import QApplication, QMainWindow
from desktop_window import DesktopWindowBar
from wechat_gui_qt import APP_QSS, ConsoleShell, _register_bundled_fonts, _ui_font
app = QApplication([])
_register_bundled_fonts()
app.setStyle('Fusion')
app.setStyleSheet(APP_QSS)
app.setFont(_ui_font(9))
window = QMainWindow()
window._push_console_state = mock.Mock()
bar = DesktopWindowBar(window)
window.setMenuBar(bar)
bar.addMenu('账号 · admin').addAction('退出登录')
shell = ConsoleShell(window)
window.console_shell = shell
window.setCentralWidget(shell)
window.resize(1630, 952)
window.show()
output = Path('C:/kefu/wechat_rpa/tmp/frameless-console.png')
def capture():
assert shell.page_ready, 'Console page failed to load'
assert window.frameGeometry() == window.geometry(), 'Native frame is still present'
assert window.grab().save(str(output))
print(json.dumps({'frame': window.frameGeometry().getRect(), 'window': window.geometry().getRect(), 'webView': shell.geometry().getRect(), 'output': str(output)}))
app.quit()
def ready(ok):
if not ok:
app.exit(2)
return
shell.page().runJavaScript('window.applyState(' + json.dumps({'view':'auto','ready':True,'demo':False,'listening':False,'statusLabel':'已停止','queue':[],'events':[],'aiOk':True,'wecomConnected':False,'people':[],'task':None,'archives':[],'chat':[],'memory':{},'settle':[],'journey':[],'chain':[],'activities':[],'logs':[],'exceptions':{},'ai':{},'automation':{},'system':{},'metrics':{}}, ensure_ascii=False) + ')')
QTimer.singleShot(1800, capture)
shell.loadFinished.connect(ready)
QTimer.singleShot(15000, lambda: app.exit(3))
sys.exit(app.exec())