Add get_edit_path function to screenshot_wayland

This commit is contained in:
Akemi Izuko 2023-12-23 20:14:00 -07:00
parent 8280bfd819
commit c77c143fbe
Signed by: akemi
GPG key ID: 8DE0764E1809E9FC

View file

@ -42,6 +42,24 @@ def get_sceenshot_path() -> Path:
else: else:
return p 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 # Copies the image to the wayland clipboard
def copy_to_clipboard(pic: Path): def copy_to_clipboard(pic: Path):
with open(pic, 'r') as img: with open(pic, 'r') as img:
@ -209,6 +227,11 @@ edit_subcmd.add_argument(
metavar="<dims>", metavar="<dims>",
help='Exact dimensions of screenshot', 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( edit_subcmd.add_argument(
'-d', '--drop-shadow', '-d', '--drop-shadow',
action='store', action='store',
@ -219,7 +242,11 @@ edit_subcmd.add_argument(
'-e', '--extension', '-e', '--extension',
type=int, type=int,
metavar="<ext>", metavar="<ext>",
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 ====
markup_subcmd = subcommands.add_parser( markup_subcmd = subcommands.add_parser(