diff options
| author | Lex Neva <lexelby@users.noreply.github.com> | 2018-08-17 16:21:58 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-08-17 16:21:58 -0400 |
| commit | f0bd1404ad078a71eb3bca1a9fef7858e709ec0c (patch) | |
| tree | 2075fc0292038b4a2e92fc018b503805cf30fdec /lib/extensions/layer_commands.py | |
| parent | ece81d0c91c8b96f7da2c0339f6807a47d57112e (diff) | |
| parent | 0e4c3a3f1b76c1b655ec2788017335e87eff29da (diff) | |
Merge pull request #243 from inkstitch/lexelby-no-embroider-command
"ignore" command
Diffstat (limited to 'lib/extensions/layer_commands.py')
| -rw-r--r-- | lib/extensions/layer_commands.py | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/lib/extensions/layer_commands.py b/lib/extensions/layer_commands.py new file mode 100644 index 00000000..88170f66 --- /dev/null +++ b/lib/extensions/layer_commands.py @@ -0,0 +1,48 @@ +import os +import sys +import inkex + +from .commands import CommandsExtension +from ..i18n import _ +from ..svg.tags import SVG_USE_TAG, XLINK_HREF +from ..svg import get_correction_transform + + +class LayerCommands(CommandsExtension): + COMMANDS = ["ignore_layer"] + + def ensure_current_layer(self): + # if no layer is selected, inkex defaults to the root, which isn't + # particularly useful + if self.current_layer is self.document.getroot(): + try: + self.current_layer = self.document.xpath(".//svg:g[@inkscape:groupmode='layer']", namespaces=inkex.NSS)[0] + except IndexError: + # No layers at all?? Fine, we'll stick with the default. + pass + + 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 + + self.ensure_current_layer() + correction_transform = get_correction_transform(self.current_layer, child=True) + + for i, command in enumerate(commands): + self.ensure_symbol(command) + + node = inkex.etree.SubElement(self.current_layer, SVG_USE_TAG, + { + "id": self.uniqueId("use"), + XLINK_HREF: "#inkstitch_%s" % command, + "height": "100%", + "width": "100%", + "x": str(i * 20), + "y": "-10", + "transform": correction_transform + }) + + namedview = self.document.xpath("//sodipodi:namedview", namespaces=inkex.NSS) |
