diff --git a/Makefile b/Makefile
index c4e214104..a13efed92 100644
--- a/Makefile
+++ b/Makefile
@@ -17,8 +17,7 @@ manual:
.PHONY: inx
inx: version locales
- mkdir -p inx
- python bin/generate-inx-files; \
+ python bin/generate-inx-files;
.PHONY: messages.po
messages.po: inx
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/about.py b/lib/inx/about.py
deleted file mode 100755
index c1ce458f3..000000000
--- 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 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))
diff --git a/templates/about.xml b/templates/about.xml
index 538b3ca83..fc937936b 100644
--- a/templates/about.xml
+++ b/templates/about.xml
@@ -1,7 +1,7 @@
About
- org.inkstitch.about
+ org.{{ id_inkstitch }}.about
{{ image_path }}inkstitch_colour_logo.svg
@@ -21,7 +21,7 @@
all
-
+
diff --git a/templates/apply_threadlist.xml b/templates/apply_threadlist.xml
index 303cb793d..4b7684494 100644
--- a/templates/apply_threadlist.xml
+++ b/templates/apply_threadlist.xml
@@ -1,7 +1,7 @@
Apply Threadlist
- org.inkstitch.apply_threadlist
+ org.{{ id_inkstitch }}.apply_threadlist
apply_threadlist
@@ -34,7 +34,7 @@
all
-
+
diff --git a/templates/auto_run.xml b/templates/auto_run.xml
index 4a524b2dc..026f21431 100644
--- a/templates/auto_run.xml
+++ b/templates/auto_run.xml
@@ -1,12 +1,12 @@
Auto-Route Running Stitch
- org.inkstitch.auto_run
+ org.{{ id_inkstitch }}.auto_run
auto_run
all
-
+
diff --git a/templates/auto_satin.xml b/templates/auto_satin.xml
index b95ffab8a..e7cf9a7a6 100644
--- a/templates/auto_satin.xml
+++ b/templates/auto_satin.xml
@@ -1,14 +1,14 @@
Auto-Route Satin Columns
- org.inkstitch.auto_satin
+ org.{{ id_inkstitch }}.auto_satin
true
false
auto_satin
all
-
+
diff --git a/templates/break_apart.xml b/templates/break_apart.xml
index b084fd8fe..1557032ec 100644
--- a/templates/break_apart.xml
+++ b/templates/break_apart.xml
@@ -1,12 +1,12 @@
Break Apart Fill Objects
- org.inkstitch.break_apart
+ org.{{ id_inkstitch }}.break_apart
break_apart
all
-
+
diff --git a/templates/cleanup.xml b/templates/cleanup.xml
index 2145b4067..e42dec126 100644
--- a/templates/cleanup.xml
+++ b/templates/cleanup.xml
@@ -1,7 +1,7 @@
Cleanup Document
- org.inkstitch.cleanup
+ org.{{ id_inkstitch }}.cleanup
true
@@ -19,7 +19,7 @@
all
-
+
diff --git a/templates/commands_scale_symbols.xml b/templates/commands_scale_symbols.xml
index 98d170032..8234938dd 100644
--- a/templates/commands_scale_symbols.xml
+++ b/templates/commands_scale_symbols.xml
@@ -1,13 +1,13 @@
Scale Command Symbols
- org.inkstitch.commands_scale_symbols
+ org.{{ id_inkstitch }}.commands_scale_symbols
commands_scale_symbols
1.0
all
-
+
diff --git a/templates/convert_to_satin.xml b/templates/convert_to_satin.xml
index aa86ed4c0..870883a56 100644
--- a/templates/convert_to_satin.xml
+++ b/templates/convert_to_satin.xml
@@ -1,12 +1,12 @@
Convert Line to Satin
- org.inkstitch.convert_to_satin
+ org.{{ id_inkstitch }}.convert_to_satin
convert_to_satin
all
-
+
diff --git a/templates/convert_to_stroke.xml b/templates/convert_to_stroke.xml
index 4c8367506..89ff04fe6 100644
--- a/templates/convert_to_stroke.xml
+++ b/templates/convert_to_stroke.xml
@@ -1,7 +1,7 @@
Convert Satin to Stroke
- org.inkstitch.convert_to_stroke
+ org.{{ id_inkstitch }}.convert_to_stroke
convert_to_stroke
all
-
+
diff --git a/templates/cut_satin.xml b/templates/cut_satin.xml
index 52b972e96..92f0223e5 100644
--- a/templates/cut_satin.xml
+++ b/templates/cut_satin.xml
@@ -1,12 +1,12 @@
Cut Satin Column
- org.inkstitch.cut_satin
+ org.{{ id_inkstitch }}.cut_satin
cut_satin
all
-
+
diff --git a/templates/cutwork_segmentation.xml b/templates/cutwork_segmentation.xml
index f20ff082f..adc744e52 100644
--- a/templates/cutwork_segmentation.xml
+++ b/templates/cutwork_segmentation.xml
@@ -1,12 +1,12 @@
Cutwork segmentation
- org.inkstitch.cutwork_segmentation
+ org.{{ id_inkstitch }}.cutwork_segmentation
cutwork_segmentation
all
-
+
diff --git a/templates/density_map.xml b/templates/density_map.xml
index fdc6b2d1e..7fee175c1 100644
--- a/templates/density_map.xml
+++ b/templates/density_map.xml
@@ -1,12 +1,12 @@
Density Map
- org.inkstitch.density_map
+ org.{{ id_inkstitch }}.density_map
density_map
all
-
+
diff --git a/templates/display_stacking_order.xml b/templates/display_stacking_order.xml
index c0793e60e..be8539f2e 100644
--- a/templates/display_stacking_order.xml
+++ b/templates/display_stacking_order.xml
@@ -1,12 +1,12 @@
Display stacking order
- org.inkstitch.display_stacking_order
+ org.{{ id_inkstitch }}.display_stacking_order
display_stacking_order
all
-
+
diff --git a/templates/duplicate_params.xml b/templates/duplicate_params.xml
index 72012bb2b..6502a243d 100644
--- a/templates/duplicate_params.xml
+++ b/templates/duplicate_params.xml
@@ -1,12 +1,12 @@
Duplicate Params
- org.inkstitch.duplicate_params
+ org.{{ id_inkstitch }}.duplicate_params
duplicate_params
all
-
+
diff --git a/templates/element_info.xml b/templates/element_info.xml
index 8211a5154..3ae3d1388 100644
--- a/templates/element_info.xml
+++ b/templates/element_info.xml
@@ -1,12 +1,12 @@
Element Info
- org.inkstitch.element_info
+ org.{{ id_inkstitch }}.element_info
element_info
all
-
+
diff --git a/templates/embroider.xml b/templates/embroider.xml
index 4dcead18d..9641cb37a 100644
--- a/templates/embroider.xml
+++ b/templates/embroider.xml
@@ -1,7 +1,7 @@
Embroider
- org.inkstitch.embroider
+ org.{{ id_inkstitch }}.embroider
@@ -10,7 +10,7 @@
all
-
+
diff --git a/templates/fill_to_stroke.xml b/templates/fill_to_stroke.xml
index 060b6ab80..35d097312 100644
--- a/templates/fill_to_stroke.xml
+++ b/templates/fill_to_stroke.xml
@@ -1,12 +1,12 @@
Fill to Stroke
- org.inkstitch.fill_to_stroke
+ org.{{ id_inkstitch }}.fill_to_stroke
fill_to_stroke
all
-
+
diff --git a/templates/flip.xml b/templates/flip.xml
index b13977dc6..cc05c166d 100644
--- a/templates/flip.xml
+++ b/templates/flip.xml
@@ -1,12 +1,12 @@
Flip Satin Column Rails
- org.inkstitch.flip_satins
+ org.{{ id_inkstitch }}.flip_satins
flip
all
-
+
diff --git a/templates/generate_palette.xml b/templates/generate_palette.xml
index cf5a18e48..1455a046b 100644
--- a/templates/generate_palette.xml
+++ b/templates/generate_palette.xml
@@ -1,12 +1,12 @@
Generate Color Palette
- org.inkstitch.generate_palette
+ org.{{ id_inkstitch }}.generate_palette
generate_palette
all
-
+
diff --git a/templates/global_commands.xml b/templates/global_commands.xml
index a7fe91f5a..72f1c8119 100644
--- a/templates/global_commands.xml
+++ b/templates/global_commands.xml
@@ -1,7 +1,7 @@
Add Commands
- org.inkstitch.global_commands
+ org.{{ id_inkstitch }}.global_commands
{% for command, description in global_commands %}
false
@@ -10,7 +10,7 @@
all
-
+
{# L10N Inkscape submenu under Extensions -> Ink/Stitch #}
diff --git a/templates/gradient_blocks.xml b/templates/gradient_blocks.xml
index f824d5149..7b6e1d35f 100644
--- a/templates/gradient_blocks.xml
+++ b/templates/gradient_blocks.xml
@@ -1,12 +1,12 @@
Convert to gradient blocks
- org.inkstitch.gradient_blocks
+ org.{{ id_inkstitch }}.gradient_blocks
gradient_blocks
all
-
+
diff --git a/templates/input.xml b/templates/input.xml
index b868c5ae9..f8bf2c7a3 100644
--- a/templates/input.xml
+++ b/templates/input.xml
@@ -1,11 +1,11 @@
{{ format | upper }} file input
- org.inkstitch.input.{{ format }}
+ org.{{ id_inkstitch }}.input.{{ format }}
.{{ format }}
application/x-embroidery-{{ format }}
- Ink/Stitch: {{ description }} (.{{ format }})
+ {{ menu_inkstitch }}: {{ description }} (.{{ format }})
{{ "convert %(file_extension)s file to Ink/Stitch manual-stitch paths" % dict(file_extension=format.upper()) }}
input
diff --git a/templates/install.xml b/templates/install.xml
index 8b6b8d486..1d99d5190 100644
--- a/templates/install.xml
+++ b/templates/install.xml
@@ -1,12 +1,12 @@
Install thread color palettes for Inkscape
- org.inkstitch.install
+ org.{{ id_inkstitch }}.install
install
all
-
+
diff --git a/templates/install_custom_palette.xml b/templates/install_custom_palette.xml
index c69458fb6..fa037e7b4 100644
--- a/templates/install_custom_palette.xml
+++ b/templates/install_custom_palette.xml
@@ -1,7 +1,7 @@
Install custom palette
- org.inkstitch.install_custom_palette
+ org.{{ id_inkstitch }}.install_custom_palette
install_custom_palette
@@ -9,7 +9,7 @@
all
-
+
diff --git a/templates/jump_to_stroke.xml b/templates/jump_to_stroke.xml
index e41e806ae..13ab96fad 100644
--- a/templates/jump_to_stroke.xml
+++ b/templates/jump_to_stroke.xml
@@ -1,12 +1,12 @@
Jump Stitch to Stroke
- org.inkstitch.jump_to_stroke
+ org.{{ id_inkstitch }}.jump_to_stroke
jump_to_stroke
all
-
+
diff --git a/templates/layer_commands.xml b/templates/layer_commands.xml
index a9996793e..81aeac95b 100644
--- a/templates/layer_commands.xml
+++ b/templates/layer_commands.xml
@@ -1,7 +1,7 @@
Add Layer Commands
- org.inkstitch.layer_commands
+ org.{{ id_inkstitch }}.layer_commands
{% for command, description in layer_commands %}
false
@@ -10,7 +10,7 @@
all
-
+
diff --git a/templates/lettering.xml b/templates/lettering.xml
index 19e0afd5b..1b9576aa2 100644
--- a/templates/lettering.xml
+++ b/templates/lettering.xml
@@ -1,12 +1,12 @@
Lettering
- org.inkstitch.lettering
+ org.{{ id_inkstitch }}.lettering
lettering
all
-
+