kopia lustrzana https://github.com/inkstitch/inkstitch
support for modified id and menu
rodzic
048dc5f396
commit
2be2dd6c6d
|
@ -1,19 +1,73 @@
|
||||||
#!/usr/bin/env python
|
#!/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 sys
|
||||||
import os
|
import os
|
||||||
from os.path import dirname
|
from pathlib import Path
|
||||||
|
import argparse
|
||||||
|
|
||||||
# add inkstitch libs to python path
|
# add inkstitch lib dir to python path
|
||||||
parent_dir = os.path.join(dirname(dirname(__file__)))
|
parent_dir = Path(__file__).resolve().parents[1]
|
||||||
sys.path.append(parent_dir)
|
sys.path.append(str(parent_dir)) # we need import from lib/ directory
|
||||||
|
|
||||||
# try find add inkex.py et al. as well
|
# find inkex module
|
||||||
sys.path.append(os.path.join(parent_dir, "inkscape", "share", "extensions"))
|
try:
|
||||||
sys.path.append(os.path.join("/usr/share/inkscape/extensions"))
|
import inkex # if it is already in the path, do nothing
|
||||||
# default inkex.py location on macOS
|
except ImportError: # if not, add inkscape version
|
||||||
sys.path.append("/Applications/Inkscape.app/Contents/Resources/share/inkscape/extensions/")
|
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)
|
||||||
|
|
|
@ -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
|
|
|
@ -40,7 +40,7 @@ def threadcatalog():
|
||||||
return threadcatalog
|
return threadcatalog
|
||||||
|
|
||||||
|
|
||||||
def generate_extension_inx_files():
|
def generate_extension_inx_files(alter_data):
|
||||||
env = build_environment()
|
env = build_environment()
|
||||||
|
|
||||||
for extension in extensions:
|
for extension in extensions:
|
||||||
|
@ -48,8 +48,9 @@ def generate_extension_inx_files():
|
||||||
continue
|
continue
|
||||||
|
|
||||||
name = extension.name()
|
name = extension.name()
|
||||||
template = env.get_template('%s.xml' % name)
|
template = env.get_template(f'{name}.xml')
|
||||||
write_inx_file(name, template.render(formats=pyembroidery_output_formats(),
|
write_inx_file(name, template.render(alter_data,
|
||||||
|
formats=pyembroidery_output_formats(),
|
||||||
debug_formats=pyembroidery_debug_formats(),
|
debug_formats=pyembroidery_debug_formats(),
|
||||||
threadcatalog=threadcatalog(),
|
threadcatalog=threadcatalog(),
|
||||||
font_categories=FONT_CATEGORIES,
|
font_categories=FONT_CATEGORIES,
|
||||||
|
|
|
@ -9,8 +9,27 @@ from .inputs import generate_input_inx_files
|
||||||
from .outputs import generate_output_inx_files
|
from .outputs import generate_output_inx_files
|
||||||
|
|
||||||
|
|
||||||
def generate_inx_files():
|
def generate_inx_files(alter=None):
|
||||||
generate_input_inx_files()
|
if alter is not None:
|
||||||
generate_output_inx_files()
|
# Ensure the alter is lowercase and string a-z and one letter long
|
||||||
generate_extension_inx_files()
|
if len(alter) != 1 or not alter[0].isalpha() or not alter[0].islower(): # error
|
||||||
generate_info_inx_files()
|
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)
|
||||||
|
|
|
@ -6,9 +6,9 @@
|
||||||
from .utils import build_environment, write_inx_file
|
from .utils import build_environment, write_inx_file
|
||||||
|
|
||||||
|
|
||||||
def generate_info_inx_files():
|
def generate_info_inx_files(alter_data):
|
||||||
env = build_environment()
|
env = build_environment()
|
||||||
info_inx_files = ['about', 'embroider']
|
info_inx_files = ['about', 'embroider']
|
||||||
for info in info_inx_files:
|
for info in info_inx_files:
|
||||||
template = env.get_template('%s.xml' % info)
|
template = env.get_template(f'{info}.xml')
|
||||||
write_inx_file(info, template.render())
|
write_inx_file(info, template.render(alter_data))
|
||||||
|
|
|
@ -14,10 +14,10 @@ def pyembroidery_input_formats():
|
||||||
yield format['extension'], format['description']
|
yield format['extension'], format['description']
|
||||||
|
|
||||||
|
|
||||||
def generate_input_inx_files():
|
def generate_input_inx_files(alter_data):
|
||||||
env = build_environment()
|
env = build_environment()
|
||||||
template = env.get_template('input.xml')
|
template = env.get_template('input.xml')
|
||||||
|
|
||||||
for format, description in pyembroidery_input_formats():
|
for format, description in pyembroidery_input_formats():
|
||||||
name = "input_%s" % format.upper()
|
name = f"input_{format.upper()}"
|
||||||
write_inx_file(name, template.render(format=format, description=description))
|
write_inx_file(name, template.render(alter_data, format=format, description=description))
|
||||||
|
|
|
@ -23,10 +23,10 @@ def pyembroidery_output_formats():
|
||||||
yield format['extension'], description, format['mimetype'], format['category']
|
yield format['extension'], description, format['mimetype'], format['category']
|
||||||
|
|
||||||
|
|
||||||
def generate_output_inx_files():
|
def generate_output_inx_files(alter_data):
|
||||||
env = build_environment()
|
env = build_environment()
|
||||||
template = env.get_template('output.xml')
|
template = env.get_template('output.xml')
|
||||||
|
|
||||||
for format, description, mimetype, category in pyembroidery_output_formats():
|
for format, description, mimetype, category in pyembroidery_output_formats():
|
||||||
name = "output_%s" % format.upper()
|
name = f"output_{format.upper()}"
|
||||||
write_inx_file(name, template.render(format=format, mimetype=mimetype, description=description))
|
write_inx_file(name, template.render(alter_data, format=format, mimetype=mimetype, description=description))
|
||||||
|
|
Ładowanie…
Reference in New Issue