summaryrefslogtreecommitdiff
path: root/lib/extensions/satin_multicolor.py
blob: ad2178bb32335f399042d05c73e857e0cdec4019 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# Authors: see git history
#
# Copyright (c) 2023 Authors
# Licensed under the GNU GPL version 3.0 or later.  See the file LICENSE for details.

import sys

import wx
import wx.adv

from ..elements import SatinColumn
from ..gui.abort_message import AbortMessageApp
from ..gui.satin_multicolor import MultiColorSatinPanel
from ..gui.simulator import SplitSimulatorWindow
from ..i18n import _
from ..utils.svg_data import get_pagecolor
from .base import InkstitchExtension


class SatinMulticolor(InkstitchExtension):
    def __init__(self, *args, **kwargs):
        self.elements = set()
        self.cancelled = False
        InkstitchExtension.__init__(self, *args, **kwargs)

    def cancel(self):
        self.cancelled = True

    def effect(self):
        self.get_elements()
        satins = [element for element in self.elements if isinstance(element, SatinColumn)]
        if not satins:
            app = AbortMessageApp(
                _("Please select at least one satin column."),
                _("https://inkstitch.org/docs/satin-tools/#multicolor-satin")
            )
            app.MainLoop()
            return

        metadata = self.get_inkstitch_metadata()
        background_color = get_pagecolor(self.svg.namedview)

        app = wx.App()
        frame = SplitSimulatorWindow(
            title=_("Ink/Stitch Multicolor Satin"),
            panel_class=MultiColorSatinPanel,
            elements=satins,
            on_cancel=self.cancel,
            metadata=metadata,
            background_color=background_color,
            target_duration=1
        )

        frame.Show()
        app.MainLoop()

        if self.cancelled:
            # This prevents the superclass from outputting the SVG, because we
            # may have modified the DOM.
            sys.exit(0)