Skip to content

Commit 911fe81

Browse files
authored
Merge pull request #1 from IridiumIO/argparse
Refactor code to use Argparse instead of GetOpt for improved readability + flexibility
2 parents 9550526 + 5f19c3f commit 911fe81

File tree

7 files changed

+429
-518
lines changed

7 files changed

+429
-518
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
/svgpath/__pycache__/
22
*.pyc
3+
/test
4+
gcodeplot_orig.py

gcodeplot.inx

Lines changed: 50 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,42 @@
66
<dependency type="executable" location="extensions">gcodeplot.py</dependency>
77
<param name="tab" type="notebook">
88
<page name="general" _gui-text="General Settings ">
9-
<param name="tool-mode" type="enum" _gui-text="Tool mode:" _gui-description="In draw mode, tool offset, overcut and inside-out sorting settings are ignored. In cut mode, shading, optimization and direction are always disabled and inside-out sorting is always enabled. In custom mode, one can mix and match these.">
10-
<item value="draw">drawing</item>
11-
<item value="cut">cutting</item>
12-
<item value="custom">custom</item>
9+
<param name="tool-mode" type="optiongroup" _gui-text="Tool mode:" appearance="combo" _gui-description="In draw mode, tool offset, overcut and inside-out sorting settings are ignored. In cut mode, shading, optimization and direction are always disabled and inside-out sorting is always enabled. In custom mode, one can mix and match these.">
10+
<option value="draw">Drawing</item>
11+
<option value="cut">Cutting</item>
12+
<option value="custom">Custom</item>
1313
</param>
1414
<param name="tolerance" type="float" min="0.0001" max="10.0" precision="3" _gui-text="Precision (mm):" _gui-description="Set rendering precision (Default: 0.05)">0.05</param>
15-
<param name="min-x" type="float" min="-1000000" max="1000000" precision="1" _gui-text="Left x-coordinate (mm):" _gui-description="x-coordinate of the print area's left edge (Default: 0)">0</param>
16-
<param name="min-y" type="float" min="-1000000" max="1000000" precision="1" _gui-text="Lower y-coordinate (mm):" _gui-description="y-coordinate of the print area's lower edge (Default: 0)">0</param>
17-
<param name="max-x" type="float" min="-1000000" max="1000000" precision="1" _gui-text="Right x-coordinate (mm):" _gui-description="x-coordinate of the print area's right edge (Default: 200)">200</param>
18-
<param name="max-y" type="float" min="-1000000" max="1000000" precision="1" _gui-text="Upper y-coordinate (mm):" _gui-description="y-coordinate of the print area's upper edge (Default: 200)">200</param>
19-
<param name="work-z" type="float" min="-1000000" max="1000000" precision="2" _gui-text="Work z-coordinate (mm):" _gui-description="z-coordinate for drawing/cutting (Default: 15)">15</param>
20-
<param name="lift-delta-z" type="float" min="-1000000" max="1000000" precision="2" _gui-text="Lift z-height (mm):" _gui-description="height to lift pen/knife for movement (Default: 4)">4</param>
21-
<param name="safe-delta-z" type="float" min="-1000000" max="1000000" precision="1" _gui-text="Parking z-height (mm):" _gui-description="height to lift pen/knife for safe parking (Default: 20)">20</param>
22-
<param name="pen-up-speed" type="float" min="-1000000" max="1000000" precision="1" _gui-text="Movement speed (mm/s):" _gui-description="Speed moving with pen up (Default: 40)">40</param>
23-
<param name="pen-down-speed" type="float" min="-1000000" max="1000000" precision="1" _gui-text="Draw speed (mm/s):" _gui-description="Speed moving with pen down (Default: 35)">35</param>
24-
<param name="z-speed" type="float" min="-1000000" max="1000000" precision="1" _gui-text="Z-speed (mm/s):" _gui-description="Speed moving pen up/down (Default: 5)">5</param>
15+
<separator />
16+
<label appearance="header">Workspace Coordinates (mm)</label>
17+
<hbox>
18+
<label indent="1" >Origin:</label>
19+
<spacer size="expand"/>
20+
<param name="min-x" type="float" min="-1000000" max="1000000" precision="1" _gui-text="X:" _gui-description="x-coordinate of the print area's left edge (Default: 0)">0</param>
21+
<param name="min-y" type="float" min="-1000000" max="1000000" precision="1" _gui-text="Y:" _gui-description="y-coordinate of the print area's lower edge (Default: 0)">0</param>
22+
</hbox>
23+
<hbox>
24+
<label indent="1" >Size:</label>
25+
<spacer size="expand"/>
26+
<param name="max-x" type="float" min="-1000000" max="1000000" precision="1" _gui-text="X:" _gui-description="x-coordinate of the print area's right edge (Default: 200)">200</param>
27+
<param name="max-y" type="float" min="-1000000" max="1000000" precision="1" _gui-text="Y:" _gui-description="y-coordinate of the print area's upper edge (Default: 200)">200</param>
28+
</hbox>
29+
<param name="work-z" type="float" min="-1000000" max="1000000" indent="1" precision="2" _gui-text="Working Z-Height:" _gui-description="z-coordinate for drawing/cutting (Default: 15)">15</param>
30+
<param name="lift-delta-z" type="float" min="-1000000" max="1000000" indent="1" precision="2" _gui-text="Lift Z-height:" _gui-description="height to lift tool for movement (Default: 4)">4</param>
31+
<param name="safe-delta-z" type="float" min="-1000000" max="1000000" indent="1" precision="1" _gui-text="Parking Z-height:" _gui-description="height to lift tool for safe parking (Default: 20)">20</param>
32+
<separator />
33+
<label appearance="header">Working Speed (mm/s)</label>
34+
35+
<param name="pen-up-speed" type="int" min="1" max="500" indent="1" precision="0" appearance="full" _gui-text="Travel Speed:" _gui-description="Speed moving with tool up (Default: 40)">40</param>
36+
<param name="pen-down-speed" type="int" min="1" max="500" indent="1" precision="0" appearance="full" _gui-text="Draw Speed:" _gui-description="Speed moving with tool down (Default: 35)">35</param>
37+
<param name="z-speed" type="int" min="1" max="100" indent="1" precision="0" appearance="full" _gui-text="Z-axis Speed:" _gui-description="Speed moving tool up/down (Default: 5)">5</param>
2538

