diff options
| author | Kaalleen <36401965+kaalleen@users.noreply.github.com> | 2020-05-27 16:08:19 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-05-27 16:08:19 +0200 |
| commit | 455b02847f14983ef8c2463849981f5e9fc44063 (patch) | |
| tree | d4ed8df3fbf9d57bdda366dbc71bfd58b0b2ce0b /lib/extensions/cleanup.py | |
| parent | b461b2d85b10951f700d8f5c51b050bed8468cd2 (diff) | |
cleanup extension (#713)
Co-authored-by: Lex Neva <github.com@lexneva.name>
Diffstat (limited to 'lib/extensions/cleanup.py')
| -rw-r--r-- | lib/extensions/cleanup.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/extensions/cleanup.py b/lib/extensions/cleanup.py new file mode 100644 index 00000000..f8cb7d9a --- /dev/null +++ b/lib/extensions/cleanup.py @@ -0,0 +1,39 @@ +import sys + +from ..elements import Fill, Stroke +from ..i18n import _ +from .base import InkstitchExtension + + +class Cleanup(InkstitchExtension): + def __init__(self, *args, **kwargs): + InkstitchExtension.__init__(self, *args, **kwargs) + self.OptionParser.add_option("-f", "--rm_fill", dest="rm_fill", type="inkbool", default=True) + self.OptionParser.add_option("-s", "--rm_stroke", dest="rm_stroke", type="inkbool", default=True) + self.OptionParser.add_option("-a", "--fill_threshold", dest="fill_threshold", type="int", default=20) + self.OptionParser.add_option("-l", "--stroke_threshold", dest="stroke_threshold", type="int", default=5) + + def effect(self): + self.rm_fill = self.options.rm_fill + self.rm_stroke = self.options.rm_stroke + self.fill_threshold = self.options.fill_threshold + self.stroke_threshold = self.options.stroke_threshold + + # Remove selection, we want every element in the document + self.selected = {} + + if not self.get_elements(): + return + + count = 0 + for element in self.elements: + if (isinstance(element, Fill) and self.rm_fill and + element.shape.area < self.fill_threshold): + element.node.getparent().remove(element.node) + count += 1 + if (isinstance(element, Stroke) and self.rm_stroke and + element.shape.length < self.stroke_threshold and element.node.getparent() is not None): + element.node.getparent().remove(element.node) + count += 1 + + print >> sys.stderr, _("%s elements removed" % count) |
