From a2e5aea0e0de7d6ef299c21f70d25b6b5222f14a Mon Sep 17 00:00:00 2001 From: mattmcw Date: Tue, 26 Dec 2023 15:10:15 -0500 Subject: [PATCH] Argparse WIP --- axi/main.py | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/axi/main.py b/axi/main.py index 85d8cd6..b2e56c4 100644 --- a/axi/main.py +++ b/axi/main.py @@ -7,7 +7,7 @@ TODO: axi (repl) ''' -def main(): +def main_old(): args = sys.argv[1:] if len(args) == 0: return @@ -45,5 +45,42 @@ def main(): else: pass +def main() : + parser = argparse.ArgumentParser(description='Command line utility for interacting with axidraw') + parser.add_argument('command', type=str.lower, help='Command for the axidraw') + + args = parser.parse_args() + if command == 'render': + d = axi.Drawing.load(args[0]) + d = d.rotate_and_scale_to_fit(12, 8.5, step=90) + path = args[1] if len(args) > 1 else 'out.png' + im = d.render() + im.write_to_png(path) + return + device = axi.Device() + if command == 'zero': + device.zero_position() + elif command == 'home': + device.home() + elif command == 'up': + device.pen_up() + elif command == 'down': + device.pen_down() + elif command == 'on': + device.enable_motors() + elif command == 'off': + device.disable_motors() + elif command == 'move': + dx, dy = map(float, args) + device.move(dx, dy) + elif command == 'goto': + x, y = map(float, args) + device.goto(x, y) + elif command == 'draw': + d = axi.Drawing.load(args[0]) + axi.draw(d) + else: + pass + if __name__ == '__main__': main()