support for modified id and menu

pull/2715/head
karnigen 2024-02-07 21:03:57 +01:00
rodzic 048dc5f396
commit 2be2dd6c6d
7 zmienionych plików z 102 dodań i 34 usunięć

Wyświetl plik

@ -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:
# <id>org.inkstitch.....</id> ---> <id>org.{{ id_inkstitch }}.....</id>
# <submenu name="Ink/Stitch" ---> <submenu name="{{ menu_inkstitch }}"
# or input/output xml template should be modified to use the filetypename:
# <filetypename>Ink/Stitch:... ---> <filetypename>{{ 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)

Wyświetl plik

@ -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

Wyświetl plik

@ -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,

Wyświetl plik

@ -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)

Wyświetl plik

@ -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))

Wyświetl plik

@ -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))

Wyświetl plik

@ -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))