-
Notifications
You must be signed in to change notification settings - Fork 66
Refactor code to use Argparse instead of GetOpt for improved readability + flexibility #43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Added Moonraker config, and separated connection settings (Moonraker, Serial) to its own tab
GCode can be uploaded via Moonraker (e.g. to Klipper). Currently does not have authentication support.
…tion - Removes manual "help" and "default" console commands and uses argparse generators instead. - config files are now passed directly into the command line by using a '$' prefix, e.g. gcodeplot.py $config.txt - most '--no' prefixes are now reduntant. Some are still retained but I don't really know why they were needed in the first place. Renamed some arguments to be clearer in this regard. - Add type hinting for some parameters Issues: - for some reason the 'cut' mode doesn't generate the exact same ordering of overlapping cuts anymore. All cuts still execute correctly, just the order of shapes being cut is different. To be investigated.
…tantly having to use "Save As" Updated layout of Inkscape config menu. - Added separators and groups to collect similar settings together visually - Now uses type="color" for the extract-color option, allowing visual picking of a color instead of typing in a string.
- Separated svgTree parsing
…ape as uint32 numbers.
…ction angle values. Now accepts "none" at the commandline again - possible that this was causing the variation in the order that shapes were being cut when using 'cut' mode.
Clean up imports
- Cleanup unecessary arguments and enable input parity with old "--no" prefixes - Create enums.py so that argparser_c.py can use it too. - Tidy up __main__ section
- Cleanup unecessary arguments and enable input parity with old "--no" prefixes - Create enums.py so that argparser_c.py can use it too. - Tidy up __main__ section
- Optimization time was broken due to using false-y boolean check rather than properly checking for True/False values
I would love to merge everything other than the argparse, because the change in config file usage could break somebody's shell script. |
I'll see if I can figure out how to keep it consistent so old scripts work too :) I probably should've use optparse instead of argparse, but I didn't even know that existed at the time |
…g the old getopt() style - If both command-line parameters and a config file are used, the command-line parameters will overwrite ones from the config file
@arpruss okay the old way of using config files should work again now, I've tested using the included mpcnc files and they work. I did make one small change, though: command-line arguments now always override values in the config file, regardless of the order they're provided. Previously, the behavior depended on the order the Given a config file: pen-down-speed=5 Old outcome: gcodeplot.py --pen-down-speed 10 --config-file cfg
>> pen-down-speed = 5
gcodeplot.py --config-file cfg --pen-down-speed 10
>> pen-down-speed = 10 New outcome: gcodeplot.py --pen-down-speed 10 --config-file cfg
>> pen-down-speed = 10
gcodeplot.py --config-file cfg --pen-down-speed 10
>> pen-down-speed = 10 This probably won't matter for most users (since mixing config files and CLI args probably isn't common), but I think it's more intuitive: if someone explicitly passes an argument on the command line, it should take precedence over the config file. |
Argparse
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 feature-equal to the oldgetopt
version, the only real difference being that command-line arguments now always override config-file argumentsgcodeplotutils/argparse_c
. This mainly has custom extensions to handle features requires for parity with the old system (comments in config files,--no
prefixes, etc)Inkscape
File > Export
in 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.Extract only one color from drawing
now uses the newColor
selector in Inkscape instead of passing RGB values as a stringGeneral
__main__
to reduce nesting and make code easier to read__main__
describing different sectionsNote
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:
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
andcutter
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 drawstar > circle > square
then the next time you run the script it will drawcircle > star > square