diff options
| author | Lex Neva <github.com@lexneva.name> | 2018-06-22 22:19:57 -0400 |
|---|---|---|
| committer | Lex Neva <github.com@lexneva.name> | 2018-06-22 22:28:51 -0400 |
| commit | 1f4bc62d960ab99c6911ab0a292d6ea52a309813 (patch) | |
| tree | 046b4034f056eeef5bc4f686d602433ac73c49e5 /lib/elements | |
| parent | e29096ee138bd674e96a369a853d75eb7c919823 (diff) | |
add quick access methods for commands
Diffstat (limited to 'lib/elements')
| -rw-r--r-- | lib/elements/element.py | 16 |
1 files changed, 16 insertions, 0 deletions
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] |
