diff --git a/.github/workflows/screenshots.yml b/.github/workflows/screenshots.yml new file mode 100644 index 0000000..f4ad100 --- /dev/null +++ b/.github/workflows/screenshots.yml @@ -0,0 +1,113 @@ +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 . + shell: powershell + + - name: Increase resolution + run: | + Set-DisplayResolution -Width 1920 -Height 1080 -Force + shell: powershell + + - name: Hide taskbar + run: | + $location = @{Path = 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\StuckRects3'; Name = 'Settings'} + $value = Get-ItemPropertyValue @location + $value[8] = 123 + Set-ItemProperty @location $value + Stop-Process -Name Explorer + shell: powershell + + # Debug capture the entire screen + - uses: OrbitalOwen/desktop-screenshot-action@0.1 + with: + file-name: "screenshot-debug0.jpg" + + # - name: Upload screenshots + # uses: actions/upload-artifact@v4 + # with: + # name: screenshots + # path: screenshot-*.png + + # - name: Run app and take screenshot (Light mode) + # run: | + # .\screenshot.ps1 light + # shell: powershell + + - name: Run app + run: | + Start-Process -NoNewWindow -FilePath "python" -ArgumentList "torf_gui/gui.py" + shell: powershell + + - name: Wait for app to start + run: | + Start-Sleep -s 5 + shell: powershell + + # Debug capture the entire screen + - uses: OrbitalOwen/desktop-screenshot-action@0.1 + with: + file-name: "screenshot-debug1.jpg" + + # - name: Upload screenshots + # uses: actions/upload-artifact@v4 + # with: + # name: screenshots + # path: screenshot-*.png + + - name: Set dark mode + run: | + $darkModeReg = "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize" + Set-ItemProperty -Path $darkModeReg -Name "AppsUseLightTheme" -Value 0 + shell: powershell + + # - name: Run app and take screenshot (Dark mode) + # run: | + # .\screenshot.ps1 dark + # shell: powershell + + - name: Run app + run: | + Start-Process -NoNewWindow -FilePath "python" -ArgumentList "torf_gui/gui.py" + shell: powershell + + - name: Wait for app to start + run: | + Start-Sleep -s 5 + shell: powershell + + # Debug capture the entire screen + - uses: OrbitalOwen/desktop-screenshot-action@0.1 + with: + file-name: "screenshot-debug2.jpg" + + - name: list directory + run: | + Get-ChildItem + shell: powershell + + - name: Upload screenshots + uses: actions/upload-artifact@v4 + with: + name: screenshots + path: screenshot-*.* diff --git a/.gitignore b/.gitignore index 009c104..7579fba 100644 --- a/.gitignore +++ b/.gitignore @@ -90,3 +90,7 @@ ENV/ # pytest .pytest_cache/ + +screenshot-light.png +screenshot-dark.png +screenshot.png diff --git a/screenshot.ps1 b/screenshot.ps1 new file mode 100644 index 0000000..44a4aee --- /dev/null +++ b/screenshot.ps1 @@ -0,0 +1,96 @@ +param ( + [Parameter(Mandatory = $true)] + [ValidateSet("light", "dark")] + [string]$theme +) + +# Debug print the theme +Write-Host "Theme: $theme" + +$version = (Get-Content torf_gui/version.py | Select-String -Pattern "__version__").ToString().Split(" ")[2].Trim('"') + +# Print the version + +Write-Host "Version: $version" + +# Start the Python script +Start-Process python "torf_gui/gui.py" + +Write-Host "Waiting for the process to start..." + +# Wait for the new process to start +Start-Sleep -Seconds 5 + +# Get the new Python process +$newProcess = Get-Process -Name python | Where-Object { $_.Id -ne $originalProcess.Id } + +# Debug print running processes +# Write-Host "Running processes:" +# Get-Process | ForEach-Object { Write-Host $_.Name } + +# Debug print the process ID +Write-Host "Process ID: $($newProcess.Id)" + +# Capture the window screenshot +Add-Type -TypeDefinition @" +using System; +using System.Drawing; +using System.Windows.Forms; +using System.Runtime.InteropServices; + +[StructLayout(LayoutKind.Sequential)] +public struct RECT { + public int Left; + public int Top; + public int Right; + public int Bottom; +} + +public class ScreenCapture { + [DllImport("user32.dll")] + public static extern IntPtr FindWindow(string lpClassName, string lpWindowName); + + [DllImport("user32.dll")] + public static extern bool GetClientRect(IntPtr hWnd, out RECT lpRect); + + [DllImport("user32.dll")] + public static extern bool ClientToScreen(IntPtr hWnd, ref Point lpPoint); + + public Image CaptureWindow(string windowTitle) { + IntPtr handle = FindWindow(null, windowTitle); + if (handle == IntPtr.Zero) { + throw new ArgumentException(String.Format("Window with title '{0}' not found.", windowTitle)); + } + + RECT rect; + GetClientRect(handle, out rect); + var topLeft = new Point(rect.Left, rect.Top); + var bottomRight = new Point(rect.Right, rect.Bottom); + ClientToScreen(handle, ref topLeft); + ClientToScreen(handle, ref bottomRight); + return CaptureArea(new Rectangle(topLeft.X, topLeft.Y, bottomRight.X - topLeft.X, bottomRight.Y - topLeft.Y)); + } + + public Image CaptureArea(Rectangle area) { + var bitmap = new Bitmap(area.Width, area.Height); + using (var graphics = Graphics.FromImage(bitmap)) { + graphics.CopyFromScreen(area.Left, area.Top, 0, 0, area.Size); + } + return bitmap; + } +} +"@ -ReferencedAssemblies System.Drawing, System.Drawing.Common, System.Drawing.Primitives, System.Windows.Forms + +# Capture the window screenshot + +Write-Host "Capturing the window screenshot..." + +$screenCapture = New-Object ScreenCapture +Write-Host "Test 1" +$bitmap = $screenCapture.CaptureWindow("torf-gui $version") +Write-Host "Test 2" +$bitmap.Save("screenshot-$theme.png", [System.Drawing.Imaging.ImageFormat]::Png) +Write-Host "Test 3" + +# Close the Python script +$newProcess.Kill() \ No newline at end of file