This repository has been archived on 2023-03-25. You can view files and clone it, but cannot push or open issues or pull requests.
mightyscape-1.1-deprecated/extensions/fablabchemnitz/inkcut/fablabchemnitz_inkcut_open.py

70 lines
2.2 KiB
Python
Raw Normal View History

2020-08-30 11:31:47 +02:00
#!/usr/bin/env python3
2020-07-30 01:16:18 +02:00
"""
Inkcut, Plot HPGL directly from Inkscape.
2020-08-30 11:23:01 +02:00
extension.py
2020-07-30 01:16:18 +02:00
2020-08-30 11:23:01 +02:00
Copyright 2010-2018 The Inkcut Team
2020-07-30 01:16:18 +02:00
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.
"""
import os
2020-08-30 11:23:01 +02:00
import sys
2020-07-30 01:16:18 +02:00
import inkex
2020-08-30 11:23:01 +02:00
import importlib
import subprocess
2020-07-30 01:16:18 +02:00
from lxml import etree
2020-08-30 11:23:01 +02:00
from fablabchemnitz_inkcut import convert_objects_to_paths
DEBUG = False
try:
from subprocess import DEVNULL # py3k
except ImportError:
import os
DEVNULL = open(os.devnull, 'wb')
class InkscapeInkcutPlugin(inkex.Effect):
def effect(self):
""" Like cut but requires no selection and does no validation for
text nodes.
"""
#: If running from source
if DEBUG:
python = '~/inkcut/venv/bin/python'
inkcut = '~/inkcut/main.py'
cmd = [python, inkcut]
else:
cmd = ['inkcut']
document = convert_objects_to_paths(self.options.input_file, self.document)
cmd += ['open', '-']
p = subprocess.Popen(cmd,
stdin=subprocess.PIPE,
stdout=DEVNULL,
stderr=subprocess.STDOUT,
close_fds=sys.platform != "win32")
p.stdin.write(etree.tostring(document))
p.stdin.close()
# Set the returncode to avoid this warning when popen is garbage collected:
# "ResourceWarning: subprocess XXX is still running".
# See https://bugs.python.org/issue38890 and
# https://bugs.python.org/issue26741.
p.returncode = 0
if __name__ == '__main__':
InkscapeInkcutPlugin().run()