summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/exceptions.py30
-rw-r--r--lib/extensions/display_stacking_order.py3
-rw-r--r--lib/extensions/print_pdf.py2
-rw-r--r--lib/inx/__init__.py6
-rwxr-xr-xlib/inx/about.py12
-rwxr-xr-xlib/inx/extensions.py7
-rw-r--r--lib/inx/generate.py29
-rwxr-xr-xlib/inx/info.py6
-rwxr-xr-xlib/inx/inputs.py6
-rw-r--r--lib/inx/outputs.py6
-rw-r--r--lib/lettering/font.py2
-rw-r--r--lib/svg/rendering.py2
-rw-r--r--lib/svg/svg.py11
13 files changed, 74 insertions, 48 deletions
diff --git a/lib/exceptions.py b/lib/exceptions.py
index 3a6b456c..8bef185f 100644
--- a/lib/exceptions.py
+++ b/lib/exceptions.py
@@ -3,12 +3,38 @@
# Copyright (c) 2010 Authors
# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details.
import traceback
+import sys
+import platform
+import subprocess
+from glob import glob
class InkstitchException(Exception):
pass
+def get_os_version():
+ if sys.platform == "win32":
+ # To get the windows version, python functions are used
+ # Using python subprocess with cmd.exe in windows is currently a security risk
+ os_ver = "Windows " + platform.release() + " version: " + platform.version()
+ if sys.platform == "darwin":
+ # macOS command line progam provides accurate info than python functions
+ mac_v = subprocess.run(["sw_vers"], capture_output=True, text=True)
+ os_ver = str(mac_v.stdout.strip())
+ if sys.platform == "linux":
+ # Getting linux version method used here is for systemd and nonsystemd linux.
+ try:
+ ltmp = subprocess.run(["cat"] + glob("/etc/*-release"), capture_output=True, text=True)
+ lnx_ver = ltmp.stdout.splitlines()
+ lnx_ver = str(list(filter(lambda x: "PRETTY_NAME" in x, lnx_ver)))
+ os_ver = lnx_ver[15:][:-3]
+ except FileNotFoundError:
+ os_ver = "Cannot get Linux distro version"
+
+ return os_ver
+
+
def format_uncaught_exception():
"""Format the current exception as a request for a bug report.
@@ -30,7 +56,9 @@ def format_uncaught_exception():
"- create a new issue at")
message += " https://github.com/inkstitch/inkstitch/issues/new\n\n"
message += _("Include the error description and also (if possible) the svg file.")
- message += '\n\n\n'
+ message += '\n\n'
+ message += get_os_version()
+ message += '\n\n'
message += version.get_inkstitch_version() + '\n'
message += traceback.format_exc()
diff --git a/lib/extensions/display_stacking_order.py b/lib/extensions/display_stacking_order.py
index 4056081d..2906c2f8 100644
--- a/lib/extensions/display_stacking_order.py
+++ b/lib/extensions/display_stacking_order.py
@@ -5,6 +5,7 @@
import inkex
+from ..commands import add_layer_commands
from ..i18n import _
from ..svg.tags import INKSCAPE_GROUPMODE, INKSCAPE_LABEL
from .base import InkstitchExtension
@@ -28,6 +29,8 @@ class DisplayStackingOrder(InkstitchExtension):
position = next(path.end_points)
self.insert_stacking_num(layer, i + 1, position)
+ add_layer_commands(layer, ["ignore_layer"])
+
# remove layer if empty
if len(layer) == 0:
self.svg.remove(layer)
diff --git a/lib/extensions/print_pdf.py b/lib/extensions/print_pdf.py
index 4e667130..ddfdc3a3 100644
--- a/lib/extensions/print_pdf.py
+++ b/lib/extensions/print_pdf.py
@@ -231,7 +231,7 @@ class Print(InkstitchExtension):
# for all color blocks together.
layers = svg.findall("./g[@%s='layer']" % INKSCAPE_GROUPMODE)
- stitch_plan_layer = svg.find(".//*[@id='__inkstitch_stitch_plan__']")
+ stitch_plan_layer = svg.findone(".//*[@id='__inkstitch_stitch_plan__']")
# Make sure there is no leftover translation from stitch plan preview
stitch_plan_layer.pop('transform')
diff --git a/lib/inx/__init__.py b/lib/inx/__init__.py
index 6d4846f2..e69de29b 100644
--- a/lib/inx/__init__.py
+++ b/lib/inx/__init__.py
@@ -1,6 +0,0 @@
-# Authors: see git history
-#
-# Copyright (c) 2010 Authors
-# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details.
-
-from .generate import generate_inx_files
diff --git a/lib/inx/about.py b/lib/inx/about.py
deleted file mode 100755
index c1ce458f..00000000
--- a/lib/inx/about.py
+++ /dev/null
@@ -1,12 +0,0 @@
-# Authors: see git history
-#
-# Copyright (c) 2010 Authors
-# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details.
-
-from .utils import build_environment, write_inx_file
-
-
-def generate_about_inx_file():
- env = build_environment()
- template = env.get_template('about.xml')
- write_inx_file("about", template.render())
diff --git a/lib/inx/extensions.py b/lib/inx/extensions.py
index 30fca4da..cceb40de 100755
--- a/lib/inx/extensions.py
+++ b/lib/inx/extensions.py
@@ -40,7 +40,7 @@ def threadcatalog():
return threadcatalog
-def generate_extension_inx_files():
+def generate_extension_inx_files(alter_data):
env = build_environment()
for extension in extensions:
@@ -48,8 +48,9 @@ def generate_extension_inx_files():
continue
name = extension.name()
- template = env.get_template('%s.xml' % name)
- write_inx_file(name, template.render(formats=pyembroidery_output_formats(),
+ template = env.get_template(f'{name}.xml')
+ write_inx_file(name, template.render(alter_data,
+ formats=pyembroidery_output_formats(),
debug_formats=pyembroidery_debug_formats(),
threadcatalog=threadcatalog(),
font_categories=FONT_CATEGORIES,
diff --git a/lib/inx/generate.py b/lib/inx/generate.py
index e94d22f6..47ca3b6d 100644
--- a/lib/inx/generate.py
+++ b/lib/inx/generate.py
@@ -9,8 +9,27 @@ from .inputs import generate_input_inx_files
from .outputs import generate_output_inx_files
-def generate_inx_files():
- generate_input_inx_files()
- generate_output_inx_files()
- generate_extension_inx_files()
- generate_info_inx_files()
+def generate_inx_files(alter=None):
+ if alter is not None:
+ # Ensure the alter is lowercase and string a-z and one letter long
+ if len(alter) != 1 or not alter[0].isalpha() or not alter[0].islower(): # error
+ raise ValueError(f"Invalid alter '{alter}' for inx files, must be a single letter a-z.")
+
+ if alter is None:
+ id_inkstitch = "inkstitch"
+ menu_inkstitch = "Ink/Stitch"
+ else:
+ id_inkstitch = f"{alter}-inkstitch"
+ menu_inkstitch = f"Ink/Stitch-{alter}"
+
+ # print(f"generate_inx_files: id_inkstitch={id_inkstitch}, menu_inkstitch={menu_inkstitch}")
+
+ alter_data = {
+ 'id_inkstitch': id_inkstitch,
+ 'menu_inkstitch': menu_inkstitch,
+ }
+
+ generate_input_inx_files(alter_data)
+ generate_output_inx_files(alter_data)
+ generate_extension_inx_files(alter_data)
+ generate_info_inx_files(alter_data)
diff --git a/lib/inx/info.py b/lib/inx/info.py
index 3a69adad..dc80c3eb 100755
--- a/lib/inx/info.py
+++ b/lib/inx/info.py
@@ -6,9 +6,9 @@
from .utils import build_environment, write_inx_file
-def generate_info_inx_files():
+def generate_info_inx_files(alter_data):
env = build_environment()
info_inx_files = ['about', 'embroider']
for info in info_inx_files:
- template = env.get_template('%s.xml' % info)
- write_inx_file(info, template.render())
+ template = env.get_template(f'{info}.xml')
+ write_inx_file(info, template.render(alter_data))
diff --git a/lib/inx/inputs.py b/lib/inx/inputs.py
index 3ae0b871..624a8dcc 100755
--- a/lib/inx/inputs.py
+++ b/lib/inx/inputs.py
@@ -14,10 +14,10 @@ def pyembroidery_input_formats():
yield format['extension'], format['description']
-def generate_input_inx_files():
+def generate_input_inx_files(alter_data):
env = build_environment()
template = env.get_template('input.xml')
for format, description in pyembroidery_input_formats():
- name = "input_%s" % format.upper()
- write_inx_file(name, template.render(format=format, description=description))
+ name = f"input_{format.upper()}"
+ write_inx_file(name, template.render(alter_data, format=format, description=description))
diff --git a/lib/inx/outputs.py b/lib/inx/outputs.py
index 3a4ac9d0..21014744 100644
--- a/lib/inx/outputs.py
+++ b/lib/inx/outputs.py
@@ -23,10 +23,10 @@ def pyembroidery_output_formats():
yield format['extension'], description, format['mimetype'], format['category']
-def generate_output_inx_files():
+def generate_output_inx_files(alter_data):
env = build_environment()
template = env.get_template('output.xml')
for format, description, mimetype, category in pyembroidery_output_formats():
- name = "output_%s" % format.upper()
- write_inx_file(name, template.render(format=format, mimetype=mimetype, description=description))
+ name = f"output_{format.upper()}"
+ write_inx_file(name, template.render(alter_data, format=format, mimetype=mimetype, description=description))
diff --git a/lib/lettering/font.py b/lib/lettering/font.py
index fb17f760..2aeff3de 100644
--- a/lib/lettering/font.py
+++ b/lib/lettering/font.py
@@ -365,7 +365,7 @@ class Font(object):
line_break_indices = [i for i, t in enumerate(text) if t == "\n"]
for group in destination_group.iterdescendants(SVG_GROUP_TAG):
# make sure we are only looking at glyph groups
- if group.get("id") != "glyph":
+ if not group.get("id", "").startswith("glyph"):
continue
i += 1
diff --git a/lib/svg/rendering.py b/lib/svg/rendering.py
index 1f74e2df..b96fe9b7 100644
--- a/lib/svg/rendering.py
+++ b/lib/svg/rendering.py
@@ -222,7 +222,7 @@ def color_block_to_paths(color_block, svg, destination, visual_commands):
def render_stitch_plan(svg, stitch_plan, realistic=False, visual_commands=True):
- layer = svg.find(".//*[@id='__inkstitch_stitch_plan__']")
+ layer = svg.findone(".//*[@id='__inkstitch_stitch_plan__']")
if layer is None:
layer = inkex.Group(attrib={
'id': '__inkstitch_stitch_plan__',
diff --git a/lib/svg/svg.py b/lib/svg/svg.py
index 3bd9a693..2c521098 100644
--- a/lib/svg/svg.py
+++ b/lib/svg/svg.py
@@ -14,20 +14,13 @@ def get_document(node):
return node.getroottree().getroot()
-def generate_unique_id(document_or_element, prefix="path"):
+def generate_unique_id(document_or_element, prefix="path", blocklist=None):
if isinstance(document_or_element, etree._ElementTree):
document = document_or_element.getroot()
else:
document = get_document(document_or_element)
- doc_ids = {node.get('id') for node in document.iterdescendants() if 'id' in node.attrib}
-
- i = 1
- while True:
- new_id = "%s%d" % (prefix, i)
- if new_id not in doc_ids:
- break
- i += 1
+ new_id = document.get_unique_id(prefix, blacklist=blocklist)
return new_id