diff --git a/bin/generate-inx-files b/bin/generate-inx-files
index 44edea15b..553e184dc 100755
--- a/bin/generate-inx-files
+++ b/bin/generate-inx-files
@@ -1,19 +1,73 @@
#!/usr/bin/env python
+# Implemented support for multiple diverse versions of Inkstitch extensions in Inkscape.
+# - useful for testing and development
+# - useful for comparing different versions of Inkstitch
+
+
+# this script generates inx files in inx/ directory from xml templates in templates/ directory
+# - added support for alternative id registration and menu names for Inkscape extensions
+# - each xml template should be modified to use the new id_inkstitch and menu_inkstitch:
+# org.inkstitch..... ---> org.{{ id_inkstitch }}.....
+# Ink/Stitch:... ---> {{ menu_inkstitch }}:...
+
+
+# Here's an example of how to use two Inkstitch extensions:
+# - install Inkstitch in two different locations (e.g. inkstitch and inkstitch-k)
+# - check out the Inkstitch repository in two different locations
+# - ensure 'make inx' is executed in both locations
+# - this will generate also inx/locale/ files
+# - generate modified inx files for second location
+# - in the second location:
+# > generate-inx-files -a k
+# - install the inx files in Inkscape extensions directory
+# - symlink .config/inkscape/extensions/inkstitch -> inkstitch
+# - symlink .config/inkscape/extensions/inkstitch-k -> inkstitch-k
+# - modify .config/inkscape/keys/default.xml if necessary
+# - run Inkscape with both Inkstitch extensions enabled
+# - first version: Extensions > Ink/Stitch
+# - second version: Extensions > Ink/Stitch-k
+
import sys
import os
-from os.path import dirname
+from pathlib import Path
+import argparse
-# add inkstitch libs to python path
-parent_dir = os.path.join(dirname(dirname(__file__)))
-sys.path.append(parent_dir)
+# add inkstitch lib dir to python path
+parent_dir = Path(__file__).resolve().parents[1]
+sys.path.append(str(parent_dir)) # we need import from lib/ directory
-# try find add inkex.py et al. as well
-sys.path.append(os.path.join(parent_dir, "inkscape", "share", "extensions"))
-sys.path.append(os.path.join("/usr/share/inkscape/extensions"))
-# default inkex.py location on macOS
-sys.path.append("/Applications/Inkscape.app/Contents/Resources/share/inkscape/extensions/")
+# find inkex module
+try:
+ import inkex # if it is already in the path, do nothing
+except ImportError: # if not, add inkscape version
+ import subprocess
+ inkscape_path = 'inkscape'
+ # for now assume inkscape is in the path and raise an error if inkscape is not in the path
+ system_path = subprocess.run([inkscape_path, "--system-data-directory"], capture_output=True, text=True).stdout.strip()
+ inkex_path = os.path.join(system_path, "extensions")
+ sys.path.append(inkex_path)
-from lib.inx import generate_inx_files
+ # possible last attempt to import inkex may be as follows:
+ # sys.path.append(os.path.join("/usr/share/inkscape/extensions"))
+ # default inkex.py location on macOS
+ # sys.path.append("/Applications/Inkscape.app/Contents/Resources/share/inkscape/extensions/")
-generate_inx_files()
+
+from lib.inx.generate import generate_inx_files
+
+# parse arguments
+# -a, --alter letter a-z: generate inx files for the given alter
+parser = argparse.ArgumentParser(description='Generate INX files, supporting multiple active inkstitch extensions in inkscape.')
+parser.add_argument('-a', '--alter', type=str, help='Letter a-z representing the alter')
+args = parser.parse_args()
+
+# print(f"generate_inx_files: alter={args.alter}")
+
+inx_path = parent_dir / "inx"
+inx_path.mkdir(parents=True, exist_ok=True)
+
+# if -a is not given, args.alter is None - not alternative inx, but generate default inx
+generate_inx_files(args.alter)
diff --git a/lib/inx/__init__.py b/lib/inx/__init__.py
index 6d4846f2f..e69de29bb 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/extensions.py b/lib/inx/extensions.py
index 30fca4da1..cceb40def 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 e94d22f6c..47ca3b6db 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 3a69adad4..dc80c3eb5 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 3ae0b8719..624a8dcc0 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 3a4ac9d0f..210147444 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))