45 lines
1.6 KiB
Python
45 lines
1.6 KiB
Python
from tkinter import messagebox
|
|
import dcc.config
|
|
import dcc.doom_base
|
|
import sys
|
|
import wand.display
|
|
import wand.image
|
|
|
|
|
|
class SS(dcc.doom_base.WadMap):
|
|
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
|
|
|
|
def take_action(self, parsed_args):
|
|
while not self._try_screenshot(parsed_args.gravity, parsed_args.yolo):
|
|
pass
|
|
|
|
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:
|
|
img.reset_coords()
|
|
if (img.size[0] < width or img.size[1] < height):
|
|
if not messagebox.askretrycancel(
|
|
title="DCC",
|
|
message=f"Image too small ({img.width}x{img.height})." +
|
|
"Try again?"
|
|
):
|
|
sys.exit("Gave up trying to select an image.")
|
|
return False
|
|
img.crop(width=width, height=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
|