Ajout de l'option `--export`

This commit is contained in:
Dark-Storm 2018-08-29 23:11:55 +02:00
parent 7bc01cfb39
commit ed595a5a25
Signed by: Darks
GPG Key ID: F61F10FA138E797C
1 changed files with 10 additions and 1 deletions

View File

@ -130,7 +130,7 @@ def generate_code(lines, args):
x, y = x + int(args.offset[0]), y + int(args.offset[1])
xa, ya = xa + int(args.offset[0]), ya + int(args.offset[1])
str_x += "{}, ".format(get_coord(x, xa))
str_y += "{}, ".format(get_coord(y, xb))
str_y += "{}, ".format(get_coord(y, ya))
str_x = str_x[:-2] + "}"
str_y = str_y[:-2] + "}"
@ -164,6 +164,7 @@ if __name__ == "__main__":
parser = ArgumentParser(description='Generate the Multi DrawStat code for an image.')
parser.add_argument('path', type=str, help='path of the image to process')
parser.add_argument('-d', '--draw', action='store_true', help='draw the result into a new file')
parser.add_argument('-e', '--export', nargs=1, help='export the code into <EXPORT>')
parser.add_argument('-f', '--flip', action='store_true', help='flip image vertically (for inverted ViewWindow)')
parser.add_argument('-i', '--info', action='store_true', help='print informative stats')
parser.add_argument('-o', '--offset', nargs=2, default=(0, 0), help='offset for viewwindow. Default: (0, 0)')
@ -208,4 +209,12 @@ if __name__ == "__main__":
if args.info:
print("{} processed in {} lines ({:.3}s)".format(args.path, len(lines), time() - start))
if args.export:
try:
f = open(args.export[0], 'w')
f.write(code)
f.close()
print("Code saved into", args.export[0])
except Exception as e:
print("Error:", str(e))
print(code)