diff options
| author | Kaalleen <36401965+kaalleen@users.noreply.github.com> | 2022-06-24 17:11:52 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-06-24 17:11:52 +0200 |
| commit | ab8c87928b39e7874c09a75b2f9badd3a46719b2 (patch) | |
| tree | 11a934b028f8a5dab34e4710d43ab895e0510fbb /lib/extensions/apply_threadlist.py | |
| parent | 3985b5ac719cb699b1539bce0bc7376970702b4d (diff) | |
Update pyembroidery (#1683)
Embroidery formats (read)
.hus: Husqvarna Embroidery Format
.zhs: Zeng Hsing Embroidery Format
Color formats (read & write)
.col : Color format.
.edr : Color format.
.inf : Color format.
Stitch formats (read & write)
.pmv : Brother Stitch Format.
Image (write)
.png : Portable Network Graphic (line art)
G-Code
The export file format is not .txt anymore but .gcode
Bug fixes
Diffstat (limited to 'lib/extensions/apply_threadlist.py')
| -rw-r--r-- | lib/extensions/apply_threadlist.py | 47 |
1 files changed, 33 insertions, 14 deletions
diff --git a/lib/extensions/apply_threadlist.py b/lib/extensions/apply_threadlist.py index 31861513..2779a901 100644 --- a/lib/extensions/apply_threadlist.py +++ b/lib/extensions/apply_threadlist.py @@ -8,6 +8,7 @@ import re import sys import inkex +import pyembroidery from ..i18n import _ from ..threads import ThreadCatalog @@ -22,6 +23,8 @@ class ApplyThreadlist(InkstitchExtension): ''' def __init__(self, *args, **kwargs): InkstitchExtension.__init__(self, *args, **kwargs) + self.arg_parser.add_argument("-o", "--options", type=str, default=None, dest="page_1") + self.arg_parser.add_argument("-i", "--info", type=str, default=None, dest="page_2") self.arg_parser.add_argument("-f", "--filepath", type=str, default="", dest="filepath") self.arg_parser.add_argument("-m", "--method", type=int, default=1, dest="method") self.arg_parser.add_argument("-t", "--palette", type=str, default=None, dest="palette") @@ -34,26 +37,18 @@ class ApplyThreadlist(InkstitchExtension): return path = self.options.filepath - if not os.path.exists(path): - inkex.errormsg(_("File not found.")) - sys.exit(1) - if os.path.isdir(path): - inkex.errormsg(_("The filepath specified is not a file but a dictionary.\nPlease choose a threadlist file to import.")) - sys.exit(1) + self.verify_path(path) method = self.options.method - if method == 1: + + if path.endswith(('col', 'inf', 'edr')): + colors = self.parse_color_format(path) + elif method == 1: colors = self.parse_inkstitch_threadlist(path) else: colors = self.parse_threadlist_by_catalog_number(path) - if all(c is None for c in colors): - inkex.errormsg(_("Couldn't find any matching colors in the file.")) - if method == 1: - inkex.errormsg(_('Please try to import as "other threadlist" and specify a color palette below.')) - else: - inkex.errormsg(_("Please chose an other color palette for your design.")) - sys.exit(1) + self.verify_colors(colors, method) # Iterate through the color blocks to apply colors element_color = "" @@ -70,6 +65,23 @@ class ApplyThreadlist(InkstitchExtension): style = element.node.get('style').replace("%s" % element_color, "%s" % colors[i]) element.node.set('style', style) + def verify_path(self, path): + if not os.path.exists(path): + inkex.errormsg(_("File not found.")) + sys.exit(1) + if os.path.isdir(path): + inkex.errormsg(_("The filepath specified is not a file but a dictionary.\nPlease choose a threadlist file to import.")) + sys.exit(1) + + def verify_colors(self, colors, method): + if all(c is None for c in colors): + inkex.errormsg(_("Couldn't find any matching colors in the file.")) + if method == 1: + inkex.errormsg(_('Please try to import as "other threadlist" and specify a color palette below.')) + else: + inkex.errormsg(_("Please chose an other color palette for your design.")) + sys.exit(1) + def parse_inkstitch_threadlist(self, path): colors = [] with open(path) as threadlist: @@ -83,6 +95,13 @@ class ApplyThreadlist(InkstitchExtension): colors.append(None) return colors + def parse_color_format(self, path): + colors = [] + threads = pyembroidery.read(path).threadlist + for color in threads: + colors.append(color.hex_color()) + return colors + def parse_threadlist_by_catalog_number(self, path): palette_name = self.options.palette palette = ThreadCatalog().get_palette_by_name(palette_name) |