2639
</page>
2740
<page name="fitting" _gui-text="Fitting and Extracting">
2841
<param name="scale" type="enum" _gui-text="Scaling mode:" _gui-description="Method for scaling to print area (Default: none; should be 'none' if tool-offset option is set in cutter tab)">
29-
<item value="none">none (needed if tool offset&gt;0)</item>
30-
<item value="fit">fit</item>
31-
<item value="down-only">down-only</item>
42+
<item value="n">none (needed if tool offset&gt;0)</item>
43+
<item value="f">fit</item>
44+
<item value="d">down-only</item>
3245
</param>
3346
<param name="align-x" type="enum" _gui-text="Horizontal alignment:" _gui-description="Horizontal alignment of drawing in plotter area">
3447
<item value="none">none</item>
@@ -42,14 +55,19 @@
4255
<item value="center">center</item>
4356
<item value="top">right</item>
4457
</param>
45-
<param name="extract-color" type="string" _gui-text="Extract one color from drawing" _gui-description="Put 'all' or leave blank to include all colors, red=#FF0000, green=#00FF00, blue=#0000FF."></param>
58+
59+
<hbox>
60+
<param name="boolean-extract-color" type="bool" gui-text="Extract only one color from drawing" _gui-description="Uncheck to include all colors; otherwise, choose the color to extract."></param>
61+
<spacer size="expand"/>
62+
<param name="extract-color" type="color" gui-text=" " appearance="colorbutton" _gui-description="The color to extract. Alpha values are discarded"></param>
63+
</hbox>
4664
</page>
4765
<page name="drawing" _gui-text="Drawing Settings">
4866
<param name="shading-threshold" type="float" min="0" max="1" precision="2" _gui-text="Shading threshold:" _gui-description="Shade whenever the shade is below this value, where 0=black and 1=white. To turn off shading, set to 0. (Default: 1, shade everything other than white).">1</param>
4967
<param name="shading-lightest" type="float" min="0" max="1000" precision="1" _gui-text="Lightest shading spacing (mm):" _gui-description="Distance between shading lines for the lightest shaded areas.">3</param>
5068
<param name="shading-darkest" type="float" min="0" max="1000" precision="1" _gui-text="Darkest shading spacing (mm):" _gui-description="Distance between shading lines for the darkest shaded areas.">0.5</param>
5169
<param name="shading-angle" type="float" min="0" max="180" precision="1" _gui-text="Shading angle (degrees)" _gui-description="Angle of shading lines">45</param>
52-
<param name="boolean-shading-crosshatch" type="boolean" _gui-text="Crosshatching" _gui-description="Crosshatching when shading">0</param>
70+
<param name="boolean-shading-crosshatch" type="bool" _gui-text="Crosshatching" _gui-description="Crosshatching when shading">false</param>
5371
<param name="optimization-time" type="int" min="0" max="600" precision="1" _gui-text="Optimization time (sec.):" _gui-description="Maximum amount of time to spend optimizing pen movement (typical is half of it).">60</param>
5472
<param name="direction" type="enum" _gui-text="Preferred drawing direction (degrees):" _gui-description="If specified, the plotter will avoid moving against this direction. Currently not compatible with optimization. (Default: none)">
5573
<item value="none">none</item>
@@ -66,24 +84,26 @@
6684
<page name="cutting" _gui-text="Cutting Settings">
6785
<param name="tool-offset" type="float" min="0" max="1000" precision="2" _gui-text="Tool offset (mm):" _gui-description="Horizontal distance from tool rotation axis to cutting tip (default: 1)">1</param>
6886
<param name="overcut" type="float" min="0" max="1000" precision="2" _gui-text="Overcut (mm):" _gui-description="Extra cut distance for closed curves (default: 1)">1</param>
69-
<param name="boolean-sort" type="boolean" _gui-text="Inside-out sorting" _gui-description="Cut inside curves first">1</param>
87+
<param name="boolean-sort" type="bool" _gui-text="Inside-out sorting" _gui-description="Cut inside curves first">true</param>
7088
<param name="lift-command" type="string" _gui-text="Lift Command" _gui-description="Gcode command to lift the pen/blade"></param>
7189
<param name="down-command" type="string" _gui-text="Down Command" _gui-description="Gcode command to lower the pen/blade"></param>
7290
</page>
7391
<page name="connectionSettings" _gui-text="Connection Settings">
7492

