49 lines
2.0 KiB
Python
49 lines
2.0 KiB
Python
"""Render every page at a chosen Qt scale using an isolated UI profile."""
|
|
import argparse
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument('--request', type=Path)
|
|
parser.add_argument('--evidence', required=True, type=Path)
|
|
options = parser.parse_args()
|
|
evidence = options.evidence.resolve()
|
|
evidence.mkdir(parents=True, exist_ok=True)
|
|
os.environ['LOCALAPPDATA'] = str(evidence / 'profile')
|
|
from PySide6.QtWidgets import QAbstractButton
|
|
from dx_productivity.ui.app import create_application, create_main_window
|
|
app = create_application([])
|
|
window = create_main_window(options.request)
|
|
report = {'scale': os.environ.get('QT_SCALE_FACTOR', '1'), 'pages': []}
|
|
try:
|
|
window.show_toolbar()
|
|
app.processEvents()
|
|
window.toolbar.grab().save(str(evidence / 'toolbar.png'))
|
|
report['toolbar_size'] = [window.toolbar.width(), window.toolbar.height()]
|
|
for index, name in enumerate(window.navigation_items()):
|
|
window.show_panel(index)
|
|
app.processEvents()
|
|
app.processEvents()
|
|
outside = []
|
|
for button in window.pages.currentWidget().findChildren(QAbstractButton):
|
|
if button.isVisibleTo(window):
|
|
point = button.mapTo(window, button.rect().bottomRight())
|
|
if not window.rect().contains(point):
|
|
outside.append(button.text())
|
|
window.grab().save(str(evidence / f'page-{index}.png'))
|
|
report['pages'].append({'name': name, 'size': [window.width(), window.height()],
|
|
'outside_buttons': outside})
|
|
assert not any(page['outside_buttons'] for page in report['pages']), report
|
|
finally:
|
|
window.request_exit()
|
|
app.processEvents()
|
|
(evidence / 'render.json').write_text(json.dumps(report, ensure_ascii=False, indent=2), encoding='utf-8')
|
|
print(json.dumps(report, ensure_ascii=False))
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|