2021-03-12 04:17:19 +00:00
|
|
|
# Authors: see git history
|
|
|
|
#
|
|
|
|
# Copyright (c) 2010 Authors
|
|
|
|
# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details.
|
|
|
|
|
2018-12-16 01:21:41 +00:00
|
|
|
import sys
|
|
|
|
|
2022-10-23 07:17:17 +00:00
|
|
|
import inkex
|
2018-12-16 01:21:41 +00:00
|
|
|
import wx
|
2021-02-04 15:40:02 +00:00
|
|
|
import wx.adv
|
2022-04-24 06:27:42 +00:00
|
|
|
|
2024-08-17 15:29:54 +00:00
|
|
|
from ..gui.abort_message import AbortMessageApp
|
2023-12-26 09:11:38 +00:00
|
|
|
from ..gui.lettering import LetteringPanel
|
2023-10-21 16:16:34 +00:00
|
|
|
from ..gui.simulator import SplitSimulatorWindow
|
2018-11-15 01:23:06 +00:00
|
|
|
from ..i18n import _
|
2019-01-08 00:55:05 +00:00
|
|
|
from ..svg import get_correction_transform
|
2023-12-26 09:11:38 +00:00
|
|
|
from ..svg.tags import INKSCAPE_LABEL, INKSTITCH_LETTERING, SVG_GROUP_TAG
|
2024-04-30 18:21:32 +00:00
|
|
|
from ..utils.svg_data import get_pagecolor
|
2023-12-26 09:11:38 +00:00
|
|
|
from .commands import CommandsExtension
|
2018-12-16 01:21:41 +00:00
|
|
|
|
|
|
|
|
2018-11-15 01:23:06 +00:00
|
|
|
class Lettering(CommandsExtension):
|
|
|
|
COMMANDS = ["trim"]
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
2018-12-16 01:21:41 +00:00
|
|
|
self.cancelled = False
|
2018-11-15 01:23:06 +00:00
|
|
|
CommandsExtension.__init__(self, *args, **kwargs)
|
|
|
|
|
2018-12-16 01:21:41 +00:00
|
|
|
def cancel(self):
|
|
|
|
self.cancelled = True
|
2018-11-15 01:23:06 +00:00
|
|
|
|
2018-12-16 01:21:41 +00:00
|
|
|
def get_or_create_group(self):
|
2022-04-24 06:27:42 +00:00
|
|
|
if self.svg.selection:
|
2018-12-16 01:21:41 +00:00
|
|
|
groups = set()
|
|
|
|
|
2022-04-24 06:27:42 +00:00
|
|
|
for node in self.svg.selection:
|
2018-12-16 01:21:41 +00:00
|
|
|
if node.tag == SVG_GROUP_TAG and INKSTITCH_LETTERING in node.attrib:
|
|
|
|
groups.add(node)
|
|
|
|
|
|
|
|
for group in node.iterancestors(SVG_GROUP_TAG):
|
|
|
|
if INKSTITCH_LETTERING in group.attrib:
|
|
|
|
groups.add(group)
|
2018-11-15 01:23:06 +00:00
|
|
|
|
2018-12-16 01:21:41 +00:00
|
|
|
if len(groups) > 1:
|
2024-08-17 15:29:54 +00:00
|
|
|
app = AbortMessageApp(
|
|
|
|
_("Please select only one block of text."),
|
|
|
|
_("https://inkstitch.org/docs/lettering/#lettering-tool")
|
|
|
|
)
|
|
|
|
app.MainLoop()
|
2018-12-16 01:21:41 +00:00
|
|
|
sys.exit(1)
|
|
|
|
elif len(groups) == 0:
|
2023-06-04 11:39:38 +00:00
|
|
|
return self.create_group()
|
2018-12-16 01:21:41 +00:00
|
|
|
else:
|
|
|
|
return list(groups)[0]
|
|
|
|
else:
|
2023-06-04 11:39:38 +00:00
|
|
|
return self.create_group()
|
|
|
|
|
|
|
|
def create_group(self):
|
|
|
|
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
|
2018-12-16 01:21:41 +00:00
|
|
|
|
|
|
|
def effect(self):
|
2023-04-08 17:14:38 +00:00
|
|
|
metadata = self.get_inkstitch_metadata()
|
2024-04-30 18:21:32 +00:00
|
|
|
background_color = get_pagecolor(self.svg.namedview)
|
2018-12-16 01:21:41 +00:00
|
|
|
app = wx.App()
|
2023-10-21 16:16:34 +00:00
|
|
|
frame = SplitSimulatorWindow(
|
|
|
|
title=_("Ink/Stitch Lettering"),
|
|
|
|
panel_class=LetteringPanel,
|
|
|
|
group=self.get_or_create_group(),
|
|
|
|
on_cancel=self.cancel,
|
|
|
|
metadata=metadata,
|
2024-04-30 18:21:32 +00:00
|
|
|
background_color=background_color,
|
2023-10-21 16:16:34 +00:00
|
|
|
target_duration=1
|
|
|
|
)
|
2018-11-15 01:23:06 +00:00
|
|
|
|
2018-12-16 01:21:41 +00:00
|
|
|
frame.Show()
|
|
|
|
app.MainLoop()
|
2018-11-15 01:23:06 +00:00
|
|
|
|
2018-12-16 01:21:41 +00:00
|
|
|
if self.cancelled:
|
|
|
|
# This prevents the superclass from outputting the SVG, because we
|
|
|
|
# may have modified the DOM.
|
|
|
|
sys.exit(0)
|