schemagen/gui.py
2021-09-30 15:12:04 +08:00

43 lines
1.8 KiB
Python

from schemgen import assemble_nbtfile, read_text, read_imtuple
import gzip
from gooey import Gooey, GooeyParser, python_bindings, util
def apply_default_rewrites(spec):
getin = util.functional.getin
top_level_subgroups = list(spec['widgets'].keys())
for subgroup in top_level_subgroups:
path = ['widgets', subgroup, 'contents']
contents = getin(spec, path)
for group in contents:
if group['name'] == 'optional arguments':
group['name'] = 'Settings'
return spec
python_bindings.argparse_to_json.apply_default_rewrites = apply_default_rewrites
@Gooey(program_name="schemgen", navigation="TABBED", optional_cols=2, show_restart_button=False, advanced=True)
def main():
import argparse
parser = GooeyParser(description='schemgen')
s = parser.add_subparsers(help='', dest='')
g1 = s.add_parser("text")
g2 = s.add_parser("image")
g1.add_argument('-o', '--output', default='output.schem', help='output worldedit schema file', widget="FileSaver")
g2.add_argument('-o', '--output', default='output.schem', help='output worldedit schema file', widget="FileSaver")
g2.add_argument('-i', '--input', type=str, default="input.png", help='input image', widget="FileChooser")
g1.add_argument('-t', '--text', type=str, default="", help='input text')
g2.add_argument('-p', '--palette', type=str, default="minecraft.gpl", help='gimp palette file', widget="FileChooser")
args = parser.parse_args()
if getattr(args, 'text', None) is not None:
assert args.text
nbt = assemble_nbtfile(*read_text(args.text))
else:
nbt = assemble_nbtfile(*read_imtuple(args.input, args.palette))
print(nbt.pretty())
with gzip.open(args.output, 'w') as f:
nbt.save(f)
if __name__ == "__main__":
main()