Repeatedly try to take a screenshot until we get an acceptable one.
This commit is contained in:
parent
1094c3aba9
commit
3d010a2609
1 changed files with 25 additions and 5 deletions
30
dcc/ss.py
30
dcc/ss.py
|
@ -1,16 +1,36 @@
|
|||
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):
|
||||
with wand.image.Image(width=THUMB_WIDTH, height=THUMB_HEIGHT, pseudo="x:") as img:
|
||||
img.reset_coords()
|
||||
img.crop(width=THUMB_WIDTH,height=THUMB_HEIGHT,gravity="center")
|
||||
img.reset_coords()
|
||||
img.save(filename=dcc.config.BaseThumbPath(parsed_args.wad, parsed_args.map))
|
||||
def try_screenshot():
|
||||
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=parsed_args.gravity)
|
||||
img.reset_coords()
|
||||
if not parsed_args.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=dcc.config.BaseThumbPath(parsed_args.wad, parsed_args.map))
|
||||
return True
|
||||
|
||||
while not try_screenshot():
|
||||
pass
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue