WIP - Automate readme screenshots #63
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Generate Screenshots | |
on: | |
pull_request: | |
push: | |
tags: | |
- "v*" | |
jobs: | |
screenshot: | |
runs-on: windows-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Python 3.x | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ">=3.7 <3.12" | |
cache: "pip" | |
- name: Install dependencies | |
run: | | |
pip install -r requirements.txt | |
shell: powershell | |
- name: Increase resolution | |
run: | | |
Set-DisplayResolution -Width 1920 -Height 1080 -Force | |
shell: powershell | |
- name: Run app and take screenshot | |
run: | | |
# Start app and take screenshot | |
python -c " | |
import sys | |
from PyQt5.QtWidgets import QApplication, QMainWindow | |
from torf_gui.ui_mainwindow import Ui_MainWindow | |
from PyQt5.QtGui import QGuiApplication | |
from PyQt5.QtCore import QTimer | |
# Create an instance of the application | |
app = QApplication(sys.argv) | |
# Create a QMainWindow and set up the Ui_MainWindow in it | |
main_window = QMainWindow() | |
ui = Ui_MainWindow() | |
ui.setupUi(main_window) | |
# Function to take screenshot | |
def take_screenshot(): | |
# Grab the screen that contains the window | |
screen = QGuiApplication.screenAt(main_window.geometry().center()) | |
if screen is not None: | |
# Grab the entire screen and crop it to the window geometry | |
screenshot = screen.grabWindow(QApplication.desktop().winId()) | |
cropped_screenshot = screenshot.copy(main_window.frameGeometry()) | |
# Save the cropped screenshot to a file | |
cropped_screenshot.save('screenshot-light.png', 'png') | |
# Quit the application | |
QApplication.quit() | |
# Set a timer to take the screenshot after 5 seconds | |
QTimer.singleShot(5000, take_screenshot) | |
# Start the application | |
main_window.show() | |
sys.exit(app.exec_()) | |
" | |
shell: powershell | |
- name: Upload screenshot | |
uses: actions/upload-artifact@v4 | |
with: | |
name: screenshot-light | |
path: screenshot-light.png |