75-
<label>Moonraker API</label>
93+
<label appearance="header">Moonraker API </label>
7694
<spacer/>
77-
<param name="moonraker" type="string" _gui-text="Moonraker URL (leave blank if not used)" _gui-description="Enter the Moonraker API URL here to directly send gcode to your 3D Printer over the network."></param>
78-
<param name="moonraker-filename" type="string" _gui-text="File name" _gui-description="Choose a name for the file to be uploaded.">Inkscape.gcode</param>
95+
<param name="moonraker" type="string" _gui-text="Moonraker URL (leave blank if not used): " _gui-description="Enter the Moonraker API URL here to directly send gcode to your 3D Printer over the network."></param>
96+
<param name="moonraker-filename" type="string" _gui-text="File name: " _gui-description="Choose a name for the file to be uploaded.">Inkscape.gcode</param>
97+
98+
<spacer/>
7999
<param name="moonraker-autoprint" type="bool" _gui-text="Start job automatically after upload" _gui-description="Automatically starts running the gcode once the file is saved">false</param>
80100
<spacer/>
81101
<separator/>
82102
<spacer/>
83-
<label>Serial Configuration</label>
103+
<label appearance="header">Serial Configuration</label>
84104
<spacer/>
85-
<param name="send-and-save" type="string" _gui-text="Serial Port (leave blank if not used)" _gui-description="If you enter the name of your serial port here (e.g., COM4), then you can directly send the file to your device."></param>
86-
<param name="send-speed" type="enum" _gui-text="Serial baud rate:" _gui-description="Baud rate of your serial device (Default: 115200)">
105+
<param name="send-and-save" type="string" _gui-text="Serial Port (leave blank if not used): " _gui-description="If you enter the name of your serial port here (e.g., COM4), then you can directly send the file to your device."></param>
106+
<param name="send-speed" type="enum" _gui-text="Serial baud rate: " _gui-description="Baud rate of your serial device (Default: 115200)">
87107
<item value="115200">115200</item>
88108
<item value="300">300</item>
89109
<item value="600">600</item>
@@ -102,14 +122,14 @@
102122

103123
</page>
104124
</param>
105-
<output>
125+
<output is_exported='true'>
106126
<extension>.gcode</extension>
107127
<mimetype>text/plain</mimetype>
108-
<filetypename>3-axis gcode plotter (*.gcode)</filetypename>
109-
<filetypetooltip>Export 3-axis gcode plotter file</filetypetooltip>
128+
<filetypename>G-Code (*.gcode)</filetypename>
129+
<filetypetooltip>Export 3-axis G-code plotter file</filetypetooltip>
110130
<dataloss>true</dataloss>
111131
</output>
112132
<script>
113133
<command reldir="extensions" interpreter="python">gcodeplot.py</command>
114134
</script>
115-
</inkscape-extension>
135+
</inkscape-extension>

0 commit comments

Comments
 (0)