summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaalleen <36401965+kaalleen@users.noreply.github.com>2021-06-02 20:33:52 +0200
committerGitHub <noreply@github.com>2021-06-02 20:33:52 +0200
commit9b15c04e36949e6509c227d17183a85ba058e835 (patch)
treebd1303f94805acbd39d31ecb93271a849c41b7a3
parentb3a6fdc7616cbd1485bd0818778af11d922d866e (diff)
input isfile (#1231)
-rw-r--r--lib/extensions/input.py11
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/extensions/input.py b/lib/extensions/input.py
index 13788510..a0861bbc 100644
--- a/lib/extensions/input.py
+++ b/lib/extensions/input.py
@@ -4,12 +4,14 @@
# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details.
import os
+import sys
import inkex
from lxml import etree
import pyembroidery
+from ..i18n import _
from ..stitch_plan import StitchPlan
from ..svg import PIXELS_PER_MM, render_stitch_plan
from ..svg.tags import INKSCAPE_LABEL
@@ -18,8 +20,9 @@ from ..svg.tags import INKSCAPE_LABEL
class Input(object):
def run(self, args):
embroidery_file = args[0]
- pattern = pyembroidery.read(embroidery_file)
+ self.validate_file_path(embroidery_file)
+ pattern = pyembroidery.read(embroidery_file)
stitch_plan = StitchPlan()
color_block = None
@@ -61,3 +64,9 @@ class Input(object):
layer.set('transform', 'translate(%s,%s)' % (extents[0], extents[1]))
print(etree.tostring(svg).decode('utf-8'))
+
+ def validate_file_path(self, path):
+ # Check if the file exists
+ if not os.path.isfile(path):
+ inkex.errormsg(_('File does not exist and cannot be opened. Please correct the file path and try again.\r%s') % path)
+ sys.exit(1)