2018-08-17 02:50:34 +00:00
|
|
|
import inkex
|
2021-03-04 17:40:53 +00:00
|
|
|
from lxml import etree
|
2018-08-17 02:50:34 +00:00
|
|
|
|
2021-03-04 17:40:53 +00:00
|
|
|
from ..commands import LAYER_COMMANDS, ensure_symbol, get_command_description
|
2018-08-17 02:50:34 +00:00
|
|
|
from ..i18n import _
|
|
|
|
from ..svg import get_correction_transform
|
2021-03-04 17:40:53 +00:00
|
|
|
from ..svg.tags import INKSCAPE_LABEL, SVG_USE_TAG, XLINK_HREF
|
2018-11-15 01:23:06 +00:00
|
|
|
from .commands import CommandsExtension
|
2018-08-17 02:50:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
class LayerCommands(CommandsExtension):
|
2018-08-18 03:02:27 +00:00
|
|
|
COMMANDS = LAYER_COMMANDS
|
2018-08-17 02:50:34 +00:00
|
|
|
|
|
|
|
def effect(self):
|
|
|
|
commands = [command for command in self.COMMANDS if getattr(self.options, command)]
|
|
|
|
|
|
|
|
if not commands:
|
|
|
|
inkex.errormsg(_("Please choose one or more commands to add."))
|
|
|
|
return
|
|
|
|
|
2021-03-04 17:40:53 +00:00
|
|
|
correction_transform = get_correction_transform(self.svg.get_current_layer(), child=True)
|
2018-08-17 02:50:34 +00:00
|
|
|
|
|
|
|
for i, command in enumerate(commands):
|
2019-07-06 08:18:01 +00:00
|
|
|
ensure_symbol(self.document, command)
|
2018-08-17 02:50:34 +00:00
|
|
|
|
2021-03-04 17:40:53 +00:00
|
|
|
etree.SubElement(self.svg.get_current_layer(), SVG_USE_TAG,
|
|
|
|
{
|
|
|
|
"id": self.uniqueId("use"),
|
|
|
|
INKSCAPE_LABEL: _("Ink/Stitch Command") + ": %s" % get_command_description(command),
|
|
|
|
XLINK_HREF: "#inkstitch_%s" % command,
|
|
|
|
"height": "100%",
|
|
|
|
"width": "100%",
|
|
|
|
"x": str(i * 20),
|
|
|
|
"y": "-10",
|
|
|
|
"transform": correction_transform
|
|
|
|
})
|