summaryrefslogtreecommitdiff
path: root/lib/extensions
diff options
context:
space:
mode:
Diffstat (limited to 'lib/extensions')
-rw-r--r--lib/extensions/base.py19
-rw-r--r--lib/extensions/convert_to_satin.py20
-rw-r--r--lib/extensions/input.py2
-rw-r--r--lib/extensions/layer_commands.py22
-rw-r--r--lib/extensions/lettering.py12
-rw-r--r--lib/extensions/troubleshoot.py117
6 files changed, 68 insertions, 124 deletions
diff --git a/lib/extensions/base.py b/lib/extensions/base.py
index 8d5cccad..dc71d922 100644
--- a/lib/extensions/base.py
+++ b/lib/extensions/base.py
@@ -49,19 +49,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.
@@ -149,7 +137,8 @@ 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, SVG_GROUP_TAG] and
+ element.get_style('display', 'inline') is None):
return []
if node.tag == SVG_DEFS_TAG:
@@ -211,7 +200,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/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/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/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 7ee162ea..75a18b24 100644
--- a/lib/extensions/lettering.py
+++ b/lib/extensions/lettering.py
@@ -12,8 +12,9 @@ import appdirs
import inkex
import wx
import wx.adv
-from lxml import etree
+from .commands import CommandsExtension
+from .lettering_custom_font_dir import get_custom_font_dir
from ..elements import nodes_to_elements
from ..gui import PresetsPanel, SimulatorPreview, info_dialog
from ..i18n import _
@@ -22,8 +23,6 @@ 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 .commands import CommandsExtension
-from .lettering_custom_font_dir import get_custom_font_dir
class LetteringFrame(wx.Frame):
@@ -258,12 +257,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:
@@ -414,10 +414,12 @@ class Lettering(CommandsExtension):
else:
return list(groups)[0]
else:
- return etree.SubElement(self.get_current_layer(), SVG_GROUP_TAG, {
+ group = inkex.Group(attrib={
INKSCAPE_LABEL: _("Ink/Stitch Lettering"),
"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/troubleshoot.py b/lib/extensions/troubleshoot.py
index 8e37acc3..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,31 +64,25 @@ 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
@@ -102,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
@@ -153,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 = [
@@ -209,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)