summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/debug/__init__.py7
-rw-r--r--lib/debug/utils.py2
-rw-r--r--lib/elements/element.py7
-rw-r--r--lib/elements/fill_stitch.py9
-rw-r--r--lib/elements/satin_column.py2
-rw-r--r--lib/extensions/gradient_blocks.py32
-rw-r--r--lib/extensions/print_pdf.py2
-rw-r--r--lib/gui/simulator.py2
-rw-r--r--lib/stitch_plan/lock_stitch.py2
-rw-r--r--lib/stitches/auto_fill.py2
-rw-r--r--lib/stitches/guided_fill.py2
-rw-r--r--lib/stitches/meander_fill.py2
-rw-r--r--lib/tiles.py2
-rw-r--r--lib/utils/smoothing.py2
-rw-r--r--lib/utils/threading.py2
15 files changed, 37 insertions, 40 deletions
diff --git a/lib/debug/__init__.py b/lib/debug/__init__.py
index 8093e6a0..3973c45a 100644
--- a/lib/debug/__init__.py
+++ b/lib/debug/__init__.py
@@ -2,10 +2,3 @@
#
# Copyright (c) 2010 Authors
# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details.
-
-
-# this enable:
-# from .debug import debug
-# from ..debug import debug
-from .debug import debug
-
diff --git a/lib/debug/utils.py b/lib/debug/utils.py
index 9618d173..10d840d9 100644
--- a/lib/debug/utils.py
+++ b/lib/debug/utils.py
@@ -5,7 +5,7 @@
# this file is without: import inkex
# - we need dump argv and sys.path as is on startup from inkscape
-# - later sys.path may be modified that influences importing inkex (see prefere_pip_inkex)
+# - later sys.path may be modified that influences importing inkex (see prefer_pip_inkex)
import os
import sys
diff --git a/lib/elements/element.py b/lib/elements/element.py
index c4e1d640..5c463c53 100644
--- a/lib/elements/element.py
+++ b/lib/elements/element.py
@@ -11,7 +11,7 @@ import numpy as np
from inkex import bezier, BaseElement
from ..commands import find_commands
-from ..debug import debug
+from ..debug.debug import debug
from ..exceptions import InkstitchException, format_uncaught_exception
from ..i18n import _
from ..marker import get_marker_elements_cache_key_data
@@ -169,9 +169,12 @@ class EmbroideryElement(object):
return self.node.specified_style()
def get_style(self, style_name, default=None):
- style = self._get_specified_style().get(style_name, default)
+ element_style = self._get_specified_style()
+ style = element_style.get(style_name, default)
if style == 'none':
style = None
+ elif style == 'currentColor':
+ style = element_style(style_name)
return style
@property
diff --git a/lib/elements/fill_stitch.py b/lib/elements/fill_stitch.py
index 47155ce0..6bf52d95 100644
--- a/lib/elements/fill_stitch.py
+++ b/lib/elements/fill_stitch.py
@@ -7,7 +7,7 @@ import math
import re
import numpy as np
-from inkex import Transform
+from inkex import LinearGradient, Transform
from shapely import geometry as shgeo
from shapely.errors import GEOSException
from shapely.ops import nearest_points
@@ -588,9 +588,10 @@ class FillStitch(EmbroideryElement):
@property
def gradient(self):
- color = self.color[5:-1]
- xpath = f'.//svg:defs/svg:linearGradient[@id="{color}"]'
- return self.node.getroottree().getroot().findone(xpath)
+ gradient = self.node.get_computed_style("fill")
+ if isinstance(gradient, LinearGradient):
+ return gradient
+ return None
@property
@param('fill_underlay', _('Underlay'), type='toggle', group=_('Fill Underlay'), default=True)
diff --git a/lib/elements/satin_column.py b/lib/elements/satin_column.py
index 9cf7bc73..6acb2f52 100644
--- a/lib/elements/satin_column.py
+++ b/lib/elements/satin_column.py
@@ -14,7 +14,7 @@ from shapely import affinity as shaffinity
from shapely import geometry as shgeo
from shapely.ops import nearest_points
-from ..debug import debug
+from ..debug.debug import debug
from ..i18n import _
from ..metadata import InkStitchMetadata
from ..stitch_plan import StitchGroup
diff --git a/lib/extensions/gradient_blocks.py b/lib/extensions/gradient_blocks.py
index f94582f0..d0eca4a4 100644
--- a/lib/extensions/gradient_blocks.py
+++ b/lib/extensions/gradient_blocks.py
@@ -5,7 +5,8 @@
from math import degrees, pi
-from inkex import DirectedLineSegment, PathElement, Transform, errormsg
+from inkex import (DirectedLineSegment, LinearGradient, PathElement, Transform,
+ errormsg)
from shapely import geometry as shgeo
from shapely.affinity import rotate
from shapely.geometry import Point
@@ -42,7 +43,7 @@ class GradientBlocks(CommandsExtension):
if not self.get_elements():
return
- elements = [element for element in self.elements if (isinstance(element, FillStitch) and self.has_gradient_color(element))]
+ elements = [element for element in self.elements if isinstance(element, FillStitch) and isinstance(element.gradient, LinearGradient)]
if not elements:
errormsg(_("Please select at least one object with a gradient fill."))
return
@@ -97,21 +98,22 @@ class GradientBlocks(CommandsExtension):
block.set('inkstitch:fill_underlay_row_spacing_mm', end_row_spacing)
parent.insert(index, block)
-
if previous_color == color:
- current = FillStitch(block)
- previous = FillStitch(previous_element)
- nearest = nearest_points(current.shape, previous.shape)
- pos_current = self._get_command_postion(current, nearest[0])
- pos_previous = self._get_command_postion(previous, nearest[1])
- add_commands(current, ['fill_end'], pos_current)
- add_commands(previous, ['fill_start'], pos_previous)
+ self._add_block_commands(block, previous_element)
previous_color = color
previous_element = block
parent.remove(element.node)
- def has_gradient_color(self, element):
- return element.color.startswith('url') and "linearGradient" in element.color
+ def _add_block_commands(self, block, previous_element):
+ current = FillStitch(block)
+ previous = FillStitch(previous_element)
+ if previous.shape.is_empty:
+ return
+ nearest = nearest_points(current.shape, previous.shape)
+ pos_current = self._get_command_postion(current, nearest[0])
+ pos_previous = self._get_command_postion(previous, nearest[1])
+ add_commands(current, ['fill_end'], pos_current)
+ add_commands(previous, ['fill_start'], pos_previous)
def _get_command_postion(self, fill, point):
center = fill.shape.centroid
@@ -129,9 +131,7 @@ class GradientBlocks(CommandsExtension):
def gradient_shapes_and_attributes(element, shape, unit_multiplier):
# e.g. url(#linearGradient872) -> linearGradient872
- color = element.color[5:-1]
- xpath = f'.//svg:defs/svg:linearGradient[@id="{color}"]'
- gradient = element.node.getroottree().getroot().findone(xpath)
+ gradient = element.gradient
gradient.apply_transform()
point1 = (float(gradient.get('x1')), float(gradient.get('y1')))
point2 = (float(gradient.get('x2')), float(gradient.get('y2')))
@@ -170,7 +170,7 @@ def gradient_shapes_and_attributes(element, shape, unit_multiplier):
# does this gradient line split the shape
offset_outside_shape = len(polygon.geoms) == 1
for poly in polygon.geoms:
- if isinstance(poly, shgeo.Polygon) and element.shape_is_valid(poly):
+ if isinstance(poly, shgeo.Polygon) and poly.is_valid:
if poly.intersects(offset_line):
if previous_color:
polygons.append(poly)
diff --git a/lib/extensions/print_pdf.py b/lib/extensions/print_pdf.py
index 640a168b..257d746a 100644
--- a/lib/extensions/print_pdf.py
+++ b/lib/extensions/print_pdf.py
@@ -22,7 +22,7 @@ from lxml import etree
from werkzeug.serving import make_server
from .base import InkstitchExtension
-from ..debug import debug
+from ..debug.debug import debug
from ..i18n import _, get_languages
from ..i18n import translation as inkstitch_translation
from ..stitch_plan import stitch_groups_to_stitch_plan
diff --git a/lib/gui/simulator.py b/lib/gui/simulator.py
index a8e917b4..e0808d6f 100644
--- a/lib/gui/simulator.py
+++ b/lib/gui/simulator.py
@@ -11,7 +11,7 @@ import wx
from numpy import split
from wx.lib.intctrl import IntCtrl
-from lib.debug import debug
+from lib.debug.debug import debug
from lib.utils import get_resource_dir
from lib.utils.settings import global_settings
from lib.utils.threading import ExitThread
diff --git a/lib/stitch_plan/lock_stitch.py b/lib/stitch_plan/lock_stitch.py
index 788e6377..e05764de 100644
--- a/lib/stitch_plan/lock_stitch.py
+++ b/lib/stitch_plan/lock_stitch.py
@@ -4,7 +4,7 @@ from math import degrees
from inkex import DirectedLineSegment, Path
from shapely.geometry import LineString
-from ..debug import debug
+from ..debug.debug import debug
from ..i18n import _
from ..svg import PIXELS_PER_MM
from ..utils import string_to_floats
diff --git a/lib/stitches/auto_fill.py b/lib/stitches/auto_fill.py
index 159a869b..85543cea 100644
--- a/lib/stitches/auto_fill.py
+++ b/lib/stitches/auto_fill.py
@@ -16,7 +16,7 @@ from shapely.ops import snap
from shapely.strtree import STRtree
-from ..debug import debug
+from ..debug.debug import debug
from ..stitch_plan import Stitch
from ..svg import PIXELS_PER_MM
from ..utils import cache
diff --git a/lib/stitches/guided_fill.py b/lib/stitches/guided_fill.py
index 1b564bcb..f170f024 100644
--- a/lib/stitches/guided_fill.py
+++ b/lib/stitches/guided_fill.py
@@ -10,7 +10,7 @@ from shapely.ops import linemerge, nearest_points, unary_union
from lib.utils import prng
-from ..debug import debug
+from ..debug.debug import debug
from ..stitch_plan import Stitch
from ..utils.geometry import Point as InkstitchPoint
from ..utils.geometry import (ensure_geometry_collection,
diff --git a/lib/stitches/meander_fill.py b/lib/stitches/meander_fill.py
index 94e38e1f..77a899c9 100644
--- a/lib/stitches/meander_fill.py
+++ b/lib/stitches/meander_fill.py
@@ -5,7 +5,7 @@ from shapely.geometry import LineString, MultiPoint, Point
from shapely.ops import nearest_points
from .. import tiles
-from ..debug import debug
+from ..debug.debug import debug
from ..i18n import _
from ..utils.clamp_path import clamp_path_to_polygon
from ..utils.geometry import Point as InkStitchPoint
diff --git a/lib/tiles.py b/lib/tiles.py
index 00d837b3..30b1b2ed 100644
--- a/lib/tiles.py
+++ b/lib/tiles.py
@@ -8,7 +8,7 @@ import networkx as nx
from shapely.geometry import LineString, MultiLineString
from shapely.prepared import prep
-from .debug import debug
+from .debug.debug import debug
from .i18n import _
from .svg import apply_transforms
from .utils import Point, cache, get_bundled_dir, guess_inkscape_config_path
diff --git a/lib/utils/smoothing.py b/lib/utils/smoothing.py
index 49771b6c..0300f6f1 100644
--- a/lib/utils/smoothing.py
+++ b/lib/utils/smoothing.py
@@ -33,7 +33,7 @@ def smooth_path(path, smoothness=1.0):
Returns:
A list of Points.
"""
- from ..debug import debug
+ from ..debug.debug import debug
if smoothness == 0:
# s of exactly zero seems to indicate a default level of smoothing
diff --git a/lib/utils/threading.py b/lib/utils/threading.py
index f774dcbe..2a95e857 100644
--- a/lib/utils/threading.py
+++ b/lib/utils/threading.py
@@ -1,7 +1,7 @@
import threading
from ..exceptions import InkstitchException
-from ..debug import debug
+from ..debug.debug import debug
class ExitThread(InkstitchException):