From 3807c2d7863c728eda615fdd51fd7c899cc31640 Mon Sep 17 00:00:00 2001 From: Akemi Izuko Date: Wed, 23 Nov 2022 17:56:36 -0700 Subject: [PATCH] Add get_edit_path function to screenshot_wayland --- bin/screenshot_wayland.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/bin/screenshot_wayland.py b/bin/screenshot_wayland.py index ae1bbcd..c2af57a 100755 --- a/bin/screenshot_wayland.py +++ b/bin/screenshot_wayland.py @@ -42,6 +42,24 @@ def get_sceenshot_path() -> Path: else: return p +# Returns a free path to the last screenshot in DIR +# +# Example: +# To edit the screenshot `1669235949.png` it'll return `1669235949_edit_0.png` +# If `1669235949_edit_0.png` exists it returns `1669235949_edit_1.png`... +# Raises IndexError if no screenshot was found in DIR +def get_edit_path(ext: str) -> (Path, Path): + pics = [f for f in os.listdir(DIR) if os.path.isfile(DIR / f)] + originals = [p for p in pics if re.fullmatch(ORIGINAL_REGEX, p)] + originals.sort() + + latest = re.split(EXTENSION_REGEX, originals[-1])[0] + edits = [p for p in pics if re.fullmatch(f"{latest}_edit_[0-9]\.[A-z0-9]+", p)] + edits_nums = [re.fullmatch(EDIT_REGEX, e)[3] for e in edits] + new_index = max([int(n) for n in edits_nums] + [0]) + 1 + + return DIR / originals[-1], DIR / f"{latest}_edit_{new_index}.{ext}" + # Copies the image to the wayland clipboard def copy_to_clipboard(pic: Path): with open(pic, 'r') as img: @@ -209,6 +227,11 @@ edit_subcmd.add_argument( metavar="", help='Exact dimensions of screenshot', ); +edit_subcmd.add_argument( + '-c', '--clipboard', + action='store_true', + help='Save the edited screenshot to your clipboard', +); edit_subcmd.add_argument( '-d', '--drop-shadow', action='store', @@ -219,7 +242,11 @@ edit_subcmd.add_argument( '-e', '--extension', type=int, metavar="", - help='Change image extension saved', + help='Change image extension and type saved', +); +edit_subcmd.add_argument( + "file", nargs='?', type=Path, + help="Save the screenshot to this file name" ); # Markup ==== markup_subcmd = subcommands.add_parser(