summaryrefslogtreecommitdiff
path: root/lib/extensions
diff options
context:
space:
mode:
Diffstat (limited to 'lib/extensions')
-rw-r--r--lib/extensions/__init__.py15
-rw-r--r--lib/extensions/base.py23
-rw-r--r--lib/extensions/commands.py1
-rw-r--r--lib/extensions/convert_to_satin.py28
-rw-r--r--lib/extensions/embroider.py3
-rw-r--r--lib/extensions/flip.py2
-rw-r--r--lib/extensions/global_commands.py12
-rw-r--r--lib/extensions/input.py17
-rw-r--r--lib/extensions/install.py31
-rw-r--r--lib/extensions/layer_commands.py30
-rw-r--r--lib/extensions/object_commands.py65
-rw-r--r--lib/extensions/output.py7
-rw-r--r--lib/extensions/print_pdf.py97
-rw-r--r--lib/extensions/zip.py5
14 files changed, 180 insertions, 156 deletions
diff --git a/lib/extensions/__init__.py b/lib/extensions/__init__.py
index 6c8db318..5b72ecb3 100644
--- a/lib/extensions/__init__.py
+++ b/lib/extensions/__init__.py
@@ -9,4 +9,19 @@ from zip import Zip
from flip import Flip
from object_commands import ObjectCommands
from layer_commands import LayerCommands
+from global_commands import GlobalCommands
from convert_to_satin import ConvertToSatin
+
+__all__ = extensions = [Embroider,
+ Install,
+ Params,
+ Print,
+ Simulate,
+ Input,
+ Output,
+ Zip,
+ Flip,
+ ObjectCommands,
+ LayerCommands,
+ GlobalCommands,
+ ConvertToSatin]
diff --git a/lib/extensions/base.py b/lib/extensions/base.py
index 571e3c2d..25de441f 100644
--- a/lib/extensions/base.py
+++ b/lib/extensions/base.py
@@ -3,11 +3,12 @@ import re
import json
from copy import deepcopy
from collections import MutableMapping
+from stringcase import snakecase
-from ..svg.tags import *
+from ..svg.tags import SVG_GROUP_TAG, INKSCAPE_GROUPMODE, SVG_DEFS_TAG, EMBROIDERABLE_TAGS, SVG_POLYLINE_TAG
from ..elements import AutoFill, Fill, Stroke, SatinColumn, Polyline, EmbroideryElement
-from ..utils import cache
from ..commands import is_command, layer_commands
+from ..i18n import _
SVG_METADATA_TAG = inkex.addNS("metadata", "svg")
@@ -98,17 +99,21 @@ class InkStitchMetadata(MutableMapping):
class InkstitchExtension(inkex.Effect):
"""Base class for Inkstitch extensions. Not intended for direct use."""
+ @classmethod
+ def name(cls):
+ return snakecase(cls.__name__)
+
def hide_all_layers(self):
for g in self.document.getroot().findall(SVG_GROUP_TAG):
if g.get(INKSCAPE_GROUPMODE) == "layer":
g.set("style", "display:none")
def no_elements_error(self):
- if self.selected:
- inkex.errormsg(_("No embroiderable paths selected."))
- else:
- inkex.errormsg(_("No embroiderable paths found in document."))
- inkex.errormsg(_("Tip: use Path -> Object to Path to convert non-paths."))
+ if self.selected:
+ inkex.errormsg(_("No embroiderable paths selected."))
+ else:
+ inkex.errormsg(_("No embroiderable paths found in document."))
+ inkex.errormsg(_("Tip: use Path -> Object to Path to convert non-paths."))
def descendants(self, node, selected=False):
nodes = []
@@ -118,7 +123,7 @@ class InkstitchExtension(inkex.Effect):
return []
if node.tag == SVG_GROUP_TAG and node.get(INKSCAPE_GROUPMODE) == "layer":
- if layer_commands(node, "ignore_layer"):
+ if len(list(layer_commands(node, "ignore_layer"))):
return []
if element.has_style('display') and element.get_style('display') is None:
@@ -171,7 +176,6 @@ class InkstitchExtension(inkex.Effect):
return classes
-
def get_elements(self):
self.elements = []
for node in self.get_nodes():
@@ -207,7 +211,6 @@ class InkstitchExtension(inkex.Effect):
return svg_filename
-
def parse(self):
"""Override inkex.Effect to add Ink/Stitch xml namespace"""
diff --git a/lib/extensions/commands.py b/lib/extensions/commands.py
index e3bfabfe..fb6f7874 100644
--- a/lib/extensions/commands.py
+++ b/lib/extensions/commands.py
@@ -1,5 +1,4 @@
import os
-import sys
import inkex
from copy import deepcopy
diff --git a/lib/extensions/convert_to_satin.py b/lib/extensions/convert_to_satin.py
index dd5a9bc2..ef4ac557 100644
--- a/lib/extensions/convert_to_satin.py
+++ b/lib/extensions/convert_to_satin.py
@@ -11,6 +11,7 @@ from ..svg.tags import SVG_PATH_TAG
from ..svg import get_correction_transform, PIXELS_PER_MM
from ..elements import Stroke
from ..utils import Point
+from ..i18n import _
class SelfIntersectionError(Exception):
@@ -51,7 +52,9 @@ class ConvertToSatin(InkstitchExtension):
try:
rails, rungs = self.path_to_satin(path, element.stroke_width, style_args)
except SelfIntersectionError:
- inkex.errormsg(_("Cannot convert %s to a satin column because it intersects itself. Try breaking it up into multiple paths.") % element.node.get('id'))
+ inkex.errormsg(
+ _("Cannot convert %s to a satin column because it intersects itself. Try breaking it up into multiple paths.") %
+ element.node.get('id'))
# revert any changes we've made
self.document = deepcopy(self.original_document)
@@ -84,7 +87,7 @@ class ConvertToSatin(InkstitchExtension):
"""Convert svg line join style to shapely parallel offset arguments."""
args = {
- 'join_style': shgeo.JOIN_STYLE.round
+ 'join_style': shgeo.JOIN_STYLE.round
}
element_join_style = element.get_style('stroke-linejoin')
@@ -113,7 +116,7 @@ class ConvertToSatin(InkstitchExtension):
# path intersects itself, when taking its stroke width into consideration. See
# the last example for parallel_offset() in the Shapely documentation:
# https://shapely.readthedocs.io/en/latest/manual.html#object.parallel_offset
- raise SelfIntersectionError()
+ raise SelfIntersectionError()
# for whatever reason, shapely returns a right-side offset's coordinates in reverse
left_rail = list(left_rail.coords)
@@ -244,7 +247,7 @@ class ConvertToSatin(InkstitchExtension):
# millimeters before this one.
if last_rung_center is not None and \
(rung_center - last_rung_center).length() < 2 * PIXELS_PER_MM:
- continue
+ continue
else:
last_rung_center = rung_center
@@ -269,7 +272,6 @@ class ConvertToSatin(InkstitchExtension):
return rungs
-
def satin_to_svg_node(self, rails, rungs, correction_transform):
d = ""
for path in chain(rails, rungs):
@@ -279,11 +281,11 @@ class ConvertToSatin(InkstitchExtension):
d += " "
return inkex.etree.Element(SVG_PATH_TAG,
- {
- "id": self.uniqueId("path"),
- "style": "stroke:#000000;stroke-width:1px;fill:none",
- "transform": correction_transform,
- "d": d,
- "embroider_satin_column": "true",
- }
- )
+ {
+ "id": self.uniqueId("path"),
+ "style": "stroke:#000000;stroke-width:1px;fill:none",
+ "transform": correction_transform,
+ "d": d,
+ "embroider_satin_column": "true",
+ }
+ )
diff --git a/lib/extensions/embroider.py b/lib/extensions/embroider.py
index 1e994e27..921201d6 100644
--- a/lib/extensions/embroider.py
+++ b/lib/extensions/embroider.py
@@ -1,7 +1,4 @@
-import sys
-import traceback
import os
-import inkex
from .base import InkstitchExtension
from ..i18n import _
diff --git a/lib/extensions/flip.py b/lib/extensions/flip.py
index d8d78cb5..65dbdc1f 100644
--- a/lib/extensions/flip.py
+++ b/lib/extensions/flip.py
@@ -1,4 +1,3 @@
-import sys
import inkex
import cubicsuperpath
from shapely import geometry as shgeo
@@ -7,6 +6,7 @@ from .base import InkstitchExtension
from ..i18n import _
from ..elements import SatinColumn
+
class Flip(InkstitchExtension):
def subpath_to_linestring(self, subpath):
return shgeo.LineString()
diff --git a/lib/extensions/global_commands.py b/lib/extensions/global_commands.py
new file mode 100644
index 00000000..9655c7af
--- /dev/null
+++ b/lib/extensions/global_commands.py
@@ -0,0 +1,12 @@
+from .layer_commands import LayerCommands
+from ..commands import GLOBAL_COMMANDS
+
+
+# It's a bit weird subclassing this from LayerCommands, but global commands
+# must still be placed in a layer. That means the two extensions
+# do the same thing and the code is the same. We keep this as separate
+# extensions because we want the user to understand that global commands
+# affect the entire document, not just the current layer.
+
+class GlobalCommands(LayerCommands):
+ COMMANDS = GLOBAL_COMMANDS
diff --git a/lib/extensions/input.py b/lib/extensions/input.py
index cb5ac452..975ba838 100644
--- a/lib/extensions/input.py
+++ b/lib/extensions/input.py
@@ -1,15 +1,11 @@
import os
-from os.path import realpath, dirname, join as path_join
-import sys
from inkex import etree
import inkex
import pyembroidery
from ..svg import PIXELS_PER_MM, render_stitch_plan
from ..svg.tags import INKSCAPE_LABEL
-from ..i18n import _
-from ..stitch_plan import StitchPlan, ColorBlock
-from ..utils.io import save_stdout
+from ..stitch_plan import StitchPlan
class Input(object):
@@ -28,12 +24,11 @@ class Input(object):
trim=(command == pyembroidery.TRIM))
extents = stitch_plan.extents
- svg = etree.Element("svg", nsmap=inkex.NSS, attrib=
- {
- "width": str(extents[0] * 2),
- "height": str(extents[1] * 2),
- "viewBox": "0 0 %s %s" % (extents[0] * 2, extents[1] * 2),
- })
+ svg = etree.Element("svg", nsmap=inkex.NSS, attrib={
+ "width": str(extents[0] * 2),
+ "height": str(extents[1] * 2),
+ "viewBox": "0 0 %s %s" % (extents[0] * 2, extents[1] * 2),
+ })
render_stitch_plan(svg, stitch_plan)
# rename the Stitch Plan layer so that it doesn't get overwritten by Embroider
diff --git a/lib/extensions/install.py b/lib/extensions/install.py
index 42a92113..6c179beb 100644
--- a/lib/extensions/install.py
+++ b/lib/extensions/install.py
@@ -3,17 +3,12 @@
import sys
import traceback
import os
-from os.path import realpath, dirname
from glob import glob
-from threading import Thread
-import socket
-import errno
-import time
-import logging
import wx
import inkex
from ..utils import guess_inkscape_config_path, get_bundled_dir
+from ..i18n import _
class InstallerFrame(wx.Frame):
@@ -27,23 +22,24 @@ class InstallerFrame(wx.Frame):
text_sizer = wx.BoxSizer(wx.HORIZONTAL)
- text = _('Ink/Stitch can install files ("add-ons") that make it easier to use Inkscape to create machine embroidery designs. These add-ons will be installed:') + \
- "\n\n • " + _("thread manufacturer color palettes") + \
- "\n • " + _("Ink/Stitch visual commands (Object -> Symbols...)")
+ text = (_('Ink/Stitch can install files ("add-ons") that make it easier to use Inkscape to create machine embroidery designs. '
+ 'These add-ons will be installed:') +
+ "\n\n • " + _("thread manufacturer color palettes") +
+ "\n • " + _("Ink/Stitch visual commands (Object -> Symbols...)"))
static_text = wx.StaticText(panel, label=text)
font = wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.NORMAL)
static_text.SetFont(font)
- text_sizer.Add(static_text, proportion=0, flag=wx.ALL|wx.EXPAND, border=10)
- sizer.Add(text_sizer, proportion=3, flag=wx.ALL|wx.EXPAND, border=0)
+ text_sizer.Add(static_text, proportion=0, flag=wx.ALL | wx.EXPAND, border=10)
+ sizer.Add(text_sizer, proportion=3, flag=wx.ALL | wx.EXPAND, border=0)
buttons_sizer = wx.BoxSizer(wx.HORIZONTAL)
install_button = wx.Button(panel, wx.ID_ANY, _("Install"))
install_button.SetBitmap(wx.ArtProvider.GetBitmap(wx.ART_TICK_MARK))
- buttons_sizer.Add(install_button, proportion=0, flag=wx.ALIGN_RIGHT|wx.ALL, border=5)
+ buttons_sizer.Add(install_button, proportion=0, flag=wx.ALIGN_RIGHT | wx.ALL, border=5)
cancel_button = wx.Button(panel, wx.ID_CANCEL, _("Cancel"))
- buttons_sizer.Add(cancel_button, proportion=0, flag=wx.ALIGN_RIGHT|wx.ALL, border=5)
- sizer.Add(buttons_sizer, proportion=1, flag=wx.ALIGN_RIGHT|wx.ALIGN_BOTTOM)
+ buttons_sizer.Add(cancel_button, proportion=0, flag=wx.ALIGN_RIGHT | wx.ALL, border=5)
+ sizer.Add(buttons_sizer, proportion=1, flag=wx.ALIGN_RIGHT | wx.ALIGN_BOTTOM)
panel.SetSizer(sizer)
panel.Layout()
@@ -63,7 +59,7 @@ class InstallerFrame(wx.Frame):
try:
self.install_addons('palettes')
self.install_addons('symbols')
- except Exception, e:
+ except Exception:
wx.MessageDialog(self,
_('Inkscape add-on installation failed') + ': \n' + traceback.format_exc(),
_('Installation Failed'),
@@ -97,7 +93,12 @@ class InstallerFrame(wx.Frame):
for palette_file in files:
shutil.copy(palette_file, dest)
+
class Install(inkex.Effect):
+ @classmethod
+ def name(cls):
+ return "install"
+
def effect(self):
app = wx.App()
installer_frame = InstallerFrame(None, title=_("Ink/Stitch Add-ons Installer"), size=(550, 250))
diff --git a/lib/extensions/layer_commands.py b/lib/extensions/layer_commands.py
index 88170f66..dbafc39f 100644
--- a/lib/extensions/layer_commands.py
+++ b/lib/extensions/layer_commands.py
@@ -1,15 +1,14 @@
-import os
-import sys
import inkex
from .commands import CommandsExtension
+from ..commands import LAYER_COMMANDS, get_command_description
from ..i18n import _
-from ..svg.tags import SVG_USE_TAG, XLINK_HREF
+from ..svg.tags import SVG_USE_TAG, INKSCAPE_LABEL, XLINK_HREF
from ..svg import get_correction_transform
class LayerCommands(CommandsExtension):
- COMMANDS = ["ignore_layer"]
+ COMMANDS = LAYER_COMMANDS
def ensure_current_layer(self):
# if no layer is selected, inkex defaults to the root, which isn't
@@ -34,15 +33,14 @@ class LayerCommands(CommandsExtension):
for i, command in enumerate(commands):
self.ensure_symbol(command)
- node = inkex.etree.SubElement(self.current_layer, SVG_USE_TAG,
- {
- "id": self.uniqueId("use"),
- XLINK_HREF: "#inkstitch_%s" % command,
- "height": "100%",
- "width": "100%",
- "x": str(i * 20),
- "y": "-10",
- "transform": correction_transform
- })
-
- namedview = self.document.xpath("//sodipodi:namedview", namespaces=inkex.NSS)
+ inkex.etree.SubElement(self.current_layer, SVG_USE_TAG,
+ {
+ "id": self.uniqueId("use"),
+ INKSCAPE_LABEL: _("Ink/Stitch Command") + ": %s" % get_command_description(command),
+ XLINK_HREF: "#inkstitch_%s" % command,
+ "height": "100%",
+ "width": "100%",
+ "x": str(i * 20),
+ "y": "-10",
+ "transform": correction_transform
+ })
diff --git a/lib/extensions/object_commands.py b/lib/extensions/object_commands.py
index 27a07969..e678890d 100644
--- a/lib/extensions/object_commands.py
+++ b/lib/extensions/object_commands.py
@@ -1,20 +1,15 @@
-import os
-import sys
import inkex
-import simpletransform
-import cubicsuperpath
from random import random
-from shapely import geometry as shgeo
from .commands import CommandsExtension
+from ..commands import OBJECT_COMMANDS, get_command_description
from ..i18n import _
-from ..elements import SatinColumn
-from ..svg.tags import SVG_GROUP_TAG, SVG_USE_TAG, SVG_PATH_TAG, INKSCAPE_GROUPMODE, XLINK_HREF, CONNECTION_START, CONNECTION_END, CONNECTOR_TYPE
+from ..svg.tags import SVG_PATH_TAG, CONNECTION_START, CONNECTION_END, CONNECTOR_TYPE, INKSCAPE_LABEL, SVG_GROUP_TAG, SVG_USE_TAG, XLINK_HREF
from ..svg import get_correction_transform
class ObjectCommands(CommandsExtension):
- COMMANDS = ["fill_start", "fill_end", "stop", "trim", "ignore_object"]
+ COMMANDS = OBJECT_COMMANDS
def add_connector(self, symbol, element):
# I'd like it if I could position the connector endpoint nicely but inkscape just
@@ -23,18 +18,20 @@ class ObjectCommands(CommandsExtension):
end_pos = element.shape.centroid
path = inkex.etree.Element(SVG_PATH_TAG,
- {
- "id": self.uniqueId("connector"),
- "d": "M %s,%s %s,%s" % (start_pos[0], start_pos[1], end_pos.x, end_pos.y),
- "style": "stroke:#000000;stroke-width:1px;stroke-opacity:0.5;fill:none;",
- "transform": get_correction_transform(symbol),
- CONNECTION_START: "#%s" % symbol.get('id'),
- CONNECTION_END: "#%s" % element.node.get('id'),
- CONNECTOR_TYPE: "polyline",
- }
- )
+ {
+ "id": self.uniqueId("connector"),
+ "d": "M %s,%s %s,%s" % (start_pos[0], start_pos[1], end_pos.x, end_pos.y),
+ "style": "stroke:#000000;stroke-width:1px;stroke-opacity:0.5;fill:none;",
+ CONNECTION_START: "#%s" % symbol.get('id'),
+ CONNECTION_END: "#%s" % element.node.get('id'),
+ CONNECTOR_TYPE: "polyline",
+
+ # l10n: the name of the line that connects a command to the object it applies to
+ INKSCAPE_LABEL: _("connector")
+ }
+ )
- symbol.getparent().insert(symbol.getparent().index(symbol), path)
+ symbol.getparent().insert(0, path)
def get_command_pos(self, element, index, total):
# Put command symbols 30 pixels out from the shape, spaced evenly around it.
@@ -71,18 +68,28 @@ class ObjectCommands(CommandsExtension):
pos = self.get_command_pos(element, i, len(commands))
- symbol = inkex.etree.SubElement(element.node.getparent(), SVG_USE_TAG,
- {
- "id": self.uniqueId("use"),
- XLINK_HREF: "#inkstitch_%s" % command,
- "height": "100%",
- "width": "100%",
- "x": str(pos.x),
- "y": str(pos.y),
- "transform": get_correction_transform(element.node)
- }
+ group = inkex.etree.SubElement(element.node.getparent(), SVG_GROUP_TAG,
+ {
+ "id": self.uniqueId("group"),
+ INKSCAPE_LABEL: _("Ink/Stitch Command") + ": %s" % get_command_description(command),
+ "transform": get_correction_transform(element.node)
+ }
)
+ symbol = inkex.etree.SubElement(group, SVG_USE_TAG,
+ {
+ "id": self.uniqueId("use"),
+ XLINK_HREF: "#inkstitch_%s" % command,
+ "height": "100%",
+ "width": "100%",
+ "x": str(pos.x),
+ "y": str(pos.y),
+
+ # l10n: the name of a command symbol (example: scissors icon for trim command)
+ INKSCAPE_LABEL: _("command marker"),
+ }
+ )
+
self.add_connector(symbol, element)
def effect(self):
diff --git a/lib/extensions/output.py b/lib/extensions/output.py
index f3bb0a80..26fd4f2e 100644
--- a/lib/extensions/output.py
+++ b/lib/extensions/output.py
@@ -1,15 +1,12 @@
import sys
-import traceback
import os
-import inkex
import tempfile
from .base import InkstitchExtension
-from ..i18n import _
from ..output import write_embroidery_file
from ..stitch_plan import patches_to_stitch_plan
-from ..svg import render_stitch_plan, PIXELS_PER_MM
-from ..utils.io import save_stdout
+from ..svg import PIXELS_PER_MM
+
class Output(InkstitchExtension):
def __init__(self, *args, **kwargs):
diff --git a/lib/extensions/print_pdf.py b/lib/extensions/print_pdf.py
index 6e2eff58..d2e2365d 100644
--- a/lib/extensions/print_pdf.py
+++ b/lib/extensions/print_pdf.py
@@ -1,5 +1,4 @@
import sys
-import traceback
import os
from threading import Thread
import socket
@@ -13,15 +12,14 @@ import json
import inkex
from jinja2 import Environment, FileSystemLoader, select_autoescape
from datetime import date
-import base64
from flask import Flask, request, Response, send_from_directory, jsonify
import webbrowser
import requests
from .base import InkstitchExtension
from ..i18n import _, translation as inkstitch_translation
-from ..svg import PIXELS_PER_MM, render_stitch_plan
-from ..svg.tags import SVG_GROUP_TAG, INKSCAPE_GROUPMODE
+from ..svg import render_stitch_plan
+from ..svg.tags import INKSCAPE_GROUPMODE
from ..stitch_plan import patches_to_stitch_plan
from ..threads import ThreadCatalog
@@ -44,7 +42,7 @@ def load_defaults():
with open(defaults_path(), 'r') as defaults_file:
defaults = json.load(defaults_file)
return defaults
- except:
+ except BaseException:
return {}
@@ -109,7 +107,7 @@ class PrintPreviewServer(Thread):
else:
self.resources_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'print', 'resources'))
- def __setup_app(self):
+ def __setup_app(self): # noqa: C901
self.__set_resources_path()
self.app = Flask(__name__)
@@ -196,11 +194,11 @@ class PrintPreviewServer(Thread):
threads = []
for color_block in self.stitch_plan:
threads.append({
- 'hex': color_block.color.hex_digits,
- 'name': color_block.color.name,
- 'manufacturer': color_block.color.manufacturer,
- 'number': color_block.color.number,
- })
+ 'hex': color_block.color.hex_digits,
+ 'name': color_block.color.name,
+ 'manufacturer': color_block.color.manufacturer,
+ 'number': color_block.color.number,
+ })
return jsonify(threads)
@@ -225,10 +223,10 @@ class PrintPreviewServer(Thread):
break
if self.last_request_time is not None and \
- (time.time() - self.last_request_time) > 3:
- self.stop()
- break
- except:
+ (time.time() - self.last_request_time) > 3:
+ self.stop()
+ break
+ except BaseException:
# seems like sometimes this thread blows up during shutdown
pass
@@ -244,7 +242,7 @@ class PrintPreviewServer(Thread):
while True:
try:
self.app.run(self.host, self.port, threaded=True)
- except socket.error, e:
+ except socket.error as e:
if e.errno == errno.EADDRINUSE:
self.port += 1
continue
@@ -262,14 +260,17 @@ class PrintInfoFrame(wx.Frame):
panel = wx.Panel(self)
sizer = wx.BoxSizer(wx.VERTICAL)
- text = wx.StaticText(panel, label=_("A print preview has been opened in your web browser. This window will stay open in order to communicate with the JavaScript code running in your browser.\n\nThis window will close after you close the print preview in your browser, or you can close it manually if necessary."))
+ message = _("A print preview has been opened in your web browser. "
+ "This window will stay open in order to communicate with the JavaScript code running in your browser.\n\n"
+ "This window will close after you close the print preview in your browser, or you can close it manually if necessary.")
+ text = wx.StaticText(panel, label=message)
font = wx.Font(14, wx.DEFAULT, wx.NORMAL, wx.NORMAL)
text.SetFont(font)
- sizer.Add(text, proportion=1, flag=wx.ALL|wx.EXPAND, border=20)
+ sizer.Add(text, proportion=1, flag=wx.ALL | wx.EXPAND, border=20)
stop_button = wx.Button(panel, id=wx.ID_CLOSE)
stop_button.Bind(wx.EVT_BUTTON, self.close_button_clicked)
- sizer.Add(stop_button, proportion=0, flag=wx.ALIGN_CENTER|wx.ALL, border=10)
+ sizer.Add(stop_button, proportion=0, flag=wx.ALIGN_CENTER | wx.ALL, border=10)
panel.SetSizer(sizer)
panel.Layout()
@@ -289,13 +290,13 @@ class PrintInfoFrame(wx.Frame):
class Print(InkstitchExtension):
def build_environment(self):
- if getattr( sys, 'frozen', False ) :
+ if getattr(sys, 'frozen', False):
template_dir = os.path.join(sys._MEIPASS, "print", "templates")
else:
template_dir = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..", "print", "templates"))
env = Environment(
- loader = FileSystemLoader(template_dir),
+ loader=FileSystemLoader(template_dir),
autoescape=select_autoescape(['html', 'xml']),
extensions=['jinja2.ext.i18n']
)
@@ -308,8 +309,8 @@ class Print(InkstitchExtension):
def strip_namespaces(self, svg):
# namespace prefixes seem to trip up HTML, so get rid of them
for element in svg.iter():
- if element.tag[0]=='{':
- element.tag = element.tag[element.tag.index('}',1) + 1:]
+ if element.tag[0] == '{':
+ element.tag = element.tag[element.tag.index('}', 1) + 1:]
def render_svgs(self, stitch_plan, realistic=False):
svg = deepcopy(self.document).getroot()
@@ -352,25 +353,25 @@ class Print(InkstitchExtension):
template = env.get_template('index.html')
return template.render(
- view = {'client_overview': False, 'client_detailedview': False, 'operator_overview': True, 'operator_detailedview': True},
- logo = {'src' : '', 'title' : 'LOGO'},
- date = date.today(),
- client = "",
- job = {
- 'title': '',
- 'num_colors': stitch_plan.num_colors,
- 'num_color_blocks': len(stitch_plan),
- 'num_stops': stitch_plan.num_stops,
- 'num_trims': stitch_plan.num_trims,
- 'dimensions': stitch_plan.dimensions_mm,
- 'num_stitches': stitch_plan.num_stitches,
- 'estimated_time': '', # TODO
- 'estimated_thread': '', # TODO
- },
- svg_overview = overview_svg,
- color_blocks = stitch_plan.color_blocks,
- palettes = ThreadCatalog().palette_names(),
- selected_palette = selected_palette,
+ view={'client_overview': False, 'client_detailedview': False, 'operator_overview': True, 'operator_detailedview': True},
+ logo={'src': '', 'title': 'LOGO'},
+ date=date.today(),
+ client="",
+ job={
+ 'title': '',
+ 'num_colors': stitch_plan.num_colors,
+ 'num_color_blocks': len(stitch_plan),
+ 'num_stops': stitch_plan.num_stops,
+ 'num_trims': stitch_plan.num_trims,
+ 'dimensions': stitch_plan.dimensions_mm,
+ 'num_stitches': stitch_plan.num_stitches,
+ 'estimated_time': '', # TODO
+ 'estimated_thread': '', # TODO
+ },
+ svg_overview=overview_svg,
+ color_blocks=stitch_plan.color_blocks,
+ palettes=ThreadCatalog().palette_names(),
+ selected_palette=selected_palette,
)
def effect(self):
@@ -396,12 +397,12 @@ class Print(InkstitchExtension):
html = self.render_html(stitch_plan, overview_svg, palette)
print_server = PrintPreviewServer(
- html=html,
- metadata=self.get_inkstitch_metadata(),
- stitch_plan=stitch_plan,
- realistic_overview_svg=realistic_overview_svg,
- realistic_color_block_svgs=realistic_color_block_svgs
- )
+ html=html,
+ metadata=self.get_inkstitch_metadata(),
+ stitch_plan=stitch_plan,
+ realistic_overview_svg=realistic_overview_svg,
+ realistic_color_block_svgs=realistic_color_block_svgs
+ )
print_server.start()
time.sleep(1)
diff --git a/lib/extensions/zip.py b/lib/extensions/zip.py
index 02f29e8a..2376f79a 100644
--- a/lib/extensions/zip.py
+++ b/lib/extensions/zip.py
@@ -1,7 +1,5 @@
import sys
-import traceback
import os
-import inkex
import tempfile
from zipfile import ZipFile
import pyembroidery
@@ -10,8 +8,7 @@ from .base import InkstitchExtension
from ..i18n import _
from ..output import write_embroidery_file
from ..stitch_plan import patches_to_stitch_plan
-from ..svg import render_stitch_plan, PIXELS_PER_MM
-from ..utils.io import save_stdout
+from ..svg import PIXELS_PER_MM
class Zip(InkstitchExtension):