Skip to content

Commit

Permalink
Use screenshot.py
Browse files Browse the repository at this point in the history
  • Loading branch information
SavageCore committed Feb 9, 2024
1 parent ec3635b commit a2a6b04
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 42 deletions.
36 changes: 1 addition & 35 deletions .github/workflows/screenshots.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,41 +32,7 @@ jobs:
- 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_())
"
python screenshot.py
shell: powershell

- name: Upload screenshot
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,5 @@ ENV/

# pytest
.pytest_cache/

screenshot-light.png
37 changes: 30 additions & 7 deletions screenshot.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,43 @@
import sys

from PyQt5.QtCore import QTimer
from PyQt5.QtWidgets import QApplication
from PyQt5.QtGui import QGuiApplication
from PyQt5.QtWidgets import QApplication, QMainWindow

from torf_gui.gui import TorfGUI
from torf_gui import __version__
from torf_gui.ui_mainwindow import Ui_MainWindow

PROGRAM_NAME = "torf-gui"
PROGRAM_NAME_VERSION = f"{PROGRAM_NAME} {__version__}"

# Create an instance of the application
app = QApplication(sys.argv)

# Create an instance of the main window class, set up its UI, and show it
main_window = TorfGUI()
main_window.setupUi(main_window)
main_window.show()
# Create a QMainWindow and set up the Ui_MainWindow in it
main_window = QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(main_window)
# Set the window title
main_window.setWindowTitle(PROGRAM_NAME_VERSION)


# 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, main_window.take_screenshot)
QTimer.singleShot(5000, take_screenshot)

# Start the application
main_window.show()
sys.exit(app.exec_())

0 comments on commit a2a6b04

Please sign in to comment.