2025-04-16 22:52:48 -04:00
|
|
|
from tkinter import messagebox
|
2025-04-16 02:55:14 -04:00
|
|
|
import dcc.config
|
|
|
|
import dcc.doom_base
|
2025-04-16 22:52:48 -04:00
|
|
|
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-04-16 22:52:48 -04:00
|
|
|
|
2025-06-15 12:31:37 -04:00
|
|
|
def _try_screenshot(self, gravity, yolo):
|
|
|
|
with wand.image.Image(
|
|
|
|
width=dcc.config.THUMB_WIDTH,
|
|
|
|
height=dcc.config.THUMB_HEIGHT,
|
|
|
|
pseudo="x:"
|
|
|
|
) as img:
|
|
|
|
img.reset_coords()
|
|
|
|
if (
|
|
|
|
img.size[0] < dcc.config.THUMB_WIDTH
|
|
|
|
or img.size[1] < dcc.config.THUMB_HEIGHT
|
|
|
|
):
|
|
|
|
if not messagebox.askretrycancel(
|
|
|
|
title="DCC", message="Image too small. Try again?"
|
|
|
|
):
|
|
|
|
sys.exit("Gave up trying to select an image.")
|
|
|
|
return False
|
|
|
|
img.crop(
|
|
|
|
width=dcc.config.THUMB_WIDTH,
|
|
|
|
height=dcc.config.THUMB_HEIGHT,
|
|
|
|
gravity=gravity
|
|
|
|
)
|
|
|
|
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
|