From 1f4bc62d960ab99c6911ab0a292d6ea52a309813 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Fri, 22 Jun 2018 22:19:57 -0400 Subject: add quick access methods for commands --- lib/elements/element.py | 16 ++++++++++++++++ messages.po | 6 +++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/elements/element.py b/lib/elements/element.py index 465813d4..3c31f1b0 100644 --- a/lib/elements/element.py +++ b/lib/elements/element.py @@ -210,6 +210,22 @@ class EmbroideryElement(object): def commands(self): return find_commands(self.node) + @cache + def get_commands(self, command): + return [c for c in self.commands if c.command == command] + + @cache + def get_command(self, command): + commands = self.get_commands(command) + + if len(commands) == 1: + return commands[0] + elif len(commands) > 1: + raise ValueError(_("%(id)s has more than one command of type '%(command)s' linked to it") % + dict(id=self.node.get(id), command=command)) + else: + return None + def strip_control_points(self, subpath): return [point for control_before, point, control_after in subpath] diff --git a/messages.po b/messages.po index fb081eb1..e6bfed43 100644 --- a/messages.po +++ b/messages.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PROJECT VERSION\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" -"POT-Creation-Date: 2018-06-16 22:33-0400\n" +"POT-Creation-Date: 2018-06-22 22:19-0400\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -47,6 +47,10 @@ msgstr "" msgid "Expand" msgstr "" +#, python-format +msgid "%(id)s has more than one command of type '%(command)s' linked to it" +msgstr "" + msgid "TRIM after" msgstr "" -- cgit v1.2.3