summaryrefslogtreecommitdiff
path: root/lib/extensions
diff options
context:
space:
mode:
Diffstat (limited to 'lib/extensions')
-rw-r--r--lib/extensions/__init__.py4
-rw-r--r--lib/extensions/base.py28
-rw-r--r--lib/extensions/break_apart.py2
-rw-r--r--lib/extensions/convert_to_satin.py20
-rw-r--r--lib/extensions/convert_to_stroke.py58
-rw-r--r--lib/extensions/input.py2
-rw-r--r--lib/extensions/install_custom_palette.py42
-rw-r--r--lib/extensions/layer_commands.py22
-rw-r--r--lib/extensions/lettering.py39
-rw-r--r--lib/extensions/params.py4
-rw-r--r--lib/extensions/print_pdf.py22
-rw-r--r--lib/extensions/troubleshoot.py124
12 files changed, 208 insertions, 159 deletions
diff --git a/lib/extensions/__init__.py b/lib/extensions/__init__.py
index 7996770d..83a522f2 100644
--- a/lib/extensions/__init__.py
+++ b/lib/extensions/__init__.py
@@ -9,6 +9,7 @@ from .auto_satin import AutoSatin
from .break_apart import BreakApart
from .cleanup import Cleanup
from .convert_to_satin import ConvertToSatin
+from .convert_to_stroke import ConvertToStroke
from .cut_satin import CutSatin
from .duplicate_params import DuplicateParams
from .embroider_settings import EmbroiderSettings
@@ -17,6 +18,7 @@ from .global_commands import GlobalCommands
from .import_threadlist import ImportThreadlist
from .input import Input
from .install import Install
+from .install_custom_palette import InstallCustomPalette
from .layer_commands import LayerCommands
from .lettering import Lettering
from .lettering_custom_font_dir import LetteringCustomFontDir
@@ -46,6 +48,7 @@ __all__ = extensions = [StitchPlanPreview,
LayerCommands,
GlobalCommands,
ConvertToSatin,
+ ConvertToStroke,
CutSatin,
AutoSatin,
Lettering,
@@ -57,6 +60,7 @@ __all__ = extensions = [StitchPlanPreview,
Cleanup,
BreakApart,
ImportThreadlist,
+ InstallCustomPalette,
Simulator,
Reorder,
DuplicateParams,
diff --git a/lib/extensions/base.py b/lib/extensions/base.py
index 862d031e..476e4969 100644
--- a/lib/extensions/base.py
+++ b/lib/extensions/base.py
@@ -50,19 +50,7 @@ class InkStitchMetadata(MutableMapping):
def __init__(self, document):
self.document = document
- self.metadata = self._get_or_create_metadata()
-
- def _get_or_create_metadata(self):
- metadata = self.document.find(SVG_METADATA_TAG)
-
- if metadata is None:
- metadata = etree.SubElement(self.document.getroot(), SVG_METADATA_TAG)
-
- # move it so that it goes right after the first element, sodipodi:namedview
- self.document.getroot().remove(metadata)
- self.document.getroot().insert(1, metadata)
-
- return metadata
+ self.metadata = document.metadata
# Because this class inherints from MutableMapping, all we have to do is
# implement these five methods and we get a full dict-like interface.
@@ -118,15 +106,17 @@ class InkstitchExtension(inkex.Effect):
if g.get(INKSCAPE_GROUPMODE) == "layer":
g.set("style", "display:none")
- def ensure_current_layer(self):
+ def get_current_layer(self):
# if no layer is selected, inkex defaults to the root, which isn't
# particularly useful
- if self.svg.get_current_layer() is self.document.getroot():
+ current_layer = self.svg.get_current_layer()
+ if current_layer is self.document.getroot():
try:
- self.current_layer = self.document.xpath(".//svg:g[@inkscape:groupmode='layer']", namespaces=inkex.NSS)[0]
+ current_layer = self.document.xpath(".//svg:g[@inkscape:groupmode='layer']", namespaces=inkex.NSS)[0]
except IndexError:
# No layers at all?? Fine, we'll stick with the default.
pass
+ return current_layer
def no_elements_error(self):
if self.svg.selected:
@@ -135,7 +125,7 @@ class InkstitchExtension(inkex.Effect):
else:
inkex.errormsg(_("There are no objects in the entire document that Ink/Stitch knows how to work with.") + "\n")
- inkex.errormsg(_("Tip: Select some objects and use Path -> Object to Path to convert them to paths.") + "\n")
+ inkex.errormsg(_("Tip: Run Extensions > Ink/Stitch > Troubleshoot > Troubleshoot Objects") + "\n")
def descendants(self, node, selected=False, troubleshoot=False): # noqa: C901
nodes = []
@@ -148,7 +138,7 @@ class InkstitchExtension(inkex.Effect):
if len(list(layer_commands(node, "ignore_layer"))):
return []
- if element.has_style('display') and element.get_style('display') is None:
+ if (node.tag in EMBROIDERABLE_TAGS or node.tag == SVG_GROUP_TAG) and element.get_style('display', 'inline') is None:
return []
if node.tag == SVG_DEFS_TAG:
@@ -211,7 +201,7 @@ class InkstitchExtension(inkex.Effect):
return patches
def get_inkstitch_metadata(self):
- return InkStitchMetadata(self.document)
+ return InkStitchMetadata(self.svg)
def get_base_file_name(self):
svg_filename = self.document.getroot().get(inkex.addNS('docname', 'sodipodi'), "embroidery.svg")
diff --git a/lib/extensions/break_apart.py b/lib/extensions/break_apart.py
index c2eb02d4..c645c7a1 100644
--- a/lib/extensions/break_apart.py
+++ b/lib/extensions/break_apart.py
@@ -141,7 +141,7 @@ class BreakApart(InkstitchExtension):
el = copy(element.node)
# Set fill-rule to evenodd
- style = el.get('style', '').split(';')
+ style = el.get('style', ' ').split(';')
style = [s for s in style if not s.startswith('fill-rule')]
style.append('fill-rule:evenodd;')
style = ';'.join(style)
diff --git a/lib/extensions/convert_to_satin.py b/lib/extensions/convert_to_satin.py
index 393ffd9e..f3b43366 100644
--- a/lib/extensions/convert_to_satin.py
+++ b/lib/extensions/convert_to_satin.py
@@ -9,16 +9,15 @@ from itertools import chain, groupby
import inkex
import numpy
-from lxml import etree
from numpy import diff, setdiff1d, sign
from shapely import geometry as shgeo
+from .base import InkstitchExtension
from ..elements import Stroke
from ..i18n import _
from ..svg import PIXELS_PER_MM, get_correction_transform
-from ..svg.tags import INKSTITCH_ATTRIBS, SVG_PATH_TAG
+from ..svg.tags import INKSTITCH_ATTRIBS
from ..utils import Point
-from .base import InkstitchExtension
class SelfIntersectionError(Exception):
@@ -317,11 +316,10 @@ class ConvertToSatin(InkstitchExtension):
d += "%s,%s " % (x, y)
d += " "
- return etree.Element(SVG_PATH_TAG,
- {
- "id": self.uniqueId("path"),
- "style": path_style,
- "transform": correction_transform,
- "d": d,
- INKSTITCH_ATTRIBS['satin_column']: "true",
- })
+ return inkex.PathElement(attrib={
+ "id": self.uniqueId("path"),
+ "style": path_style,
+ "transform": correction_transform,
+ "d": d,
+ INKSTITCH_ATTRIBS['satin_column']: "true",
+ })
diff --git a/lib/extensions/convert_to_stroke.py b/lib/extensions/convert_to_stroke.py
new file mode 100644
index 00000000..dfaef615
--- /dev/null
+++ b/lib/extensions/convert_to_stroke.py
@@ -0,0 +1,58 @@
+# Authors: see git history
+#
+# Copyright (c) 2010 Authors
+# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details.
+
+import inkex
+from lxml import etree
+
+from ..elements import SatinColumn
+from ..i18n import _
+from ..svg import get_correction_transform
+from ..svg.tags import SVG_PATH_TAG
+from .base import InkstitchExtension
+
+
+class ConvertToStroke(InkstitchExtension):
+ """Convert a satin column into a running stitch."""
+
+ def __init__(self, *args, **kwargs):
+ InkstitchExtension.__init__(self, *args, **kwargs)
+ self.arg_parser.add_argument("-k", "--keep_satin", type=inkex.Boolean, default=False, dest="keep_satin")
+
+ def effect(self):
+ if not self.svg.selected or not self.get_elements():
+ inkex.errormsg(_("Please select at least one satin column to convert to a running stitch."))
+ return
+
+ if not any(isinstance(item, SatinColumn) for item in self.elements):
+ # L10N: Convert To Satin extension, user selected one or more objects that were not lines.
+ inkex.errormsg(_("Please select at least one satin column to convert to a running stitch."))
+ return
+
+ for element in self.elements:
+ if not isinstance(element, SatinColumn):
+ continue
+
+ parent = element.node.getparent()
+ center_line = element.center_line.simplify(0.05)
+
+ d = "M"
+ for x, y in center_line.coords:
+ d += "%s,%s " % (x, y)
+ d += " "
+
+ stroke_element = etree.Element(SVG_PATH_TAG,
+ {
+ "id": self.uniqueId("path"),
+ "style": self.path_style(element),
+ "transform": get_correction_transform(element.node),
+ "d": d
+ })
+ parent.insert(parent.index(element.node), stroke_element)
+ if not self.options.keep_satin:
+ parent.remove(element.node)
+
+ def path_style(self, element):
+ color = element.get_style('stroke', '#000000')
+ return "stroke:%s;stroke-width:1px;stroke-dasharray:3, 1;fill:none" % (color)
diff --git a/lib/extensions/input.py b/lib/extensions/input.py
index a0861bbc..a8b8bee3 100644
--- a/lib/extensions/input.py
+++ b/lib/extensions/input.py
@@ -47,7 +47,7 @@ class Input(object):
del stitch_plan.last_color_block[-1]
extents = stitch_plan.extents
- svg = etree.Element("svg", nsmap=inkex.NSS, attrib={
+ svg = inkex.SvgDocumentElement("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),
diff --git a/lib/extensions/install_custom_palette.py b/lib/extensions/install_custom_palette.py
new file mode 100644
index 00000000..da546cad
--- /dev/null
+++ b/lib/extensions/install_custom_palette.py
@@ -0,0 +1,42 @@
+# Authors: see git history
+#
+# Copyright (c) 2021 Authors
+# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details.
+
+import os
+import shutil
+
+import inkex
+
+from ..i18n import _
+from ..utils import guess_inkscape_config_path
+from .base import InkstitchExtension
+
+
+class InstallCustomPalette(InkstitchExtension):
+ def __init__(self, *args, **kwargs):
+ InkstitchExtension.__init__(self, *args, **kwargs)
+ self.arg_parser.add_argument("-f", "--filepath", type=str, default="", dest="filepath")
+
+ def effect(self):
+ gpl = self.options.filepath
+ if not os.path.isfile(gpl):
+ inkex.errormsg(_("File does not exist."))
+
+ palette_name = os.path.basename(gpl)
+ if not palette_name.endswith('.gpl'):
+ inkex.errormsg(_("Wrong file type. Ink/Stitch only accepts gpl color palettes."))
+
+ if not palette_name.startswith('InkStitch'):
+ palette_name = 'InkStitch %s' % palette_name
+
+ palette_path = os.path.join(guess_inkscape_config_path(), 'palettes')
+
+ if not os.path.isdir(palette_path):
+ inkex.errormsg(_("Ink/Stitch cannot find your palette folder automatically. Please install your palette manually."))
+ dest = os.path.join(palette_path, palette_name)
+ shutil.copyfile(gpl, dest)
+
+ if not os.path.isfile(dest):
+ inkex.errormsg("Something wwent wrong. Ink/Stitch wasn't able to copy your palette "
+ "file into the Inkscape palettes folder. Please do it manually.")
diff --git a/lib/extensions/layer_commands.py b/lib/extensions/layer_commands.py
index 2494e820..26f01fad 100644
--- a/lib/extensions/layer_commands.py
+++ b/lib/extensions/layer_commands.py
@@ -4,12 +4,9 @@
# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details.
import inkex
-from lxml import etree
-from ..commands import LAYER_COMMANDS, ensure_symbol, get_command_description
+from ..commands import LAYER_COMMANDS, add_layer_commands
from ..i18n import _
-from ..svg import get_correction_transform
-from ..svg.tags import INKSCAPE_LABEL, SVG_USE_TAG, XLINK_HREF
from .commands import CommandsExtension
@@ -23,19 +20,4 @@ class LayerCommands(CommandsExtension):
inkex.errormsg(_("Please choose one or more commands to add."))
return
- correction_transform = get_correction_transform(self.svg.get_current_layer(), child=True)
-
- for i, command in enumerate(commands):
- ensure_symbol(self.document, command)
-
- etree.SubElement(self.svg.get_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
- })
+ add_layer_commands(self.svg.get_current_layer(), commands)
diff --git a/lib/extensions/lettering.py b/lib/extensions/lettering.py
index cf627fe5..312a47ce 100644
--- a/lib/extensions/lettering.py
+++ b/lib/extensions/lettering.py
@@ -12,7 +12,6 @@ import appdirs
import inkex
import wx
import wx.adv
-from lxml import etree
from ..elements import nodes_to_elements
from ..gui import PresetsPanel, SimulatorPreview, info_dialog
@@ -21,7 +20,7 @@ from ..lettering import Font, FontError
from ..svg import get_correction_transform
from ..svg.tags import (INKSCAPE_LABEL, INKSTITCH_LETTERING, SVG_GROUP_TAG,
SVG_PATH_TAG)
-from ..utils import DotDict, cache, get_bundled_dir
+from ..utils import DotDict, cache, get_bundled_dir, get_resource_dir
from .commands import CommandsExtension
from .lettering_custom_font_dir import get_custom_font_dir
@@ -44,6 +43,9 @@ class LetteringFrame(wx.Frame):
_("Ink/Stitch Lettering")
)
+ icon = wx.Icon(os.path.join(get_resource_dir("icons"), "inkstitch256x256.png"))
+ self.SetIcon(icon)
+
self.preview = SimulatorPreview(self, target_duration=1)
self.presets_panel = PresetsPanel(self)
@@ -142,10 +144,10 @@ class LetteringFrame(wx.Frame):
for font_dir in font_dirs:
font = Font(os.path.join(font_path, font_dir))
- if font.name == "" or font.id == "":
+ if font.marked_custom_font_name == "" or font.marked_custom_font_id == "":
continue
- self.fonts[font.name] = font
- self.fonts_by_id[font.id] = font
+ self.fonts[font.marked_custom_font_name] = font
+ self.fonts_by_id[font.marked_custom_font_id] = font
if len(self.fonts) == 0:
info_dialog(self, _("Unable to find any fonts! Please try reinstalling Ink/Stitch."))
@@ -154,6 +156,7 @@ class LetteringFrame(wx.Frame):
def set_font_list(self):
for font in self.fonts.values():
image = font.preview_image
+
if image is not None:
image = wx.Image(font.preview_image)
"""
@@ -169,16 +172,10 @@ class LetteringFrame(wx.Frame):
"""
# Windows requires all images to have the exact same size
image.Rescale(300, 20, quality=wx.IMAGE_QUALITY_HIGH)
- self.font_chooser.Append(font.name, wx.Bitmap(image))
+ self.font_chooser.Append(font.marked_custom_font_name, wx.Bitmap(image))
else:
self.font_chooser.Append(font.name)
- def get_font_names(self):
- font_names = [font.name for font in self.fonts.values()]
- font_names.sort()
-
- return font_names
-
def get_font_descriptions(self):
return {font.name: font.description for font in self.fonts.values()}
@@ -189,9 +186,11 @@ class LetteringFrame(wx.Frame):
'''A default font will be substituted.'''
info_dialog(self, _(message) % font_id)
try:
- self.font_chooser.SetValue(self.fonts_by_id[font_id].name)
+ font = self.fonts_by_id[font_id].marked_custom_font_name
except KeyError:
- self.font_chooser.SetValue(self.default_font.name)
+ font = self.default_font.name
+ self.font_chooser.SetValue(font)
+
self.on_font_changed()
@property
@@ -208,7 +207,7 @@ class LetteringFrame(wx.Frame):
def on_font_changed(self, event=None):
font = self.fonts.get(self.font_chooser.GetValue(), self.default_font)
- self.settings.font = font.id
+ self.settings.font = font.marked_custom_font_id
self.scale_spinner.SetRange(int(font.min_scale * 100), int(font.max_scale * 100))
font_variants = []
@@ -260,12 +259,13 @@ class LetteringFrame(wx.Frame):
if self.settings.scale == 100:
destination_group = self.group
else:
- destination_group = etree.SubElement(self.group, SVG_GROUP_TAG, {
+ destination_group = inkex.Group(attrib={
# L10N The user has chosen to scale the text by some percentage
# (50%, 200%, etc). If you need to use the percentage symbol,
# make sure to double it (%%).
INKSCAPE_LABEL: _("Text scale %s%%") % self.settings.scale
})
+ self.group.append(destination_group)
font = self.fonts.get(self.font_chooser.GetValue(), self.default_font)
try:
@@ -416,11 +416,12 @@ class Lettering(CommandsExtension):
else:
return list(groups)[0]
else:
- self.ensure_current_layer()
- return etree.SubElement(self.svg.get_current_layer(), SVG_GROUP_TAG, {
+ group = inkex.Group(attrib={
INKSCAPE_LABEL: _("Ink/Stitch Lettering"),
- "transform": get_correction_transform(self.svg.get_current_layer(), child=True)
+ "transform": get_correction_transform(self.get_current_layer(), child=True)
})
+ self.get_current_layer().append(group)
+ return group
def effect(self):
app = wx.App()
diff --git a/lib/extensions/params.py b/lib/extensions/params.py
index 7775aed1..c96b9691 100644
--- a/lib/extensions/params.py
+++ b/lib/extensions/params.py
@@ -343,6 +343,10 @@ class SettingsFrame(wx.Frame):
wx.Frame.__init__(self, None, wx.ID_ANY,
_("Embroidery Params")
)
+
+ icon = wx.Icon(os.path.join(get_resource_dir("icons"), "inkstitch256x256.png"))
+ self.SetIcon(icon)
+
self.notebook = wx.Notebook(self, wx.ID_ANY)
self.tabs = self.tabs_factory(self.notebook)
diff --git a/lib/extensions/print_pdf.py b/lib/extensions/print_pdf.py
index a1a8c6c0..0facdf92 100644
--- a/lib/extensions/print_pdf.py
+++ b/lib/extensions/print_pdf.py
@@ -15,10 +15,10 @@ from datetime import date
from threading import Thread
import appdirs
-import requests
from flask import Flask, Response, jsonify, request, send_from_directory
from jinja2 import Environment, FileSystemLoader, select_autoescape
from lxml import etree
+from werkzeug.serving import make_server
from ..gui import open_url
from ..i18n import get_languages
@@ -66,7 +66,8 @@ class PrintPreviewServer(Thread):
self.realistic_color_block_svgs = kwargs.pop('realistic_color_block_svgs')
Thread.__init__(self, *args, **kwargs)
self.daemon = True
- self.shutting_down = False
+ self.flask_server = None
+ self.server_thread = None
self.__setup_app()
@@ -89,15 +90,9 @@ class PrintPreviewServer(Thread):
def index():
return self.html
- @self.app.route('/shutdown', methods=['POST'])
- def shutdown():
- self.shutting_down = True
- request.environ.get('werkzeug.server.shutdown')()
- return "shutting down"
-
@self.app.route('/resources/<path:resource>', methods=['GET'])
def resources(resource):
- return send_from_directory(self.resources_path, resource, cache_timeout=1)
+ return send_from_directory(self.resources_path, resource, max_age=1)
@self.app.route('/settings/<field_name>', methods=['POST'])
def set_field(field_name):
@@ -158,9 +153,8 @@ class PrintPreviewServer(Thread):
return Response(self.realistic_overview_svg, mimetype='image/svg+xml')
def stop(self):
- # for whatever reason, shutting down only seems possible in
- # the context of a flask request, so we'll just make one
- requests.post("http://%s:%s/shutdown" % (self.host, self.port))
+ self.flask_server.shutdown()
+ self.server_thread.join()
def disable_logging(self):
logging.getLogger('werkzeug').setLevel(logging.ERROR)
@@ -173,7 +167,9 @@ class PrintPreviewServer(Thread):
while True:
try:
- self.app.run(self.host, self.port, threaded=True)
+ self.flask_server = make_server(self.host, self.port, self.app)
+ self.server_thread = Thread(target=self.flask_server.serve_forever)
+ self.server_thread.start()
except socket.error as e:
if e.errno == errno.EADDRINUSE:
self.port += 1
diff --git a/lib/extensions/troubleshoot.py b/lib/extensions/troubleshoot.py
index 113a9383..bf7faf76 100644
--- a/lib/extensions/troubleshoot.py
+++ b/lib/extensions/troubleshoot.py
@@ -5,18 +5,15 @@
import textwrap
-from inkex import errormsg
-from lxml import etree
+import inkex
+from .base import InkstitchExtension
from ..commands import add_layer_commands
from ..elements.validation import (ObjectTypeWarning, ValidationError,
ValidationWarning)
from ..i18n import _
from ..svg.path import get_correction_transform
-from ..svg.tags import (INKSCAPE_GROUPMODE, INKSCAPE_LABEL, SODIPODI_ROLE,
- SVG_GROUP_TAG, SVG_PATH_TAG, SVG_TEXT_TAG,
- SVG_TSPAN_TAG)
-from .base import InkstitchExtension
+from ..svg.tags import (INKSCAPE_GROUPMODE, INKSCAPE_LABEL, SODIPODI_ROLE)
class Troubleshoot(InkstitchExtension):
@@ -49,7 +46,7 @@ class Troubleshoot(InkstitchExtension):
message += "\n\n"
message += _("If you are still having trouble with a shape not being embroidered, "
"check if it is in a layer with an ignore command.")
- errormsg(message)
+ inkex.errormsg(message)
def insert_pointer(self, problem):
correction_transform = get_correction_transform(self.troubleshoot_layer)
@@ -67,32 +64,28 @@ class Troubleshoot(InkstitchExtension):
pointer_style = "stroke:#000000;stroke-width:0.2;fill:%s;" % (fill_color)
text_style = "fill:%s;stroke:#000000;stroke-width:0.2;font-size:8px;text-align:center;text-anchor:middle" % (fill_color)
- path = etree.Element(
- SVG_PATH_TAG,
- {
- "id": self.uniqueId("inkstitch__invalid_pointer__"),
- "d": "m %s,%s 4,20 h -8 l 4,-20" % (problem.position.x, problem.position.y),
- "style": pointer_style,
- INKSCAPE_LABEL: _('Invalid Pointer'),
- "transform": correction_transform
- }
- )
+ path = inkex.PathElement(attrib={
+ "id": self.uniqueId("inkstitch__invalid_pointer__"),
+ "d": "m %s,%s 4,20 h -8 l 4,-20" % (problem.position.x, problem.position.y),
+ "style": pointer_style,
+ INKSCAPE_LABEL: _('Invalid Pointer'),
+ "transform": correction_transform
+ })
layer.insert(0, path)
- text = etree.Element(
- SVG_TEXT_TAG,
- {
- INKSCAPE_LABEL: _('Description'),
- "x": str(problem.position.x),
- "y": str(float(problem.position.y) + 30),
- "transform": correction_transform,
- "style": text_style
- }
- )
+ text = inkex.TextElement(attrib={
+ INKSCAPE_LABEL: _('Description'),
+ "x": str(problem.position.x),
+ "y": str(float(problem.position.y) + 30),
+ "transform": correction_transform,
+ "style": text_style
+ })
layer.append(text)
- tspan = etree.Element(SVG_TSPAN_TAG)
+ tspan = inkex.Tspan()
tspan.text = problem.name
+ if problem.label:
+ tspan.text += " (%s)" % problem.label
text.append(tspan)
def create_troubleshoot_layer(self):
@@ -100,46 +93,34 @@ class Troubleshoot(InkstitchExtension):
layer = svg.find(".//*[@id='__validation_layer__']")
if layer is None:
- layer = etree.Element(
- SVG_GROUP_TAG,
- {
- 'id': '__validation_layer__',
- INKSCAPE_LABEL: _('Troubleshoot'),
- INKSCAPE_GROUPMODE: 'layer',
- })
+ layer = inkex.Group(attrib={
+ 'id': '__validation_layer__',
+ INKSCAPE_LABEL: _('Troubleshoot'),
+ INKSCAPE_GROUPMODE: 'layer',
+ })
svg.append(layer)
-
else:
# Clear out everything from the last run
del layer[:]
add_layer_commands(layer, ["ignore_layer"])
- error_group = etree.SubElement(
- layer,
- SVG_GROUP_TAG,
- {
- "id": '__validation_errors__',
- INKSCAPE_LABEL: _("Errors"),
- })
+ error_group = inkex.Group(attrib={
+ "id": '__validation_errors__',
+ INKSCAPE_LABEL: _("Errors"),
+ })
layer.append(error_group)
- warning_group = etree.SubElement(
- layer,
- SVG_GROUP_TAG,
- {
- "id": '__validation_warnings__',
- INKSCAPE_LABEL: _("Warnings"),
- })
+ warning_group = inkex.Group(attrib={
+ "id": '__validation_warnings__',
+ INKSCAPE_LABEL: _("Warnings"),
+ })
layer.append(warning_group)
- type_warning_group = etree.SubElement(
- layer,
- SVG_GROUP_TAG,
- {
- "id": '__validation_ignored__',
- INKSCAPE_LABEL: _("Type Warnings"),
- })
+ type_warning_group = inkex.Group(attrib={
+ "id": '__validation_ignored__',
+ INKSCAPE_LABEL: _("Type Warnings"),
+ })
layer.append(type_warning_group)
self.troubleshoot_layer = layer
@@ -151,14 +132,11 @@ class Troubleshoot(InkstitchExtension):
svg = self.document.getroot()
text_x = str(float(svg.get('viewBox', '0 0 800 0').split(' ')[2]) + 5.0)
- text_container = etree.Element(
- SVG_TEXT_TAG,
- {
- "x": text_x,
- "y": str(5),
- "style": "fill:#000000;font-size:5px;line-height:1;"
- }
- )
+ text_container = inkex.TextElement(attrib={
+ "x": text_x,
+ "y": str(5),
+ "style": "fill:#000000;font-size:5px;line-height:1;"
+ })
self.troubleshoot_layer.append(text_container)
text = [
@@ -180,9 +158,8 @@ class Troubleshoot(InkstitchExtension):
elif problem_type == "type_warning":
text_color = "#ff9900"
problem_type_header = _("Object Type Warnings")
- problem_type_description = _("Ink/Stitch only knows how to works with paths and ignores everything else. "
- "You might want these shapes to be ignored, but if you don't, "
- "follow the instructions to change this behaviour.")
+ problem_type_description = _("These objects may not work properly with Ink/Stitch. "
+ "Follow the instructions to correct unwanted behaviour.")
if problems:
text.append([problem_type_header, "font-weight: bold; fill: %s; text-decoration: underline; font-size: 7px;" % text_color])
text.append(["", ""])
@@ -208,13 +185,10 @@ class Troubleshoot(InkstitchExtension):
text = self.split_text(text)
for text_line in text:
- tspan = etree.Element(
- SVG_TSPAN_TAG,
- {
- SODIPODI_ROLE: "line",
- "style": text_line[1]
- }
- )
+ tspan = inkex.Tspan(attrib={
+ SODIPODI_ROLE: "line",
+ "style": text_line[1]
+ })
tspan.text = text_line[0]
text_container.append(tspan)