diff options
Diffstat (limited to 'lib/extensions')
| -rw-r--r-- | lib/extensions/__init__.py | 10 | ||||
| -rw-r--r-- | lib/extensions/base.py | 5 | ||||
| -rw-r--r-- | lib/extensions/layer_commands.py | 6 | ||||
| -rw-r--r-- | lib/extensions/object_commands.py | 25 |
4 files changed, 38 insertions, 8 deletions
diff --git a/lib/extensions/__init__.py b/lib/extensions/__init__.py index 6c8db318..1606795c 100644 --- a/lib/extensions/__init__.py +++ b/lib/extensions/__init__.py @@ -10,3 +10,13 @@ from flip import Flip from object_commands import ObjectCommands from layer_commands import LayerCommands from convert_to_satin import ConvertToSatin + +from base import InkstitchExtension +import inspect + +extensions = [] +for item in locals().values(): + if inspect.isclass(item) and \ + issubclass(item, InkstitchExtension) and \ + item is not InkstitchExtension: + extensions.append(item) diff --git a/lib/extensions/base.py b/lib/extensions/base.py index 571e3c2d..1794b68c 100644 --- a/lib/extensions/base.py +++ b/lib/extensions/base.py @@ -3,6 +3,7 @@ import re import json from copy import deepcopy from collections import MutableMapping +from stringcase import snakecase from ..svg.tags import * from ..elements import AutoFill, Fill, Stroke, SatinColumn, Polyline, EmbroideryElement @@ -98,6 +99,10 @@ class InkStitchMetadata(MutableMapping): class InkstitchExtension(inkex.Effect): """Base class for Inkstitch extensions. Not intended for direct use.""" + @classmethod + def name(cls): + return snakecase(cls.__name__) + def hide_all_layers(self): for g in self.document.getroot().findall(SVG_GROUP_TAG): if g.get(INKSCAPE_GROUPMODE) == "layer": diff --git a/lib/extensions/layer_commands.py b/lib/extensions/layer_commands.py index 88170f66..576af044 100644 --- a/lib/extensions/layer_commands.py +++ b/lib/extensions/layer_commands.py @@ -3,13 +3,14 @@ import sys import inkex from .commands import CommandsExtension +from ..commands import LAYER_COMMANDS, get_command_description from ..i18n import _ -from ..svg.tags import SVG_USE_TAG, XLINK_HREF +from ..svg.tags import * from ..svg import get_correction_transform class LayerCommands(CommandsExtension): - COMMANDS = ["ignore_layer"] + COMMANDS = LAYER_COMMANDS def ensure_current_layer(self): # if no layer is selected, inkex defaults to the root, which isn't @@ -37,6 +38,7 @@ class LayerCommands(CommandsExtension): node = inkex.etree.SubElement(self.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%", diff --git a/lib/extensions/object_commands.py b/lib/extensions/object_commands.py index 27a07969..e9ee6063 100644 --- a/lib/extensions/object_commands.py +++ b/lib/extensions/object_commands.py @@ -7,14 +7,15 @@ from random import random from shapely import geometry as shgeo from .commands import CommandsExtension +from ..commands import OBJECT_COMMANDS, get_command_description from ..i18n import _ from ..elements import SatinColumn -from ..svg.tags import SVG_GROUP_TAG, SVG_USE_TAG, SVG_PATH_TAG, INKSCAPE_GROUPMODE, XLINK_HREF, CONNECTION_START, CONNECTION_END, CONNECTOR_TYPE +from ..svg.tags import * from ..svg import get_correction_transform class ObjectCommands(CommandsExtension): - COMMANDS = ["fill_start", "fill_end", "stop", "trim", "ignore_object"] + COMMANDS = OBJECT_COMMANDS def add_connector(self, symbol, element): # I'd like it if I could position the connector endpoint nicely but inkscape just @@ -27,14 +28,16 @@ class ObjectCommands(CommandsExtension): "id": self.uniqueId("connector"), "d": "M %s,%s %s,%s" % (start_pos[0], start_pos[1], end_pos.x, end_pos.y), "style": "stroke:#000000;stroke-width:1px;stroke-opacity:0.5;fill:none;", - "transform": get_correction_transform(symbol), CONNECTION_START: "#%s" % symbol.get('id'), CONNECTION_END: "#%s" % element.node.get('id'), CONNECTOR_TYPE: "polyline", + + # l10n: the name of the line that connects a command to the object it applies to + INKSCAPE_LABEL: _("connector") } ) - symbol.getparent().insert(symbol.getparent().index(symbol), path) + symbol.getparent().insert(0, path) def get_command_pos(self, element, index, total): # Put command symbols 30 pixels out from the shape, spaced evenly around it. @@ -71,7 +74,15 @@ class ObjectCommands(CommandsExtension): pos = self.get_command_pos(element, i, len(commands)) - symbol = inkex.etree.SubElement(element.node.getparent(), SVG_USE_TAG, + group = inkex.etree.SubElement(element.node.getparent(), SVG_GROUP_TAG, + { + "id": self.uniqueId("group"), + INKSCAPE_LABEL: _("Ink/Stitch Command") + ": %s" % get_command_description(command), + "transform": get_correction_transform(element.node) + } + ) + + symbol = inkex.etree.SubElement(group, SVG_USE_TAG, { "id": self.uniqueId("use"), XLINK_HREF: "#inkstitch_%s" % command, @@ -79,7 +90,9 @@ class ObjectCommands(CommandsExtension): "width": "100%", "x": str(pos.x), "y": str(pos.y), - "transform": get_correction_transform(element.node) + + # l10n: the name of a command symbol (example: scissors icon for trim command) + INKSCAPE_LABEL: _("command marker"), } ) |
