mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Merge pull request #1518 from edrogers/fix-formatting-of-default-screenshot-filename
Make default filename for screenshots use ISO8601 datetime format
This commit is contained in:
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
|
||||
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
||||
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
## [0.11.0] - Unreleased
|
||||
|
||||
### Changed
|
||||
|
||||
- The default filename for screenshots uses a datetime format similar to ISO8601, but with reserved characters replaced by underscores https://github.com/Textualize/textual/pull/1518
|
||||
|
||||
## [0.10.0] - 2023-01-19
|
||||
|
||||
### Added
|
||||
|
||||
@@ -722,7 +722,7 @@ class App(Generic[ReturnType], DOMNode):
|
||||
self,
|
||||
filename: str | None = None,
|
||||
path: str = "./",
|
||||
time_format: str = "%Y%m%d %H%M%S %f",
|
||||
time_format: str | None = None,
|
||||
) -> str:
|
||||
"""Save an SVG screenshot of the current screen.
|
||||
|
||||
@@ -730,17 +730,21 @@ class App(Generic[ReturnType], DOMNode):
|
||||
filename: Filename of SVG screenshot, or None to auto-generate
|
||||
a filename with the date and time. Defaults to None.
|
||||
path: Path to directory for output. Defaults to current working directory.
|
||||
time_format: Time format to use if filename is None. Defaults to "%Y-%m-%d %X %f".
|
||||
time_format: Date and time format to use if filename is None.
|
||||
Defaults to a format like ISO 8601 with some reserved characters replaced with underscores.
|
||||
|
||||
Returns:
|
||||
Filename of screenshot.
|
||||
"""
|
||||
if filename is None:
|
||||
svg_filename = (
|
||||
f"{self.title.lower()} {datetime.now().strftime(time_format)}.svg"
|
||||
)
|
||||
for reserved in '<>:"/\\|?*':
|
||||
svg_filename = svg_filename.replace(reserved, "_")
|
||||
if time_format is None:
|
||||
dt = datetime.now().isoformat()
|
||||
else:
|
||||
dt = datetime.now().strftime(time_format)
|
||||
svg_filename_stem = f"{self.title.lower()} {dt}"
|
||||
for reserved in ' <>:"/\\|?*.':
|
||||
svg_filename_stem = svg_filename_stem.replace(reserved, "_")
|
||||
svg_filename = svg_filename_stem + ".svg"
|
||||
else:
|
||||
svg_filename = filename
|
||||
svg_path = os.path.expanduser(os.path.join(path, svg_filename))
|
||||
|
||||
Reference in New Issue
Block a user