Skip to content

Commit 8cbebd1

Browse files
committed
avoid repeatedly changing colour to same colour
1 parent 721611d commit 8cbebd1

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/turtlethread/stitches.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,12 @@ def to_pyembroidery(self) -> pyembroidery.EmbPattern:
4040
pattern = pyembroidery.EmbPattern()
4141
for stitch_group in self.stitch_groups:
4242
if (not isinstance(stitch_group, JumpStitch)) and stitch_group.color is not None:
43-
pattern += stitch_group.color
43+
change_col = True
44+
if len(pattern.threadlist) > 0:
45+
change_col = (pattern.threadlist[-1].hex_color() != pyembroidery.EmbThread(stitch_group.color).hex_color())
46+
47+
if change_col:
48+
pattern += stitch_group.color
4449

4550
scaled_stitch_commands = (
4651
(x * self.scale, y * self.scale, cmd) for x, y, cmd in stitch_group.get_stitch_commands()

src/turtlethread/turtle.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,8 @@ def end_fill(self):
617617

618618

619619
def color(self, newcol: str):
620+
if newcol == self.curr_color:
621+
return # make no change, to avoid asking the user to repeatedly change thread
620622
# We need to change the stitch group so that the color change is reflected!
621623
if self._stitch_group_stack:
622624
previous_stitch_group = self._stitch_group_stack.pop()

0 commit comments

Comments
 (0)