summaryrefslogtreecommitdiff
path: root/lib/extensions/zip.py
diff options
context:
space:
mode:
authorKaalleen <36401965+kaalleen@users.noreply.github.com>2021-03-04 18:40:53 +0100
committerGitHub <noreply@github.com>2021-03-04 18:40:53 +0100
commite84a86d4ac0caf29d6074728376ff0a594243fec (patch)
tree888c79ed0094ba2916a1d329861a85515959913c /lib/extensions/zip.py
parentb39575a50191307b3b56eab6455626398eec6397 (diff)
Update for Inkscape 1.0 (#880)
* update for inkscape 1.0 * add about extension * Build improvements for the inkscape1.0 branch (#985) * zip: export real svg not stitch plan * #411 and #726 * Tools for Font Creators (#1018) * ignore very small holes in fills * remove embroider (#1026) * auto_fill: ignore shrink_or_grow if result is empty (#589) * break apart: do not ignore small fills Co-authored-by: Hagen Fritsch <rumpeltux-github@irgendwo.org> Co-authored-by: Lex Neva <github.com@lexneva.name>
Diffstat (limited to 'lib/extensions/zip.py')
-rw-r--r--lib/extensions/zip.py34
1 files changed, 17 insertions, 17 deletions
diff --git a/lib/extensions/zip.py b/lib/extensions/zip.py
index aebff331..fedf8c65 100644
--- a/lib/extensions/zip.py
+++ b/lib/extensions/zip.py
@@ -1,36 +1,34 @@
import os
import sys
import tempfile
+from copy import deepcopy
from zipfile import ZipFile
-import inkex
+from inkex import Boolean
+from lxml import etree
+
import pyembroidery
from ..i18n import _
from ..output import write_embroidery_file
from ..stitch_plan import patches_to_stitch_plan
-from ..svg import PIXELS_PER_MM
-from .base import InkstitchExtension
from ..threads import ThreadCatalog
+from .base import InkstitchExtension
class Zip(InkstitchExtension):
def __init__(self, *args, **kwargs):
InkstitchExtension.__init__(self)
- self.OptionParser.add_option("-c", "--collapse_len_mm",
- action="store", type="float",
- dest="collapse_length_mm", default=3.0,
- help="max collapse length (mm)")
# it's kind of obnoxious that I have to do this...
self.formats = []
for format in pyembroidery.supported_formats():
if 'writer' in format and format['category'] == 'embroidery':
extension = format['extension']
- self.OptionParser.add_option('--format-%s' % extension, type="inkbool", dest=extension)
+ self.arg_parser.add_argument('--format-%s' % extension, type=Boolean, dest=extension)
self.formats.append(extension)
- self.OptionParser.add_option('--format-svg', type="inkbool", dest='svg')
- self.OptionParser.add_option('--format-threadlist', type="inkbool", dest='threadlist')
+ self.arg_parser.add_argument('--format-svg', type=Boolean, dest='svg')
+ self.arg_parser.add_argument('--format-threadlist', type=Boolean, dest='threadlist')
self.formats.append('svg')
self.formats.append('threadlist')
@@ -38,8 +36,10 @@ class Zip(InkstitchExtension):
if not self.get_elements():
return
+ self.metadata = self.get_inkstitch_metadata()
+ collapse_len = self.metadata['collapse_len_mm']
patches = self.elements_to_patches(self.elements)
- stitch_plan = patches_to_stitch_plan(patches, self.options.collapse_length_mm * PIXELS_PER_MM)
+ stitch_plan = patches_to_stitch_plan(patches, collapse_len=collapse_len)
base_file_name = self.get_base_file_name()
path = tempfile.mkdtemp()
@@ -50,10 +50,10 @@ class Zip(InkstitchExtension):
if getattr(self.options, format):
output_file = os.path.join(path, "%s.%s" % (base_file_name, format))
if format == 'svg':
- output = open(output_file, 'w')
- output.write(inkex.etree.tostring(self.document.getroot()))
- output.close()
- if format == 'threadlist':
+ document = deepcopy(self.document.getroot())
+ with open(output_file, 'w', encoding='utf-8') as svg:
+ svg.write(etree.tostring(document).decode('utf-8'))
+ elif format == 'threadlist':
output_file = os.path.join(path, "%s_%s.txt" % (base_file_name, _("threadlist")))
output = open(output_file, 'w')
output.write(self.get_threadlist(stitch_plan, base_file_name))
@@ -76,8 +76,8 @@ class Zip(InkstitchExtension):
# inkscape will read the file contents from stdout and copy
# to the destination file that the user chose
- with open(temp_file.name) as output_file:
- sys.stdout.write(output_file.read())
+ with open(temp_file.name, 'rb') as output_file:
+ sys.stdout.buffer.write(output_file.read())
os.remove(temp_file.name)
for file in files: