G-CODE Editor: CNC Programming Assistant
G-CODE Editor is a PyQt5 desktop app that turns stitch routes into G-code for a CNC sewing machine, with bartacking, needle moves and speed ramps.

G-CODE Editor builds complete programs for a CNC sewing machine. A route file is a list of X and Y stitch points, and the machine needs much more around them: start-up and shutdown code, a header for every seam, a needle-down and needle-up move on every stitch, a thread-cut sequence after each seam, and a feed rate. Operators rarely write that byte by byte. This application gives each part a proper interface and produces the final G-CODE from the configured values, which removes a class of typing mistakes that show up as scrap.
From route files to a program:
- Load File reads every .nc file in the routes folder, in file-name order, and keeps only the X and Y coordinate lines
- Generate G-Code writes the start block once. Each route gets a numbered comment, G01 G90 on the first route only, a move to its first point, M114 and a G04 P200 dwell, then every remaining point as a stitch: the coordinate with the needle-down Z, followed by the needle-up Z. Every coordinate is shifted by the calibration offset
- The thread-cut block follows each route, and the end block closes the program
- Save File writes whatever is in the output pane to the gcode_output folder under a timestamped name, so a last manual edit is kept and nothing is overwritten
Sewing controls:
- Needle positions: needle down and needle up, Z3 and Z30 by default, written into every stitch
- Bartacking: labelled Punteriz, with separate counts for the start and end of a seam: the needle goes back and forth that many times between the first two stitch points, or the last two
- Upper thread tension bobbin: when enabled, M118 before the first needle-down and M119 after the needle-down or the needle-up, per the Reset After Lines setting
- Sewing speed: start speed, maximum speed and increment, as F values. Each seam speeds up by one increment per stitch to the maximum, holds it, and slows down over the same number of stitches before the end. The F word is written only when the speed changes, and a start above the maximum is rejected up front
- Calibration: X and Y offsets, rounded to two decimals, as is every coordinate
With the defaults of 10000, 50000 and 5000, the sample program in the repository climbs from F10000 to F50000 over the first nine stitches of the first seam.
Parameter blocks: The start, route start, thread-cut and end blocks are plain G-code, one command per line, each in its own text area. Generating a program saves them to parameters.json with the needle positions and calibration, and Reset Parameters reloads them. The default thread-cut block alone is thirty commands of M-codes, G04 dwells and a short relative Z move. Speed, bartack and bobbin settings are not stored and start from their defaults each session.
Interface: A PyQt5 window split in two: parameters on the left, the output on the right in a monospaced editor with wrapping off and a live line count. Turkish is the default and English is one menu click away, with every label changing in place.
Structure: Model-View-Controller: GCodeProcessor holds the calibration, speed and bartacking rules, MultiRouteProcessor assembles the routes, and one controller connects the view to the model. The only dependency is PyQt5 5.15.9. The repository ships three sample routes and a generated program, so the flow can be tried without a machine.
How it came together: Between 10 and 14 January 2025 the generator gained its pieces one at a time: the needle moves, the thread-cut and end blocks, calibration, the M118 and M119 rule, bartacking and sewing speed. In March 2025 it was restructured into MVC and made bilingual.
Where it fits: Preparing programs for a CNC sewing line, refining G-CODE before it runs, trying out route-based sequences, and as the operator-facing software on a control panel next to the machine.

