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 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'lib') 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] -- cgit v1.2.3