From 3bd5e94c34f4668fb1cd42946974970d67dfb61d Mon Sep 17 00:00:00 2001 From: Ed Rogers Date: Sat, 7 Jan 2023 22:55:29 -0600 Subject: [PATCH 1/3] Make default filename for screenshots use ISO8601 datetime format --- CHANGELOG.md | 1 + src/textual/app.py | 15 +++++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6eed955935..c8eb04ce67 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - `MouseScrollUp` and `MouseScrollDown` now inherit from `MouseEvent` and have attached modifier keys. https://github.com/Textualize/textual/pull/1458 - Fail-fast and print pretty tracebacks for Widget compose errors https://github.com/Textualize/textual/pull/1505 +- The default filename for screenshots uses ISO8601 datetime format, with colons and spaces replaced with underscores https://github.com/Textualize/textual/pull/1518 ### Fixed diff --git a/src/textual/app.py b/src/textual/app.py index b207bbd025..ea1e43b3c1 100644 --- a/src/textual/app.py +++ b/src/textual/app.py @@ -644,7 +644,7 @@ def save_screenshot( 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. @@ -652,16 +652,19 @@ def save_screenshot( filename (str | None, optional): Filename of SVG screenshot, or None to auto-generate a filename with the date and time. Defaults to None. path (str, optional): Path to directory for output. Defaults to current working directory. - time_format (str, optional): Time format to use if filename is None. Defaults to "%Y-%m-%d %X %f". + time_format (str | None, optional): Date and time format to use if filename is None. + Defaults to ISO 8601 format. Colons are replaced with underscores. Returns: str: Filename of screenshot. """ if filename is None: - svg_filename = ( - f"{self.title.lower()} {datetime.now().strftime(time_format)}.svg" - ) - for reserved in '<>:"/\\|?*': + if time_format is None: + dt = datetime.now().isoformat() + else: + dt = datetime.now().strftime(time_format) + svg_filename = f"{self.title.lower()} {dt}.svg" + for reserved in ' <>:"/\\|?*': svg_filename = svg_filename.replace(reserved, "_") else: svg_filename = filename From 61da0c5c70f518646900569a75f720af2bc6ac25 Mon Sep 17 00:00:00 2001 From: Ed Rogers Date: Wed, 18 Jan 2023 18:56:40 -0600 Subject: [PATCH 2/3] Add full stop to reserved character list --- CHANGELOG.md | 2 +- src/textual/app.py | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c8eb04ce67..31d343be69 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,7 +17,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - `MouseScrollUp` and `MouseScrollDown` now inherit from `MouseEvent` and have attached modifier keys. https://github.com/Textualize/textual/pull/1458 - Fail-fast and print pretty tracebacks for Widget compose errors https://github.com/Textualize/textual/pull/1505 -- The default filename for screenshots uses ISO8601 datetime format, with colons and spaces replaced with underscores https://github.com/Textualize/textual/pull/1518 +- 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 ### Fixed diff --git a/src/textual/app.py b/src/textual/app.py index ea1e43b3c1..8da8846f6e 100644 --- a/src/textual/app.py +++ b/src/textual/app.py @@ -663,9 +663,10 @@ def save_screenshot( dt = datetime.now().isoformat() else: dt = datetime.now().strftime(time_format) - svg_filename = f"{self.title.lower()} {dt}.svg" - for reserved in ' <>:"/\\|?*': - svg_filename = svg_filename.replace(reserved, "_") + 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)) From 1c3329ad47df93c44f19c0435f8ecb360c4f6b09 Mon Sep 17 00:00:00 2001 From: Ed Rogers Date: Wed, 18 Jan 2023 19:07:21 -0600 Subject: [PATCH 3/3] Update doc-string --- src/textual/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/textual/app.py b/src/textual/app.py index 8da8846f6e..0cd23f40fb 100644 --- a/src/textual/app.py +++ b/src/textual/app.py @@ -653,7 +653,7 @@ def save_screenshot( a filename with the date and time. Defaults to None. path (str, optional): Path to directory for output. Defaults to current working directory. time_format (str | None, optional): Date and time format to use if filename is None. - Defaults to ISO 8601 format. Colons are replaced with underscores. + Defaults to a format like ISO 8601 with some reserved characters replaced with underscores. Returns: str: Filename of screenshot.