Skip to content

Commit e5a49fa

Browse files
nohwndCopilot
andcommitted
Address review feedback: mss.mss() context manager, fix RECT struct, consistent placeholder
- Use mss.mss() context manager instead of mss.MSS() (ui-screenshots, screen-recording) - Fix broken RECT struct in window+GIF combining example (screen-recording) - Consistent projectId placeholder in AzDO upload example (pr-screenshots) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent bca9d30 commit e5a49fa

3 files changed

Lines changed: 25 additions & 21 deletions

File tree

skills/pr-screenshots/SKILL.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ $token = az account get-access-token `
7878
--resource "499b84ac-1321-427f-aa17-267ca6975798" `
7979
--query accessToken -o tsv
8080
81-
$base = "https://{org}.visualstudio.com/{projectGUID}/_apis/git/repositories/{repoId}"
81+
$base = "https://{org}.visualstudio.com/{projectId}/_apis/git/repositories/{repoId}"
8282
$url = "$base/pullRequests/{prId}/attachments/screenshot.png?api-version=7.1-preview.1"
8383
8484
# Use HttpClient — Invoke-RestMethod can corrupt binary data

skills/screen-recording/SKILL.md

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -148,17 +148,17 @@ import time
148148

149149
def record_gif(output_path, region=None, duration=5, fps=8):
150150
"""Record screen region to GIF. region = {left, top, width, height} or None for full screen."""
151-
sct = mss.MSS()
152-
if region is None:
153-
region = sct.monitors[1] # primary monitor
154-
155-
frames = []
156-
t_end = time.time() + duration
157-
while time.time() < t_end:
158-
t0 = time.time()
159-
shot = sct.grab(region)
160-
frames.append(Image.frombytes('RGB', shot.size, shot.rgb))
161-
time.sleep(max(0, 1 / fps - (time.time() - t0)))
151+
with mss.mss() as sct:
152+
if region is None:
153+
region = sct.monitors[1] # primary monitor
154+
155+
frames = []
156+
t_end = time.time() + duration
157+
while time.time() < t_end:
158+
t0 = time.time()
159+
shot = sct.grab(region)
160+
frames.append(Image.frombytes('RGB', shot.size, shot.rgb))
161+
time.sleep(max(0, 1 / fps - (time.time() - t0)))
162162

163163
frames[0].save(output_path, save_all=True, append_images=frames[1:],
164164
duration=int(1000 / fps), loop=0, optimize=True)
@@ -175,12 +175,16 @@ Tested: 3s at 8fps → 24 frames, ~31KB. Keep fps ≤ 10 for reasonable file siz
175175

176176
```python
177177
# Find window rect, then record it as a GIF
178-
from ui_capture import find_window # see ui-screenshots skill
178+
# Reuse find_window() from the ui-screenshots skill
179179
import ctypes
180-
from ctypes import c_int, Structure, byref
180+
from ctypes import c_int, Structure, byref, windll
181181

182-
rect = Structure() # RECT struct
183-
ctypes.windll.user32.GetWindowRect(find_window('My App')[0][0], ctypes.byref(rect))
182+
class RECT(Structure):
183+
_fields_ = [('left', c_int), ('top', c_int), ('right', c_int), ('bottom', c_int)]
184+
185+
hwnd = find_window('My App')[0][0]
186+
rect = RECT()
187+
windll.user32.GetWindowRect(hwnd, byref(rect))
184188
region = {'left': rect.left, 'top': rect.top,
185189
'width': rect.right - rect.left, 'height': rect.bottom - rect.top}
186190
record_gif('app-demo.gif', region=region, duration=5, fps=8)

skills/ui-screenshots/SKILL.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,11 @@ def capture_window(title_contains, output_path):
147147
user32.GetWindowRect(hwnd, byref(rect))
148148
w, h = rect.right - rect.left, rect.bottom - rect.top
149149

150-
sct = mss.MSS()
151-
shot = sct.grab({'left': rect.left, 'top': rect.top, 'width': w, 'height': h})
152-
img = Image.frombytes('RGB', shot.size, shot.rgb)
153-
img.save(output_path)
154-
return img
150+
with mss.mss() as sct:
151+
shot = sct.grab({'left': rect.left, 'top': rect.top, 'width': w, 'height': h})
152+
img = Image.frombytes('RGB', shot.size, shot.rgb)
153+
img.save(output_path)
154+
return img
155155

156156
# Usage:
157157
capture_window('Visual Studio Code', 'vscode-capture.png')

0 commit comments

Comments
 (0)