Screenshot: Add markup support

This commit is contained in:
Akemi Izuko 2022-11-27 22:46:57 -07:00
parent f1e0a6a777
commit 6bb267dd8d
No known key found for this signature in database
GPG key ID: 905D444F6A5E4BE4
2 changed files with 22 additions and 20 deletions

View file

@ -30,13 +30,6 @@ DS_SHADOW_DARK = 'black'
DEFAULT_EDIT_QUALITY = 50 DEFAULT_EDIT_QUALITY = 50
DEFAULT_EDIT_EXTENSION = 'avif' DEFAULT_EDIT_EXTENSION = 'avif'
# Returns the path of the latest screenshot
def get_latest_sceenshot_path() -> Path:
pics = [f for f in os.listdir(DIR) if os.path.isfile(DIR / f)]
pngs = [p for p in pics if re.fullmatch("[0-9_]+\.png", p)]
pngs.sort()
return DIR / pngs[-1]
# Returns a path to an unused screenshot in DIR # Returns a path to an unused screenshot in DIR
def get_sceenshot_path() -> Path: def get_sceenshot_path() -> Path:
t = time.time() t = time.time()
@ -48,6 +41,7 @@ def get_sceenshot_path() -> Path:
return p return p
# Returns a free path to the last screenshot in DIR # Returns a free path to the last screenshot in DIR
# (original_path, new_edit_path)
# #
# Example: # Example:
# To edit the screenshot `1669235949.png` it'll return `1669235949_edit_0.png` # To edit the screenshot `1669235949.png` it'll return `1669235949_edit_0.png`
@ -196,16 +190,20 @@ def archive_subcommand(args):
tar.add(pic, arcname=pic.name) tar.add(pic, arcname=pic.name)
# Provides a drawing editor for the latest image # Provides a drawing editor for the latest image
def markup_latest(args): def markup_subcommand(args):
img = get_latest_sceenshot_path() og_path, edit_path = get_edit_path('png')
if args.gimp: if args.show_latest:
print("TODO gimp") print(og_path)
else: return
run(["swappy", img]).check_returncode()
run(["swappy", "-f", og_path, "-o", edit_path]).check_returncode()
if args.clipboard: if args.clipboard:
copy_to_clipboard(img) copy_to_clipboard(edit_path)
if args.file is not None:
shutil.copyfile(edit_path, args.file)
# =================================================================== # ===================================================================
# Parse args # Parse args
@ -381,10 +379,15 @@ markup_subcmd.add_argument(
help='Save the screenshot to your clipboard', help='Save the screenshot to your clipboard',
); );
markup_subcmd.add_argument( markup_subcmd.add_argument(
'--gimp', '-s', '--show-latest',
action='store_true', action='store_true',
help='Edit via gimp, instead of swappy', help='Show the path to the latest image and exit',
); );
markup_subcmd.add_argument(
"file", nargs='?', type=Path,
help="Save the edited screenshot to this file name",
);
args = parser.parse_args(); args = parser.parse_args();
# Second layer of parser checks # Second layer of parser checks
@ -405,6 +408,4 @@ match args.subcommand:
case "archive": case "archive":
archive_subcommand(args) archive_subcommand(args)
case "markup": case "markup":
print("Markup is not ready for use yet") markup_subcommand(args)
exit(1)
markup_latest(args)

View file

@ -305,7 +305,8 @@ mode "screenshots" {
# 1. Get screenshot # 1. Get screenshot
bindsym a exec $screenshot_script take select -c $screenshot_tmp && $screenshot_sound bindsym a exec $screenshot_script take select -c $screenshot_tmp && $screenshot_sound
bindsym f exec $screenshot_script take full -c $screenshot_tmp && $screenshot_sound bindsym f exec $screenshot_script take full -c $screenshot_tmp && $screenshot_sound
bindsym m mode "default"; exec $screenshot_script markup bindsym m mode "default"; exec $screenshot_script markup -c $screenshot_tmp && $screenshot_sound
bindsym g mode "default"; exec gimp $($screenshot_script markup --show-latest)
# 2. Downsize the screenshot, since 4k is too big # 2. Downsize the screenshot, since 4k is too big
bindsym 1 exec $screenshot_script edit -c -e png -q '40%' -r '50%' $screenshot_tmp && $screenshot_sound bindsym 1 exec $screenshot_script edit -c -e png -q '40%' -r '50%' $screenshot_tmp && $screenshot_sound