summaryrefslogtreecommitdiff
path: root/lib/extensions
diff options
context:
space:
mode:
Diffstat (limited to 'lib/extensions')
-rw-r--r--lib/extensions/__init__.py2
-rw-r--r--lib/extensions/base.py12
-rw-r--r--lib/extensions/convert_to_satin.py27
-rw-r--r--lib/extensions/flip.py1
-rw-r--r--lib/extensions/input.py11
-rw-r--r--lib/extensions/install.py16
-rw-r--r--lib/extensions/layer_commands.py20
-rw-r--r--lib/extensions/object_commands.py58
-rw-r--r--lib/extensions/output.py1
-rw-r--r--lib/extensions/print_pdf.py84
10 files changed, 116 insertions, 116 deletions
diff --git a/lib/extensions/__init__.py b/lib/extensions/__init__.py
index 1606795c..b865db4c 100644
--- a/lib/extensions/__init__.py
+++ b/lib/extensions/__init__.py
@@ -19,4 +19,4 @@ for item in locals().values():
if inspect.isclass(item) and \
issubclass(item, InkstitchExtension) and \
item is not InkstitchExtension:
- extensions.append(item)
+ extensions.append(item)
diff --git a/lib/extensions/base.py b/lib/extensions/base.py
index 1794b68c..07eaa40c 100644
--- a/lib/extensions/base.py
+++ b/lib/extensions/base.py
@@ -109,11 +109,11 @@ class InkstitchExtension(inkex.Effect):
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 = []
@@ -176,7 +176,6 @@ class InkstitchExtension(inkex.Effect):
return classes
-
def get_elements(self):
self.elements = []
for node in self.get_nodes():
@@ -212,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/convert_to_satin.py b/lib/extensions/convert_to_satin.py
index dd5a9bc2..d27e42cc 100644
--- a/lib/extensions/convert_to_satin.py
+++ b/lib/extensions/convert_to_satin.py
@@ -51,7 +51,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 +86,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 +115,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 +246,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 +271,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 +280,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/flip.py b/lib/extensions/flip.py
index d8d78cb5..5bea510f 100644
--- a/lib/extensions/flip.py
+++ b/lib/extensions/flip.py
@@ -7,6 +7,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/input.py b/lib/extensions/input.py
index cb5ac452..e450bef6 100644
--- a/lib/extensions/input.py
+++ b/lib/extensions/input.py
@@ -28,12 +28,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..2863bef0 100644
--- a/lib/extensions/install.py
+++ b/lib/extensions/install.py
@@ -28,22 +28,21 @@ 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...)")
+ "\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 +62,7 @@ class InstallerFrame(wx.Frame):
try:
self.install_addons('palettes')
self.install_addons('symbols')
- except Exception, e:
+ except Exception as e:
wx.MessageDialog(self,
_('Inkscape add-on installation failed') + ': \n' + traceback.format_exc(),
_('Installation Failed'),
@@ -97,6 +96,7 @@ class InstallerFrame(wx.Frame):
for palette_file in files:
shutil.copy(palette_file, dest)
+
class Install(inkex.Effect):
def effect(self):
app = wx.App()
diff --git a/lib/extensions/layer_commands.py b/lib/extensions/layer_commands.py
index 576af044..b9be2b27 100644
--- a/lib/extensions/layer_commands.py
+++ b/lib/extensions/layer_commands.py
@@ -36,15 +36,15 @@ class LayerCommands(CommandsExtension):
self.ensure_symbol(command)
node = 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
- })
+ {
+ "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
+ })
namedview = self.document.xpath("//sodipodi:namedview", namespaces=inkex.NSS)
diff --git a/lib/extensions/object_commands.py b/lib/extensions/object_commands.py
index e9ee6063..483f2a0a 100644
--- a/lib/extensions/object_commands.py
+++ b/lib/extensions/object_commands.py
@@ -24,18 +24,18 @@ 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;",
- 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")
- }
- )
+ {
+ "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(0, path)
@@ -75,26 +75,26 @@ class ObjectCommands(CommandsExtension):
pos = self.get_command_pos(element, i, len(commands))
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)
- }
+ {
+ "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"),
- }
- )
+ {
+ "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)
diff --git a/lib/extensions/output.py b/lib/extensions/output.py
index f3bb0a80..090cd3a9 100644
--- a/lib/extensions/output.py
+++ b/lib/extensions/output.py
@@ -11,6 +11,7 @@ from ..stitch_plan import patches_to_stitch_plan
from ..svg import render_stitch_plan, PIXELS_PER_MM
from ..utils.io import save_stdout
+
class Output(InkstitchExtension):
def __init__(self, *args, **kwargs):
InkstitchExtension.__init__(self)
diff --git a/lib/extensions/print_pdf.py b/lib/extensions/print_pdf.py
index 6e2eff58..ee3dc316 100644
--- a/lib/extensions/print_pdf.py
+++ b/lib/extensions/print_pdf.py
@@ -44,7 +44,7 @@ def load_defaults():
with open(defaults_path(), 'r') as defaults_file:
defaults = json.load(defaults_file)
return defaults
- except:
+ except BaseException:
return {}
@@ -196,11 +196,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 +225,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 +244,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
@@ -265,11 +265,11 @@ class PrintInfoFrame(wx.Frame):
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."))
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 +289,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 +308,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 +352,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 +396,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)