Skip to content

Commit

Permalink
Merge pull request #4181 from davep/screenshot-location
Browse files Browse the repository at this point in the history
Add support for specifying the screenshot location and filename
  • Loading branch information
davep authored Feb 19, 2024
2 parents e849168 + c52ad4e commit 1604c2b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

- Added support for environment variable `TEXTUAL_ANIMATIONS` to control what animations Textual displays https://github.com/Textualize/textual/pull/4062
- Add attribute `App.animation_level` to control whether animations on that app run or not https://github.com/Textualize/textual/pull/4062
- Added support for a `TEXTUAL_SCREENSHOT_LOCATION` environment variable to specify the location of an automated screenshot https://github.com/Textualize/textual/pull/4181/
- Added support for a `TEXTUAL_SCREENSHOT_FILENAME` environment variable to specify the filename of an automated screenshot https://github.com/Textualize/textual/pull/4181/


## [0.51.0] - 2024-02-15
Expand Down
10 changes: 7 additions & 3 deletions src/textual/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -1153,7 +1153,7 @@ def export_screenshot(self, *, title: str | None = None) -> str:
def save_screenshot(
self,
filename: str | None = None,
path: str = "./",
path: str | None = None,
time_format: str | None = None,
) -> str:
"""Save an SVG screenshot of the current screen.
Expand All @@ -1168,7 +1168,8 @@ def save_screenshot(
Returns:
Filename of screenshot.
"""
if filename is None:
path = path or "./"
if not filename:
if time_format is None:
dt = datetime.now().isoformat()
else:
Expand Down Expand Up @@ -2397,7 +2398,10 @@ async def _ready(self) -> None:

async def take_screenshot() -> None:
"""Take a screenshot and exit."""
self.save_screenshot()
self.save_screenshot(
path=constants.SCREENSHOT_LOCATION,
filename=constants.SCREENSHOT_FILENAME,
)
self.exit()

if constants.SCREENSHOT_DELAY >= 0:
Expand Down
6 changes: 6 additions & 0 deletions src/textual/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ def _get_textual_animations() -> AnimationLevel:
SCREENSHOT_DELAY: Final[int] = _get_environ_int("TEXTUAL_SCREENSHOT", -1)
"""Seconds delay before taking screenshot."""

SCREENSHOT_LOCATION: Final[str | None] = get_environ("TEXTUAL_SCREENSHOT_LOCATION")
"""The location where screenshots should be written."""

SCREENSHOT_FILENAME: Final[str | None] = get_environ("TEXTUAL_SCREENSHOT_FILENAME")
"""The filename to use for the screenshot."""

PRESS: Final[str] = get_environ("TEXTUAL_PRESS", "")
"""Keys to automatically press."""

Expand Down

0 comments on commit 1604c2b

Please sign in to comment.