Skip to content

Commit afb7512

Browse files
committed
Allow taking screenshot of other buffers
1 parent 98b3ccd commit afb7512

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

demosys/view/screenshot.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
from demosys import context
88

99

10+
class Config:
11+
"""Container for screenshot target"""
12+
target = None
13+
alignment = 1
14+
15+
1016
def create(file_format='png', name=None):
1117
"""
1218
Create a screenshot
@@ -21,12 +27,18 @@ def create(file_format='png', name=None):
2127
else:
2228
print("SCREENSHOT_PATH not defined in settings. Using cwd as fallback.")
2329

24-
fbo = context.ctx().screen
25-
image = Image.frombytes("RGB", (fbo.width, fbo.height), fbo.read())
30+
if not Config.target:
31+
Config.target = context.ctx().screen
32+
33+
image = Image.frombytes(
34+
"RGB",
35+
(Config.target.width, Config.target.height), Config.target.read(alignment=Config.alignment)
36+
)
2637
image = image.transpose(Image.FLIP_TOP_BOTTOM)
2738

2839
if not name:
2940
name = "{}.{}".format(datetime.now().strftime("%Y-%m-%d-%H-%M-%S-%f"), file_format)
3041

31-
print("Creating screenshot:", name)
32-
image.save(os.path.join(dest, name), format=file_format)
42+
dest = os.path.join(dest, name)
43+
print("Creating screenshot:", dest)
44+
image.save(dest, format=file_format)

0 commit comments

Comments
 (0)