diff --git a/gui.py b/gui.py new file mode 100644 index 0000000..bf2ee2f --- /dev/null +++ b/gui.py @@ -0,0 +1,43 @@ +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() diff --git a/req-gooey.txt b/req-gooey.txt new file mode 100644 index 0000000..06e5b6e --- /dev/null +++ b/req-gooey.txt @@ -0,0 +1,2 @@ +gooey==1.0.3 +wxPython==4.0.7.post2