From 13016f50ecace38a93f7d8e55bdad8b21fb0d2c7 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Fri, 17 Aug 2018 20:55:43 -0400 Subject: group symbol+connector and label with command description --- lib/commands.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'lib/commands.py') diff --git a/lib/commands.py b/lib/commands.py index cadfa080..5a471c2e 100644 --- a/lib/commands.py +++ b/lib/commands.py @@ -3,13 +3,42 @@ import cubicsuperpath from .svg import apply_transforms from .svg.tags import SVG_USE_TAG, SVG_SYMBOL_TAG, CONNECTION_START, CONNECTION_END, XLINK_HREF +from .utils import cache +from .i18n import _ +COMMANDS = { + # l10n: command attached to an object + "fill_start": _("Fill stitch starting position"), + + # l10n: command attached to an object + "fill_end": _("Fill stitch ending position"), + + # l10n: command attached to an object + "stop": _("Stop (pause machine) after sewing this object"), + + # l10n: command attached to an object + "trim": _("Trim thread after sewing this object"), + + # l10n: command attached to an object + "ignore_object": _("Ignore this object (do not stitch)"), + + # l10n: command that affects entire layer + "ignore_layer": _("Ignore layer (do not stitch any objects in this layer)") +} + +OBJECT_COMMANDS = [ "fill_start", "fill_end", "stop", "trim", "ignore_object" ] +LAYER_COMMANDS = [ "ignore_layer" ] class CommandParseError(Exception): pass class BaseCommand(object): + @property + @cache + def description(self): + return get_command_description(self.command) + def parse_symbol(self): if self.symbol.tag != SVG_SYMBOL_TAG: raise CommandParseError("use points to non-symbol") @@ -87,6 +116,9 @@ class StandaloneCommand(BaseCommand): self.parse_symbol() +def get_command_description(command): + return COMMANDS[command] + def find_commands(node): """Find the symbols this node is connected to and return them as Commands""" -- cgit v1.2.3 From 871358d990d4a06b2eaaf0e405f2d18e26753d52 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Mon, 20 Aug 2018 15:49:19 -0400 Subject: gettextify INX templates --- lib/commands.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'lib/commands.py') diff --git a/lib/commands.py b/lib/commands.py index 5a471c2e..214b5f40 100644 --- a/lib/commands.py +++ b/lib/commands.py @@ -4,26 +4,26 @@ import cubicsuperpath from .svg import apply_transforms from .svg.tags import SVG_USE_TAG, SVG_SYMBOL_TAG, CONNECTION_START, CONNECTION_END, XLINK_HREF from .utils import cache -from .i18n import _ +from .i18n import _, N_ COMMANDS = { - # l10n: command attached to an object - "fill_start": _("Fill stitch starting position"), + # L10N command attached to an object + "fill_start": N_("Fill stitch starting position"), - # l10n: command attached to an object - "fill_end": _("Fill stitch ending position"), + # L10N command attached to an object + "fill_end": N_("Fill stitch ending position"), - # l10n: command attached to an object - "stop": _("Stop (pause machine) after sewing this object"), + # L10N command attached to an object + "stop": N_("Stop (pause machine) after sewing this object"), - # l10n: command attached to an object - "trim": _("Trim thread after sewing this object"), + # L10N command attached to an object + "trim": N_("Trim thread after sewing this object"), - # l10n: command attached to an object - "ignore_object": _("Ignore this object (do not stitch)"), + # L10N command attached to an object + "ignore_object": N_("Ignore this object (do not stitch)"), - # l10n: command that affects entire layer - "ignore_layer": _("Ignore layer (do not stitch any objects in this layer)") + # L10N command that affects entire layer + "ignore_layer": N_("Ignore layer (do not stitch any objects in this layer)") } OBJECT_COMMANDS = [ "fill_start", "fill_end", "stop", "trim", "ignore_object" ] @@ -117,7 +117,7 @@ class StandaloneCommand(BaseCommand): self.parse_symbol() def get_command_description(command): - return COMMANDS[command] + return _(COMMANDS[command]) def find_commands(node): -- cgit v1.2.3 From 038875f876d79d0f1e971886fe42f5bee4f9f31e Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Tue, 21 Aug 2018 20:32:50 -0400 Subject: autopep8 --- lib/commands.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'lib/commands.py') diff --git a/lib/commands.py b/lib/commands.py index 214b5f40..7764539c 100644 --- a/lib/commands.py +++ b/lib/commands.py @@ -26,8 +26,9 @@ COMMANDS = { "ignore_layer": N_("Ignore layer (do not stitch any objects in this layer)") } -OBJECT_COMMANDS = [ "fill_start", "fill_end", "stop", "trim", "ignore_object" ] -LAYER_COMMANDS = [ "ignore_layer" ] +OBJECT_COMMANDS = ["fill_start", "fill_end", "stop", "trim", "ignore_object"] +LAYER_COMMANDS = ["ignore_layer"] + class CommandParseError(Exception): pass @@ -50,7 +51,7 @@ class BaseCommand(object): else: raise CommandParseError("symbol is not an Ink/Stitch command") - def get_node_by_url(self,url): + def get_node_by_url(self, url): # url will be #path12345. Find the corresponding object. if url is None: raise CommandParseError("url is None") @@ -116,6 +117,7 @@ class StandaloneCommand(BaseCommand): self.parse_symbol() + def get_command_description(command): return _(COMMANDS[command]) @@ -138,6 +140,7 @@ def find_commands(node): return commands + def layer_commands(layer, command): """Find standalone (unconnected) command symbols in this layer.""" @@ -150,6 +153,7 @@ def layer_commands(layer, command): return commands + def standalone_commands(svg): """Find all unconnected command symbols in the SVG.""" @@ -165,5 +169,6 @@ def standalone_commands(svg): return commands + def is_command(node): return CONNECTION_START in node.attrib or CONNECTION_END in node.attrib -- cgit v1.2.3 From d4acb52d6983e5e47f526aaf6216372291385016 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Wed, 22 Aug 2018 21:56:36 -0400 Subject: add `point` property to StandaloneCommand --- lib/commands.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'lib/commands.py') diff --git a/lib/commands.py b/lib/commands.py index 7764539c..b9cf9610 100644 --- a/lib/commands.py +++ b/lib/commands.py @@ -1,9 +1,9 @@ import inkex import cubicsuperpath -from .svg import apply_transforms +from .svg import apply_transforms, get_node_transform from .svg.tags import SVG_USE_TAG, SVG_SYMBOL_TAG, CONNECTION_START, CONNECTION_END, XLINK_HREF -from .utils import cache +from .utils import cache, Point from .i18n import _, N_ COMMANDS = { @@ -117,6 +117,15 @@ class StandaloneCommand(BaseCommand): self.parse_symbol() + @property + @cache + def point(self): + pos = [float(self.node.get("x", 0)), float(self.node.get("y", 0))] + transform = get_node_transform(self.node) + simpletransform.applyTransformToPoint(transform, pos) + + return Point(*pos) + def get_command_description(command): return _(COMMANDS[command]) -- cgit v1.2.3 From a448b2c0ea4e61b28dccd406ffcc5a5ebb96cdd2 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Wed, 22 Aug 2018 22:13:51 -0400 Subject: add origin command and remove guides method --- lib/commands.py | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) (limited to 'lib/commands.py') diff --git a/lib/commands.py b/lib/commands.py index b9cf9610..37196990 100644 --- a/lib/commands.py +++ b/lib/commands.py @@ -1,5 +1,6 @@ import inkex import cubicsuperpath +import simpletransform from .svg import apply_transforms, get_node_transform from .svg.tags import SVG_USE_TAG, SVG_SYMBOL_TAG, CONNECTION_START, CONNECTION_END, XLINK_HREF @@ -22,8 +23,11 @@ COMMANDS = { # L10N command attached to an object "ignore_object": N_("Ignore this object (do not stitch)"), - # L10N command that affects entire layer - "ignore_layer": N_("Ignore layer (do not stitch any objects in this layer)") + # L10N command that affects a layer + "ignore_layer": N_("Ignore layer (do not stitch any objects in this layer)"), + + # L10N command that affects entire document + "origin": N_("Origin for exported embroidery files"), } OBJECT_COMMANDS = ["fill_start", "fill_end", "stop", "trim", "ignore_object"] @@ -153,31 +157,31 @@ def find_commands(node): def layer_commands(layer, command): """Find standalone (unconnected) command symbols in this layer.""" - commands = [] + for global_command in global_commands(layer.getroottree().getroot(), command): + if layer in global_command.node.iterancestors(): + yield global_command - for standalone_command in standalone_commands(layer.getroottree().getroot()): - if standalone_command.command == command: - if layer in standalone_command.node.iterancestors(): - commands.append(command) - return commands +def global_commands(svg, command): + """Find standalone (unconnected) command symbols anywhere in the document.""" + for standalone_command in _standalone_commands(svg): + if standalone_command.command == command: + yield standalone_command -def standalone_commands(svg): + +def _standalone_commands(svg): """Find all unconnected command symbols in the SVG.""" xpath = ".//svg:use[starts-with(@xlink:href, '#inkstitch_')]" symbols = svg.xpath(xpath, namespaces=inkex.NSS) - commands = [] for symbol in symbols: try: - commands.append(StandaloneCommand(symbol)) + yield StandaloneCommand(symbol) except CommandParseError: pass - return commands - def is_command(node): return CONNECTION_START in node.attrib or CONNECTION_END in node.attrib -- cgit v1.2.3 From a8ac170e87cf9db1b976ca1a068b67f5a70cc571 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Wed, 22 Aug 2018 22:48:40 -0400 Subject: implement stop position --- lib/commands.py | 45 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 8 deletions(-) (limited to 'lib/commands.py') diff --git a/lib/commands.py b/lib/commands.py index 37196990..a9b97b35 100644 --- a/lib/commands.py +++ b/lib/commands.py @@ -1,3 +1,4 @@ +import sys import inkex import cubicsuperpath import simpletransform @@ -9,25 +10,28 @@ from .i18n import _, N_ COMMANDS = { # L10N command attached to an object - "fill_start": N_("Fill stitch starting position"), + N_("fill_start"): N_("Fill stitch starting position"), # L10N command attached to an object - "fill_end": N_("Fill stitch ending position"), + N_("fill_end"): N_("Fill stitch ending position"), # L10N command attached to an object - "stop": N_("Stop (pause machine) after sewing this object"), + N_("stop"): N_("Stop (pause machine) after sewing this object"), # L10N command attached to an object - "trim": N_("Trim thread after sewing this object"), + N_("trim"): N_("Trim thread after sewing this object"), # L10N command attached to an object - "ignore_object": N_("Ignore this object (do not stitch)"), + N_("ignore_object"): N_("Ignore this object (do not stitch)"), # L10N command that affects a layer - "ignore_layer": N_("Ignore layer (do not stitch any objects in this layer)"), + N_("ignore_layer"): N_("Ignore layer (do not stitch any objects in this layer)"), # L10N command that affects entire document - "origin": N_("Origin for exported embroidery files"), + N_("origin"): N_("Origin for exported embroidery files"), + + # L10N command that affects entire document + N_("stop_point"): N_("Jump destination for Stop commands (a.k.a. \"Frame Out position\")."), } OBJECT_COMMANDS = ["fill_start", "fill_end", "stop", "trim", "ignore_object"] @@ -132,7 +136,7 @@ class StandaloneCommand(BaseCommand): def get_command_description(command): - return _(COMMANDS[command]) + return COMMANDS[command] def find_commands(node): @@ -169,6 +173,31 @@ def global_commands(svg, command): if standalone_command.command == command: yield standalone_command +@cache +def global_command(svg, command): + """Find a single command of the specified type. + + If more than one is found, print an error and exit. + """ + + commands = list(global_commands(svg, command)) + + if len(commands) == 1: + return commands[0] + elif len(commands) > 1: + print >> sys.stderr, _("Error: there is more than one %(command)s command in the document, but there can only be one. " + "Please remove all but one.") % dict(command=command) + + # L10N This is a continuation of the previous error message, letting the user know + # what command we're talking about since we don't normally expose the actual + # command name to them. Contents of %(description)s are in a separate translation + # string. + print >> sys.stderr, _("%(command)s: %(description)s") % dict(command=command, description=_(get_command_description(command))) + + sys.exit(1) + else: + return None + def _standalone_commands(svg): """Find all unconnected command symbols in the SVG.""" -- cgit v1.2.3 From 7f9208ae2a97026019ff36d28faf37a5c1b9b270 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Thu, 23 Aug 2018 21:46:22 -0400 Subject: style fixes --- lib/commands.py | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/commands.py') diff --git a/lib/commands.py b/lib/commands.py index a9b97b35..3a4ca230 100644 --- a/lib/commands.py +++ b/lib/commands.py @@ -173,6 +173,7 @@ def global_commands(svg, command): if standalone_command.command == command: yield standalone_command + @cache def global_command(svg, command): """Find a single command of the specified type. -- cgit v1.2.3 From 53f92df05635668783a6b9407a01326de14a1291 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Fri, 24 Aug 2018 16:29:13 -0400 Subject: add 'Add Commands' extension --- lib/commands.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/commands.py') diff --git a/lib/commands.py b/lib/commands.py index 3a4ca230..db3c8a71 100644 --- a/lib/commands.py +++ b/lib/commands.py @@ -31,11 +31,12 @@ COMMANDS = { N_("origin"): N_("Origin for exported embroidery files"), # L10N command that affects entire document - N_("stop_point"): N_("Jump destination for Stop commands (a.k.a. \"Frame Out position\")."), + N_("stop_position"): N_("Jump destination for Stop commands (a.k.a. \"Frame Out position\")."), } OBJECT_COMMANDS = ["fill_start", "fill_end", "stop", "trim", "ignore_object"] LAYER_COMMANDS = ["ignore_layer"] +GLOBAL_COMMANDS = ["origin", "stop_position"] class CommandParseError(Exception): -- cgit v1.2.3