Refactor code to use Argparse instead of GetOpt for improved readability + flexibility
Argparse
- Commandline parameters now use
argparse()instead ofgetopt(). This reduces the need to provide separate help/default/variable assignments and makes it easier to manage new parameters. This change is almost entirely feature-equal to the oldgetoptversion, the only real difference being that config files are passed into the script usingpython gcodeplot.py $config.txtinstead ofpython gcodeplot.py --config-file config.txt. - Custom argparse definitions and functions have been allocated to
gcodeplotutils/argparse_c. This mainly has custom extensions to handle features requires for parity with the old system (comments in config files,--noprefixes, etc)
Inkscape
- GCode can now be exported using
File > Exportin Inkscape. This allows you to keep a degree of separation between the SVG and exported GCode (plus it's fewer clicks when rapidly testing, as you can keep the Export window open in a tab. Saving normally still works as expected. - The layout for the GCodePlot dialog has been improved with better grouping of related variables
Extract only one color from drawingnow uses the newColorselector in Inkscape instead of passing RGB values as a string
General
- Simplified
__main__to reduce nesting and make code easier to read - Added comments to
__main__describing different sections
Note This PR also includes the changes from #42 adding Moonraker support. Sorry, I didn't quite know how to separate the changes without deleting all the Moonraker stuff, creating this PR, then re-adding the Moonraker stuff. I don't want to clog up your repo with changes and un-changes, but if you're more happy with this PR (as it's more testable since you don't have Moonraker), I can do the following steps:
- Remove Moonraker support from within this branch (IridiumIO/GcodePlot/argparse) which will automatically update this PR
- Merge this PR into your base repository if accepted
- Pull these changes into the Moonraker PR which can then sit open until someone else tests it.
Thoughts? I've tested the generated GCode using my own tests (complex overlapped shapes with variable shading/cutting) as well as running the included mpcnc and cutter config files to check that the output gcode is identical. There is some variation in both the new and old files due to non-deterministic choosing of which shapes to draw first (e.g. one time it will draw star > circle > square then the next time you run the script it will draw circle > star > square