summaryrefslogtreecommitdiff
path: root/lib/threads
diff options
context:
space:
mode:
authorKaalleen <36401965+kaalleen@users.noreply.github.com>2025-07-11 22:14:52 +0200
committerGitHub <noreply@github.com>2025-07-11 22:14:52 +0200
commit2235ec6571601e12be7eb3c74907668fb68bebd4 (patch)
tree61d85cb615a1b2327283e89f09592e1eb85ad91c /lib/threads
parent7bd72274780ccaeae8bbae6e761341079df21ecb (diff)
Fix issue with bad color names (#3816)
* fix issue with bad color names and define element colors at one place and reuse * fix bad tartan color * verify color in gradient block * add thread color tests * use default color behavior for elements linked to non-existing definitions (gradients) * Added mypy change for tests (authored by: CapellanCitizen)
Diffstat (limited to 'lib/threads')
-rw-r--r--lib/threads/color.py31
1 files changed, 20 insertions, 11 deletions
diff --git a/lib/threads/color.py b/lib/threads/color.py
index 699f4448..335dc32b 100644
--- a/lib/threads/color.py
+++ b/lib/threads/color.py
@@ -5,19 +5,20 @@
import colorsys
-from inkex import Color
+from inkex import Color, ColorError
+
from pyembroidery.EmbThread import EmbThread
class ThreadColor(object):
def __init__(self, color, name=None, number=None, manufacturer=None, description=None, chart=None):
- '''
- avoid error messages:
- * set colors with a gradient to black
- * currentColor/context-fill/context-stroke: should not just be black, but we want to avoid
- error messages until inkex will be able to handle these css properties
- '''
- if isinstance(color, str) and color.startswith(('url', 'currentColor', 'context')):
+ self.rgb = None
+
+ if isinstance(color, str) and color.lower().startswith(('url', 'currentcolor', 'context')):
+ '''
+ Avoid error messages for currentcolor, context-fill, context-stroke and every string starting with an url.
+ they should not just be black, but we want to avoid error messages
+ '''
color = None
elif isinstance(color, str) and color.startswith('rgb'):
color = tuple(int(value) for value in color[4:-1].split(','))
@@ -33,11 +34,19 @@ class ThreadColor(object):
self.rgb = (color.get_red(), color.get_green(), color.get_blue())
return
elif isinstance(color, str):
- self.rgb = tuple(Color(color).to('rgb'))
+ try:
+ self.rgb = tuple(Color(color).to('rgb'))
+ except ColorError:
+ self.rgb = None
elif isinstance(color, (list, tuple)):
self.rgb = tuple(color)
- else:
- raise ValueError("Invalid color: " + repr(color))
+
+ if self.rgb is None:
+ '''
+ Instead of erroring out, we want to set everything to black at this point.
+ This includes for example patterns and gradients
+ '''
+ self.rgb = (0, 0, 0)
self.name = name
self.number = number