doomcc/dcc/ss.py

46 lines
1.6 KiB
Python
Raw Normal View History

from tkinter import messagebox
2025-04-16 02:55:14 -04:00
import dcc.config
import dcc.doom_base
import sys
import wand.display
2025-04-16 02:55:14 -04:00
import wand.image
2025-06-15 12:31:37 -04:00
2025-04-16 02:55:14 -04:00
class SS(dcc.doom_base.WadMap):
2025-06-15 12:31:37 -04:00
def get_parser(self, prog_name):
parser = super().get_parser(prog_name)
parser.add_argument("-g", "--gravity", default="center")
parser.add_argument("-y", "--yolo", action="store_true")
return parser
2025-04-16 02:55:14 -04:00
2025-06-15 12:31:37 -04:00
def take_action(self, parsed_args):
while not self._try_screenshot(parsed_args.gravity, parsed_args.yolo):
pass
2025-06-15 12:31:37 -04:00
def _try_screenshot(self, gravity, yolo):
width = self.thumbnail_width
height = self.thumbnail_height
with wand.image.Image(width=width, height=height, pseudo="x:") as img:
2025-06-15 12:31:37 -04:00
img.reset_coords()
if (img.size[0] < width or img.size[1] < height):
2025-06-15 12:31:37 -04:00
if not messagebox.askretrycancel(
title="DCC",
message=f"Image too small ({img.width}x{img.height})." +
"Try again?"
2025-06-15 12:31:37 -04:00
):
sys.exit("Gave up trying to select an image.")
return False
img.crop(width=width, height=height, gravity=gravity)
2025-06-15 12:31:37 -04:00
img.reset_coords()
if not yolo:
wand.display.display(img)
accepted = messagebox.askyesnocancel(
title="DCC", message="Is this image acceptable?"
)
if accepted is None:
sys.exit("Gave up on image verification")
if not accepted:
return False
img.save(filename=self.base_thumb_path())
return True