Skip to content
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

Refactor code to use Argparse instead of GetOpt for improved readability + flexibility #43

Open
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

Iridium-IO
Copy link

@Iridium-IO Iridium-IO commented Dec 30, 2023

Argparse

  • Commandline parameters now use argparse() instead of getopt(). 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 old getopt version, the only real difference being that config files are passed into the script using python gcodeplot.py $config.txt instead of python 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, --no prefixes, etc)

Inkscape

  • GCode can now be exported using 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.
  • The layout for the GCodePlot dialog has been improved with better grouping of related variables
  • Extract only one color from drawing now uses the new Color selector in Inkscape instead of passing RGB values as a string

1
3
2

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

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
…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.
- 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant